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
fix: pi models.json rebuild from scratch, health test drm field, connections mcpb path
Louis Beaumont7d3585078434
diff --git a/apps/screenpipe-app-tauri/components/settings/connections-section.tsx b/apps/screenpipe-app-tauri/components/settings/connections-section.tsxindex 679c551a0..055b53295 100644--- a/apps/screenpipe-app-tauri/components/settings/connections-section.tsx+++ b/apps/screenpipe-app-tauri/components/settings/connections-section.tsx@@ -16,7 +16,7 @@ import { useSettings } from "@/lib/hooks/use-settings";import { ensureChatGptPreset } from "@/lib/utils/chatgpt-preset";import { showChatWithPrefill } from "@/lib/chat-utils";import { Command } from "@tauri-apps/plugin-shell";-import { openUrl } from "@tauri-apps/plugin-opener";+import { openUrl, revealItemInDir } from "@tauri-apps/plugin-opener";import { message } from "@tauri-apps/plugin-dialog";import { writeFile, readTextFile } from "@tauri-apps/plugin-fs";import { fetch as tauriFetch } from "@tauri-apps/plugin-http";@@ -326,6 +326,7 @@ function Tile({ tile, selected, onClick }: {function ClaudePanel({ onConnected }: { onConnected?: () => void }) {const [downloadState, setDownloadState] = useState<"idle" | "downloading" | "downloaded">("idle");const [versionInfo, setVersionInfo] = useState<McpVersionInfo>({ available: null, installed: null });+ const [mcpbPath, setMcpbPath] = useState<string>("");useEffect(() => {Promise.all([@@ -344,11 +345,12 @@ function ClaudePanel({ onConnected }: { onConnected?: () => void }) {if (!response.ok) throw new Error("failed to download .mcpb file");const data = new Uint8Array(await response.arrayBuffer());const tmp = await tempDir();- const mcpbPath = await join(tmp, "screenpipe.mcpb");- await writeFile(mcpbPath, data);+ const filePath = await join(tmp, "screenpipe.mcpb");+ await writeFile(filePath, data);+ setMcpbPath(filePath);const os = platform();- if (os === "macos") await Command.create("open", [mcpbPath]).execute();- else if (os === "windows") await Command.create("cmd", ["/c", "start", "", mcpbPath]).execute();+ if (os === "macos") await Command.create("open", [filePath]).execute();+ else if (os === "windows") await Command.create("cmd", ["/c", "start", "", filePath]).execute();setDownloadState("downloaded");onConnected?.();} catch (error) {@@ -389,8 +391,17 @@ function ClaudePanel({ onConnected }: { onConnected?: () => void }) {</Button></div>{downloadState === "downloaded" && (- <div className="p-3 bg-muted border border-border rounded-lg">+ <div className="p-3 bg-muted border border-border rounded-lg space-y-2"><p className="text-xs"><strong>connected!</strong> restart claude if it was running. try: "what did I do in the last 5 minutes?"</p>+ <details className="text-xs text-muted-foreground">+ <summary className="cursor-pointer hover:text-foreground">didn't work? troubleshooting steps</summary>+ <ul className="mt-1.5 ml-4 list-disc space-y-1">+ <li>drag and drop the .mcpb file into claude desktop's window</li>+ <li>or in claude: developer → extensions → install extension → select the file</li>+ {mcpbPath && <li>file location: <code className="bg-background px-1 rounded select-all">{mcpbPath}</code></li>}+ <li>if nothing works, reinstall claude desktop to fix file associations</li>+ </ul>+ </details></div>)}</div>diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lockindex d0308d45e..8a0c55e07 100644--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock@@ -9640,7 +9640,7 @@ dependencies = [[[package]]name = "screenpipe-app"-version = "2.2.284"+version = "2.2.286"dependencies = ["anyhow","arboard",diff --git a/apps/screenpipe-app-tauri/src-tauri/src/health.rs b/apps/screenpipe-app-tauri/src-tauri/src/health.rsindex 64ed9edf7..de7b96d39 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/health.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/health.rs@@ -751,6 +751,7 @@ mod tests {audio_pipeline: None,vision_db_write_stalled: false,audio_db_write_stalled: false,+ drm_content_paused: false,})}@@ -771,6 +772,7 @@ mod tests {audio_pipeline: None,vision_db_write_stalled: false,audio_db_write_stalled: false,+ drm_content_paused: false,})}diff --git a/apps/screenpipe-app-tauri/src-tauri/src/pi.rs b/apps/screenpipe-app-tauri/src-tauri/src/pi.rsindex 23c561bf6..a74bce4f8 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/pi.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/pi.rs@@ -668,29 +668,18 @@ fn default_max_tokens() -> i32 {4096}-/// Merge providers into pi's existing config (preserves other providers/auth).-/// Now supports any OpenAI-compatible provider (OpenAI, Ollama, custom, screenpipe-cloud).-fn ensure_pi_config(+/// Build the models.json content for pi-coding-agent.+///+/// Pure function (no I/O) — builds a clean JSON value from scratch with only the+/// providers we manage. This prevents stale/schema-invalid providers left over from+/// older versions from poisoning pi-coding-agent's Ajv validation.+fn build_models_json(user_token: Option<&str>,provider_config: Option<&PiProviderConfig>,-) -> Result<(), String> {- let config_dir = get_pi_config_dir()?;- std::fs::create_dir_all(&config_dir)- .map_err(|e| format!("Failed to create pi config dir: {}", e))?;-- // -- models.json: merge providers into existing config --- let models_path = config_dir.join("models.json");- let mut models_config: serde_json::Value = if models_path.exists() {- let content = std::fs::read_to_string(&models_path).unwrap_or_default();- serde_json::from_str(&content).unwrap_or_else(|_| json!({"providers": {}}))- } else {- json!({"providers": {}})- };+) -> serde_json::Value {+ let mut providers_map = serde_json::Map::new();// Always add screenpipe cloud provider- // Use actual token value in apiKey (not env var name) — Pi v0.51.1+ may not- // resolve env var names reliably, causing tier=anonymous on the gateway.- // Falls back to env var name for backwards compatibility when token is absent.let api_key_value = user_token.unwrap_or("SCREENPIPE_API_KEY");let screenpipe_provider = json!({"baseUrl": SCREENPIPE_API_URL,@@ -699,15 +688,7 @@ fn ensure_pi_config("authHeader": true,"models": screenpipe_cloud_models()});-- if let Some(providers) = models_config- .get_mut("providers")- .and_then(|p| p.as_object_mut())- {- providers.insert("screenpipe".to_string(), screenpipe_provider);- } else {- models_config = json!({"providers": {"screenpipe": screenpipe_provider}});- }+ providers_map.insert("screenpipe".to_string(), screenpipe_provider);// Add the user's selected provider (if not screenpipe-cloud)if let Some(config) = provider_config {@@ -733,23 +714,18 @@ fn ensure_pi_config(config.url.clone()};- // Pi's models.json schema requires baseUrl to have minLength: 1.- // Writing an empty baseUrl poisons the entire file and breaks ALL- // providers (including screenpipe cloud). Skip the entry instead.if base_url.is_empty() {warn!("skipping pi provider '{}': no baseUrl configured (would invalidate models.json)",provider_name);} else {- // Pi resolves apiKey values as env var names, so reference the env var- // we'll set when spawning the processlet api_key = match config.provider.as_str() {- "native-ollama" => "ollama".to_string(), // Ollama ignores API key but Pi requires one- "openai" => "OPENAI_API_KEY".to_string(), // Pi will read from env- "openai-chatgpt" => "OPENAI_CHATGPT_TOKEN".to_string(), // OAuth token from env- "anthropic" => "ANTHROPIC_API_KEY".to_string(), // Pi will read from env- "custom" => "CUSTOM_API_KEY".to_string(), // Pi will read from env+ "native-ollama" => "ollama".to_string(),+ "openai" => "OPENAI_API_KEY".to_string(),+ "openai-chatgpt" => "OPENAI_CHATGPT_TOKEN".to_string(),+ "anthropic" => "ANTHROPIC_API_KEY".to_string(),+ "custom" => "CUSTOM_API_KEY".to_string(),_ => "".to_string(),};@@ -776,16 +752,26 @@ fn ensure_pi_config(]});- if let Some(providers) = models_config- .get_mut("providers")- .and_then(|p| p.as_object_mut())- {- providers.insert(provider_name.to_string(), user_provider);- }+ providers_map.insert(provider_name.to_string(), user_provider);}}}+ json!({"providers": providers_map})+}++/// Write pi's provider config (models.json + auth.json).+fn ensure_pi_config(+ user_token: Option<&str>,+ provider_config: Option<&PiProviderConfig>,+) -> Result<(), String> {+ let config_dir = get_pi_config_dir()?;+ std::fs::create_dir_all(&config_dir)+ .map_err(|e| format!("Failed to create pi config dir: {}", e))?;++ let models_config = build_models_json(user_token, provider_config);++ let models_path = config_dir.join("models.json");let models_str = serde_json::to_string_pretty(&models_config).map_err(|e| format!("Failed to serialize models config: {}", e))?;std::fs::write(&models_path, models_str)@@ -2721,4 +2707,133 @@ mod tests {assert_eq!(super::read_lines_lossy(&mut reader), None);}++ // -- build_models_json tests --++ use super::{build_models_json, PiProviderConfig};++ fn make_provider_config(provider: &str, model: &str) -> PiProviderConfig {+ PiProviderConfig {+ provider: provider.to_string(),+ url: String::new(),+ model: model.to_string(),+ api_key: None,+ max_tokens: 4096,+ system_prompt: None,+ }+ }++ #[test]+ fn test_build_models_json_default_has_screenpipe_provider() {+ let config = build_models_json(None, None);+ let providers = config["providers"].as_object().unwrap();+ assert!(providers.contains_key("screenpipe"));+ assert_eq!(providers.len(), 1);++ let sp = &providers["screenpipe"];+ assert_eq!(sp["baseUrl"], "https://api.screenpi.pe/v1");+ assert_eq!(sp["api"], "openai-completions");+ assert_eq!(sp["apiKey"], "SCREENPIPE_API_KEY");+ assert_eq!(sp["authHeader"], true);+ assert!(sp["models"].as_array().unwrap().len() > 0);+ }++ #[test]+ fn test_build_models_json_with_user_token() {+ let config = build_models_json(Some("tok_abc123"), None);+ let sp = &config["providers"]["screenpipe"];+ assert_eq!(sp["apiKey"], "tok_abc123");+ }++ #[test]+ fn test_build_models_json_screenpipe_cloud_no_extra_provider() {+ let pc = make_provider_config("screenpipe-cloud", "auto");+ let config = build_models_json(None, Some(&pc));+ let providers = config["providers"].as_object().unwrap();+ // screenpipe-cloud maps to "" (empty), so only the screenpipe provider is added+ assert_eq!(providers.len(), 1);+ assert!(providers.contains_key("screenpipe"));+ }++ #[test]+ fn test_build_models_json_openai_adds_second_provider() {+ let pc = make_provider_config("openai", "gpt-4o");+ let config = build_models_json(None, Some(&pc));+ let providers = config["providers"].as_object().unwrap();+ assert_eq!(providers.len(), 2);+ assert!(providers.contains_key("screenpipe"));+ assert!(providers.contains_key("openai-byok"));++ let openai = &providers["openai-byok"];+ assert_eq!(openai["baseUrl"], "https://api.openai.com/v1");+ assert_eq!(openai["api"], "openai-completions");+ assert_eq!(openai["apiKey"], "OPENAI_API_KEY");+ let models = openai["models"].as_array().unwrap();+ assert_eq!(models.len(), 1);+ assert_eq!(models[0]["id"], "gpt-4o");+ }++ #[test]+ fn test_build_models_json_ollama_provider() {+ let pc = make_provider_config("native-ollama", "llama3");+ let config = build_models_json(None, Some(&pc));+ let providers = config["providers"].as_object().unwrap();+ assert!(providers.contains_key("ollama"));+ assert_eq!(providers["ollama"]["baseUrl"], "http://localhost:11434/v1");+ }++ #[test]+ fn test_build_models_json_anthropic_provider() {+ let pc = make_provider_config("anthropic", "claude-sonnet-4-5");+ let config = build_models_json(None, Some(&pc));+ let providers = config["providers"].as_object().unwrap();+ assert!(providers.contains_key("anthropic-byok"));+ assert_eq!(+ providers["anthropic-byok"]["baseUrl"],+ "https://api.anthropic.com"+ );+ assert_eq!(providers["anthropic-byok"]["api"], "anthropic-messages");+ }++ #[test]+ fn test_build_models_json_custom_with_empty_url_skipped() {+ // custom provider with empty URL should be skipped (would invalidate schema)+ let pc = make_provider_config("custom", "my-model");+ let config = build_models_json(None, Some(&pc));+ let providers = config["providers"].as_object().unwrap();+ assert_eq!(providers.len(), 1); // only screenpipe+ assert!(!providers.contains_key("custom"));+ }++ #[test]+ fn test_build_models_json_custom_with_url() {+ let mut pc = make_provider_config("custom", "my-model");+ pc.url = "http://my-server:8080/v1".to_string();+ let config = build_models_json(None, Some(&pc));+ let providers = config["providers"].as_object().unwrap();+ assert_eq!(providers.len(), 2);+ assert!(providers.contains_key("custom"));+ assert_eq!(providers["custom"]["baseUrl"], "http://my-server:8080/v1");+ }++ #[test]+ fn test_build_models_json_no_stale_providers() {+ // The key regression test: even if an old models.json had a corrupted+ // provider, build_models_json always produces a clean config with only+ // the providers we explicitly add. This is a pure function so there is+ // no file to corrupt — the test verifies the output shape is always valid.+ let config = build_models_json(Some("tok"), None);+ let providers = config["providers"].as_object().unwrap();++ // Only "screenpipe" — no leftover providers+ assert_eq!(providers.len(), 1);++ // Every model has required fields for pi-coding-agent schema+ let models = providers["screenpipe"]["models"].as_array().unwrap();+ for m in models {+ assert!(m["id"].as_str().unwrap().len() > 0, "model missing id");+ assert!(m["cost"]["input"].is_number(), "model missing cost.input");+ assert!(m["cost"]["output"].is_number(), "model missing cost.output");+ }+ }}diff --git a/crates/screenpipe-core/src/agents/pi.rs b/crates/screenpipe-core/src/agents/pi.rsindex cfaa592c5..bee64cf94 100644--- a/crates/screenpipe-core/src/agents/pi.rs+++ b/crates/screenpipe-core/src/agents/pi.rs@@ -271,14 +271,12 @@ impl PiExecutor {let config_dir = get_pi_config_dir()?;std::fs::create_dir_all(&config_dir)?;- // -- models.json: merge screenpipe provider into existing providers --+ // -- models.json: build clean config with only managed providers --+ // Writing from scratch prevents stale/schema-invalid providers left over+ // from older versions from poisoning pi-coding-agent's Ajv validation,+ // which would reject the entire file and hide all custom providers.let models_path = config_dir.join("models.json");- let mut models_config: serde_json::Value = if models_path.exists() {- let content = std::fs::read_to_string(&models_path).unwrap_or_default();- serde_json::from_str(&content).unwrap_or_else(|_| json!({"providers": {}}))- } else {- json!({"providers": {}})- };+ let mut models_config = json!({"providers": {}});// Only add screenpipe cloud provider if it's the intended provider// (or no provider specified). If the user explicitly chose ollama/openai/custom,@@ -317,17 +315,6 @@ impl PiExecutor {.and_then(|p| p.as_object_mut()){providers.insert("screenpipe".to_string(), screenpipe_provider);- } else {- models_config = json!({"providers": {"screenpipe": screenpipe_provider}});- }- } else {- // Remove screenpipe provider if it exists from a previous config to avoid- // silent credit drain when user explicitly chose a different provider.- if let Some(providers) = models_config- .get_mut("providers")- .and_then(|p| p.as_object_mut())- {- providers.remove("screenpipe");}}@@ -454,7 +441,7 @@ impl PiExecutor {}}- debug!("pi config merged at {:?}", models_path);+ debug!("pi config written at {:?}", models_path);Ok(())}