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(windows): stop the mcp prewarm opening a terminal on every launch

louis0301953b45db8044e4
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/pi.rs b/apps/screenpipe-app-tauri/src-tauri/src/pi.rs
index 27b54e5d4..3ce0e704b 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/pi.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/pi.rs
@@ -267,17 +267,19 @@ fn build_command_for_path(path: &str) -> Command {
cmd.arg(js);
return cmd;
}
- // Not a bun shim or resolution failed — run .exe directly
- Command::new(path)
+ // Not a bun shim or resolution failed — run .exe directly. Still a
+ // console program, so it gets the same treatment as the bun path
+ // above rather than being the one branch that flashes.
+ screenpipe_core::no_window_command(path)
} else {
- Command::new(path)
+ screenpipe_core::no_window_command(path)
}
} else if let Some(bun) = find_bun_executable() {
let mut cmd = bun_command(&bun);
cmd.arg(path);
cmd
} else {
- Command::new(path)
+ screenpipe_core::no_window_command(path)
}
}
@@ -290,7 +292,9 @@ fn build_command_for_path(path: &str) -> Command {
cmd.arg(path);
cmd
} else {
- Command::new(path)
+ // A no-op off Windows, kept in the same shape as the windows arm so
+ // both read as "every command this factory returns is guarded".
+ screenpipe_core::no_window_command(path)
}
}
@@ -1239,7 +1243,12 @@ fn apply_no_window(cmd: &mut Command) {
}
fn bun_command(bun: &str) -> Command {
- let mut cmd = Command::new(bun);
+ // No-window at construction, not left to `run_command_output`: bun is a
+ // console program and not every caller runs it through that helper. The
+ // screenpipe-mcp prewarm spawns this directly at every launch and waits up
+ // to two minutes for it, so the missing flag was a terminal sitting on the
+ // user's desktop for the whole startup.
+ let mut cmd = screenpipe_core::no_window_command(bun);
// Single source of truth in screenpipe-core: on Linux, bun subprocesses
// must not inherit the app's LD_LIBRARY_PATH, or bundled runtimes like
// AppImage can make bun crash before it prints diagnostics.
diff --git a/crates/screenpipe-core/src/agents/pi.rs b/crates/screenpipe-core/src/agents/pi.rs
index 8f6aee548..472baab3a 100644
--- a/crates/screenpipe-core/src/agents/pi.rs
+++ b/crates/screenpipe-core/src/agents/pi.rs
@@ -2880,14 +2880,18 @@ pub fn scrub_bun_runtime_env(cmd: &mut std::process::Command) {
}
}
+/// bun is a console program, so the flag belongs here and not at the call
+/// sites. A factory that hands out an unguarded `Command` makes every caller
+/// responsible for remembering it, and the callers that spawn directly instead
+/// of going through a `*_output` helper did not.
fn std_bun_command(bun: &str) -> std::process::Command {
- let mut cmd = std::process::Command::new(bun);
+ let mut cmd = crate::no_window::no_window_command(bun);
scrub_bun_runtime_env(&mut cmd);
cmd
}
fn tokio_bun_command(bun: &str) -> tokio::process::Command {
- let mut cmd = tokio::process::Command::new(bun);
+ let mut cmd = crate::no_window::no_window_command_async(bun);
if should_scrub_bun_runtime_env() {
cmd.env_remove("LD_LIBRARY_PATH");
}
@@ -3210,7 +3214,7 @@ fn build_async_command(path: &str) -> tokio::process::Command {
c
}
} else {
- tokio::process::Command::new(path)
+ crate::no_window::no_window_command_async(path)
};
// Inject bundled bun directory into PATH so node_modules resolve correctly.
diff --git a/crates/screenpipe-core/tests/no_console_flash.rs b/crates/screenpipe-core/tests/no_console_flash.rs
index 3d5fe4ea6..658e35108 100644
--- a/crates/screenpipe-core/tests/no_console_flash.rs
+++ b/crates/screenpipe-core/tests/no_console_flash.rs
@@ -217,3 +217,91 @@ fn console_programs_are_never_spawned_without_create_no_window() {
offenders.join("\n ")
);
}
+
+/// True when the function declared on this line hands a `Command` back to its
+/// caller.
+fn is_command_factory(line: &str) -> bool {
+ if !is_fn_signature(line) {
+ return false;
+ }
+ let t = line.trim_end().trim_end_matches('{').trim_end();
+ t.ends_with("-> Command")
+ || t.ends_with("-> std::process::Command")
+ || t.ends_with("-> tokio::process::Command")
+}
+
+/// A factory's callers cannot see whether the flag was set, so the factory has
+/// to set it.
+///
+/// The literal-program-name scan above cannot catch this shape: the program is
+/// a variable (`bun`, a resolved path) and the spawn happens somewhere else
+/// entirely. That is how the screenpipe-mcp prewarm shipped a terminal on every
+/// Windows launch — `bun_command` returned an unguarded `Command`, the install
+/// path happened to run it through a helper that added the flag, and the
+/// prewarm spawned it directly and then waited two minutes with a console
+/// sitting on the user's desktop.
+#[test]
+fn command_factories_guard_every_command_they_hand_out() {
+ let Some(root) = repo_root() else {
+ return;
+ };
+
+ let mut files = Vec::new();
+ collect_rs(&root.join("crates"), &mut files);
+ collect_rs(
+ &root.join("apps/screenpipe-app-tauri/src-tauri/src"),
+ &mut files,
+ );
+
+ let mut offenders = Vec::new();
+ for file in &files {
+ let Ok(text) = fs::read_to_string(file) else {
+ continue;
+ };
+ let lines: Vec<&str> = text.lines().collect();
+ let mut in_test_mod = false;
+ for (i, line) in lines.iter().enumerate() {
+ if line.contains("#[cfg(test)]") {
+ in_test_mod = true;
+ }
+ if in_test_mod || !is_command_factory(line) {
+ continue;
+ }
+ let (_, end) = enclosing_fn_range(&lines, i + 1);
+ for j in (i + 1)..end {
+ if !lines[j].contains("Command::new(") {
+ continue;
+ }
+ if is_non_windows_branch(&lines, i, j) {
+ continue;
+ }
+ // Same per-spawn region as above: a guarded sibling must not
+ // vouch for an unguarded one.
+ let region_end = ((j + 1)..end)
+ .find(|&k| {
+ lines[k].contains("Command::new") || lines[k].contains("no_window_command")
+ })
+ .unwrap_or(end)
+ .min(j + 25);
+ let region = lines[j..region_end.max(j + 1)].join("\n");
+ if GUARDS.iter().any(|guard| region.contains(guard)) {
+ continue;
+ }
+ offenders.push(format!(
+ "{}:{} hands out an unguarded Command — `{}`",
+ file.strip_prefix(&root).unwrap_or(file).display(),
+ j + 1,
+ line.trim()
+ ));
+ }
+ }
+ }
+
+ assert!(
+ offenders.is_empty(),
+ "a Command factory must guard what it returns — its callers cannot \
+ tell that it did not. Build it with \
+ `screenpipe_core::no_window_command`/`no_window_command_async`:\n {}",
+ offenders.join("\n ")
+ );
+}