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: restart Pi on preset switch + disable web search for non-cloud providers

Louis Beaumontf3e55dbcf36b
diff --git a/apps/screenpipe-app-tauri/components/standalone-chat.tsx b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
index 78420c69b..ba7cc705b 100644
--- a/apps/screenpipe-app-tauri/components/standalone-chat.tsx
+++ b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
@@ -1454,8 +1454,8 @@ export function StandaloneChat({ className }: { className?: string } = {}) {
// Track previous preset to detect changes
const prevPresetRef = useRef<{ provider?: string; model?: string; token?: string | null }>({});
- // Update Pi config when user switches preset — no restart, just update config files.
- // Pi picks up the new provider/model on the next prompt.
+ // Restart Pi when user switches preset so the new model takes effect immediately.
+ // Pi uses CLI args from startup, so config-only updates don't change the running model.
useEffect(() => {
if (!activePreset) return;
const prev = prevPresetRef.current;
@@ -1467,9 +1467,9 @@ export function StandaloneChat({ className }: { className?: string } = {}) {
if (!presetChanged && !tokenChanged) return;
const providerConfig = buildProviderConfig();
- console.log("[Pi] Config updated (no restart):", providerConfig?.provider, providerConfig?.model);
+ console.log("[Pi] Preset changed, restarting:", providerConfig?.provider, providerConfig?.model);
commands.piUpdateConfig(settings.user?.token ?? null, providerConfig).catch((e) => {
- console.error("[Pi] Config update failed:", e);
+ console.error("[Pi] Preset switch failed:", e);
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [activePreset?.provider, activePreset?.model, settings.user?.token]);
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/pi.rs b/apps/screenpipe-app-tauri/src-tauri/src/pi.rs
index 9781a7c0f..3dcf1cd29 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/pi.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/pi.rs
@@ -361,20 +361,46 @@ fn ensure_screenpipe_skill(project_dir: &str) -> Result<(), String> {
}
/// Ensure the web-search extension exists in the project's .pi/extensions directory
-fn ensure_web_search_extension(project_dir: &str) -> Result<(), String> {
+/// Install or remove the web-search extension based on provider.
+/// Web search uses the screenpipe cloud backend (Gemini + Google Search),
+/// so we only enable it for screenpipe-cloud presets to avoid sending
+/// user data to our backend when they chose a local/custom provider.
+fn ensure_web_search_extension(
+ project_dir: &str,
+ provider_config: Option<&PiProviderConfig>,
+) -> Result<(), String> {
let ext_dir = std::path::Path::new(project_dir)
.join(".pi")
.join("extensions");
let ext_path = ext_dir.join("web-search.ts");
- std::fs::create_dir_all(&ext_dir)
- .map_err(|e| format!("Failed to create extensions dir: {}", e))?;
+ let is_screenpipe_cloud = match provider_config {
+ Some(config) => matches!(
+ config.provider.as_str(),
+ "screenpipe-cloud" | "pi"
+ ),
+ None => true, // default preset = screenpipe cloud
+ };
+
+ if is_screenpipe_cloud {
+ std::fs::create_dir_all(&ext_dir)
+ .map_err(|e| format!("Failed to create extensions dir: {}", e))?;
+
+ let ext_content = include_str!("../assets/extensions/web-search.ts");
+ std::fs::write(&ext_path, ext_content)
+ .map_err(|e| format!("Failed to write web-search extension: {}", e))?;
- let ext_content = include_str!("../assets/extensions/web-search.ts");
- std::fs::write(&ext_path, ext_content)
- .map_err(|e| format!("Failed to write web-search extension: {}", e))?;
+ debug!("Web search extension installed at {:?}", ext_path);
+ } else if ext_path.exists() {
+ std::fs::remove_file(&ext_path)
+ .map_err(|e| format!("Failed to remove web-search extension: {}", e))?;
+
+ info!(
+ "Web search extension removed (provider {:?} is not screenpipe-cloud)",
+ provider_config.map(|c| &c.provider)
+ );
+ }
- debug!("Web search extension installed at {:?}", ext_path);
Ok(())
}
@@ -696,8 +722,8 @@ pub async fn pi_start_inner(
// Ensure screenpipe-search skill exists in project
ensure_screenpipe_skill(&project_dir)?;
- // Ensure web-search extension exists in project
- ensure_web_search_extension(&project_dir)?;
+ // Install web-search extension only for screenpipe-cloud presets
+ ensure_web_search_extension(&project_dir, provider_config.as_ref())?;
// Ensure Pi is configured with the user's provider
ensure_pi_config(user_token.as_deref(), provider_config.as_ref())?;
@@ -1118,20 +1144,33 @@ pub async fn pi_check() -> Result<PiCheckResult, String> {
})
}
-/// Update Pi config files (models.json / auth.json) without restarting the process.
-/// Call this when the user changes preset — Pi picks up the new config on next prompt.
+/// Update Pi config and restart the chat session so the new model takes effect.
+/// Without restart, Pi keeps using the provider/model from its original CLI args.
#[tauri::command]
#[specta::specta]
pub async fn pi_update_config(
+ app: AppHandle,
+ state: State<'_, PiState>,
user_token: Option<String>,
provider_config: Option<PiProviderConfig>,
) -> Result<(), String> {
- ensure_pi_config(user_token.as_deref(), provider_config.as_ref())?;
info!(
- "Pi config updated (provider: {:?}, model: {:?})",
+ "Pi preset changed (provider: {:?}, model: {:?}) — restarting chat session",
provider_config.as_ref().map(|c| &c.provider),
provider_config.as_ref().map(|c| &c.model),
);
+
+ // Resolve the chat project directory
+ let home = dirs::home_dir().ok_or("could not resolve home directory")?;
+ let project_dir = home
+ .join(".screenpipe")
+ .join("pi-chat")
+ .to_string_lossy()
+ .to_string();
+
+ // Restart Pi for the "chat" session with the new provider/model
+ pi_start_inner(app, &state, "chat", project_dir, user_token, provider_config).await?;
+
Ok(())
}
diff --git a/crates/screenpipe-core/src/agents/pi.rs b/crates/screenpipe-core/src/agents/pi.rs
index 5884573b2..ce955f001 100644
--- a/crates/screenpipe-core/src/agents/pi.rs
+++ b/crates/screenpipe-core/src/agents/pi.rs
@@ -114,15 +114,35 @@ impl PiExecutor {
Ok(())
}
- /// Ensure the web-search extension exists in `project_dir/.pi/extensions/`.
- pub fn ensure_web_search_extension(project_dir: &Path) -> Result<()> {
+ /// Install or remove the web-search extension based on provider.
+ /// Web search uses the screenpipe cloud backend, so we only enable it
+ /// for screenpipe-cloud to avoid sending data to our backend when the
+ /// user chose a local/custom provider.
+ pub fn ensure_web_search_extension(
+ project_dir: &Path,
+ provider: Option<&str>,
+ ) -> Result<()> {
let ext_dir = project_dir.join(".pi").join("extensions");
let ext_path = ext_dir.join("web-search.ts");
- std::fs::create_dir_all(&ext_dir)?;
- let ext_content = include_str!("../../assets/extensions/web-search.ts");
- std::fs::write(&ext_path, ext_content)?;
- debug!("web-search extension installed at {:?}", ext_path);
+ let is_screenpipe_cloud = matches!(
+ provider,
+ None | Some("screenpipe") | Some("screenpipe-cloud") | Some("pi")
+ );
+
+ if is_screenpipe_cloud {
+ std::fs::create_dir_all(&ext_dir)?;
+ let ext_content = include_str!("../../assets/extensions/web-search.ts");
+ std::fs::write(&ext_path, ext_content)?;
+ debug!("web-search extension installed at {:?}", ext_path);
+ } else if ext_path.exists() {
+ std::fs::remove_file(&ext_path)?;
+ info!(
+ "web-search extension removed (provider {:?} is not screenpipe-cloud)",
+ provider
+ );
+ }
+
Ok(())
}
@@ -558,15 +578,16 @@ impl AgentExecutor for PiExecutor {
provider_url,
)?;
Self::ensure_screenpipe_skill(working_dir)?;
- Self::ensure_web_search_extension(working_dir)?;
-
- let pi_path = find_pi_executable()
- .ok_or_else(|| anyhow!("pi not found. install with: bun add -g {}", PI_PACKAGE))?;
// Provider resolution:
// 1. Explicit provider from pipe frontmatter → use it
// 2. No provider specified → screenpipe cloud (default)
let resolved_provider = provider.unwrap_or("screenpipe").to_string();
+
+ Self::ensure_web_search_extension(working_dir, Some(&resolved_provider))?;
+
+ let pi_path = find_pi_executable()
+ .ok_or_else(|| anyhow!("pi not found. install with: bun add -g {}", PI_PACKAGE))?;
let resolved_model = Self::resolve_model(model, &resolved_provider);
info!(
@@ -641,7 +662,7 @@ impl AgentExecutor for PiExecutor {
provider_url,
)?;
Self::ensure_screenpipe_skill(working_dir)?;
- Self::ensure_web_search_extension(working_dir)?;
+ Self::ensure_web_search_extension(working_dir, Some(&resolved_provider))?;
let pi_path = find_pi_executable()
.ok_or_else(|| anyhow!("pi not found. install with: bun add -g {}", PI_PACKAGE))?;