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(pipes): resolve presets from encrypted store.bin

Louis Beaumont92b182008f26
diff --git a/Cargo.lock b/Cargo.lock
index 9cf6563da..bd99d4891 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -7905,6 +7905,7 @@ dependencies = [
"reqwest 0.13.3",
"screenpipe-events",
"screenpipe-secrets",
+ "screenpipe-vault",
"serde",
"serde_json",
"serde_yaml",
diff --git a/crates/screenpipe-core/Cargo.toml b/crates/screenpipe-core/Cargo.toml
index 800060c08..e1052a145 100644
--- a/crates/screenpipe-core/Cargo.toml
+++ b/crates/screenpipe-core/Cargo.toml
@@ -46,6 +46,7 @@ reqwest = { workspace = true }
hex = { version = "0.4", optional = true }
async-trait = "0.1"
screenpipe-secrets = { path = "../screenpipe-secrets", optional = true }
+screenpipe-vault = { path = "../screenpipe-vault", optional = true }
sqlx = { version = "0.7", features = ["sqlite", "runtime-tokio-rustls"], optional = true }
once_cell = "1.19.0"
@@ -63,7 +64,7 @@ default = ["security"]
# without changing behavior (it's never enabled at compile time).
cargo-clippy = []
security = ["dep:regex", "dep:lazy_static"]
-secrets = ["dep:screenpipe-secrets", "dep:sqlx"]
+secrets = ["dep:screenpipe-secrets", "dep:screenpipe-vault", "dep:sqlx"]
cloud-sync = [
"dep:argon2",
"dep:chacha20poly1305",
diff --git a/crates/screenpipe-core/src/pipes/mod.rs b/crates/screenpipe-core/src/pipes/mod.rs
index 07c752a0b..35b27350c 100644
--- a/crates/screenpipe-core/src/pipes/mod.rs
+++ b/crates/screenpipe-core/src/pipes/mod.rs
@@ -881,6 +881,50 @@ fn refresh_chatgpt_token(token_data: &mut serde_json::Value, now: u64) {
}
}
+/// Magic prefix written by the app/CLI when `store.bin` is encrypted.
+/// Matches `STORE_MAGIC` in `screenpipe-engine/src/cli/store_file.rs`.
+const STORE_MAGIC: &[u8; 8] = b"SPSTORE1";
+
+/// Read `store.bin`, decrypting via the secrets keychain key if it starts with
+/// the `SPSTORE1` magic prefix. Keeps `resolve_preset` and `pipe models list`
+/// in agreement on encrypted stores; before this helper the runner did a plain
+/// `read_to_string` and silently failed when the file was encrypted.
+fn read_store_bin(path: &Path) -> Option<serde_json::Value> {
+ let data = std::fs::read(path).ok()?;
+ if data.len() >= STORE_MAGIC.len() && &data[..STORE_MAGIC.len()] == STORE_MAGIC {
+ #[cfg(feature = "secrets")]
+ {
+ use screenpipe_secrets::keychain::{get_key, KeyResult};
+ let key = match get_key() {
+ KeyResult::Found(k) => k,
+ _ => {
+ warn!(
+ "store.bin is encrypted but keychain key is unavailable; \
+ pipe preset resolution will fail. Open the app once or \
+ disable store encryption."
+ );
+ return None;
+ }
+ };
+ let plaintext =
+ screenpipe_vault::crypto::decrypt_small(&data[STORE_MAGIC.len()..], &key).ok()?;
+ return serde_json::from_slice(&plaintext).ok();
+ }
+ #[cfg(not(feature = "secrets"))]
+ {
+ warn!(
+ "store.bin is encrypted but this build lacks the `secrets` feature; \
+ cannot read AI presets"
+ );
+ return None;
+ }
+ }
+ if data.iter().all(|b| b.is_ascii_whitespace()) {
+ return Some(serde_json::json!({}));
+ }
+ serde_json::from_slice(&data).ok()
+}
+
/// Read `~/.screenpipe/store.bin` and find the preset by id.
/// Falls back to the default preset if `preset_id` is `"default"`.
/// Creates store.bin with a default preset if it doesn't exist (CLI mode).
@@ -926,8 +970,7 @@ fn resolve_preset(pipes_dir: &Path, preset_id: &str) -> Option<ResolvedPreset> {
}
}
- let content = std::fs::read_to_string(&store_path).ok()?;
- let store: serde_json::Value = serde_json::from_str(&content).ok()?;
+ let store = read_store_bin(&store_path)?;
let presets = store.get("settings")?.get("aiPresets")?.as_array()?;
// Normalize legacy preset IDs to current names
@@ -1006,6 +1049,28 @@ fn resolve_preset(pipes_dir: &Path, preset_id: &str) -> Option<ResolvedPreset> {
})
}
+/// Enumerate the preset IDs currently in `store.bin`, for surfacing in error
+/// messages. Returns an empty vec if the store is missing or unreadable —
+/// callers should phrase the message accordingly.
+fn list_available_preset_ids(pipes_dir: &Path) -> Vec<String> {
+ let Some(parent) = pipes_dir.parent() else {
+ return Vec::new();
+ };
+ let Some(store) = read_store_bin(&parent.join("store.bin")) else {
+ return Vec::new();
+ };
+ store
+ .get("settings")
+ .and_then(|s| s.get("aiPresets"))
+ .and_then(|p| p.as_array())
+ .map(|arr| {
+ arr.iter()
+ .filter_map(|p| p.get("id").and_then(|v| v.as_str()).map(str::to_string))
+ .collect()
+ })
+ .unwrap_or_default()
+}
+
// ---------------------------------------------------------------------------
// Structured error parsing from stderr
// ---------------------------------------------------------------------------
@@ -2268,12 +2333,20 @@ impl PipeManager {
)
}
None => {
+ let available = list_available_preset_ids(&self.pipes_dir);
+ let available_hint = if available.is_empty() {
+ String::from("no presets are configured")
+ } else {
+ format!("available presets: {}", available.join(", "))
+ };
return Err(anyhow!(
- "pipe '{}': preset '{}' not found in settings — \
- create the preset in Settings → AI or remove the \
- 'preset: {}' line from the pipe config",
+ "pipe '{}': preset '{}' not found in settings — {}. \
+ Set one of those in the pipe's `preset:` field, or \
+ create a new preset with `screenpipe pipe models create {} --provider … --model …`, \
+ or remove the `preset:` line to use the default.",
name,
preset_id,
+ available_hint,
preset_id
));
}