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
perf: pass AI preset prompt as system prompt to Pi for prompt caching
Louis Beaumont5e1f34059d54
diff --git a/apps/screenpipe-app-tauri/components/standalone-chat.tsx b/apps/screenpipe-app-tauri/components/standalone-chat.tsxindex 1eba2a637..dbc1cd5a2 100644--- a/apps/screenpipe-app-tauri/components/standalone-chat.tsx+++ b/apps/screenpipe-app-tauri/components/standalone-chat.tsx@@ -1512,15 +1512,21 @@ export function StandaloneChat({ className }: { className?: string } = {}) {// Build Pi provider config from active presetconst buildProviderConfig = useCallback(() => {if (!activePreset) return null;+ // Combine the screenpipe search instructions with the user's preset prompt.+ // This is passed via --append-system-prompt to Pi, enabling Anthropic prompt+ // caching (90% input cost reduction on subsequent messages).+ const presetPrompt = activePreset.prompt || "";+ const systemPrompt = `${buildSystemPrompt()}\n\n${presetPrompt}`.trim() || null;return {provider: activePreset.provider,url: activePreset.url || "",model: activePreset.model || "",apiKey: ("apiKey" in activePreset ? (activePreset.apiKey as string) : null) || null,maxTokens: (activePreset as any).maxTokens ?? 4096,+ systemPrompt,};// eslint-disable-next-line react-hooks/exhaustive-deps- }, [activePreset?.provider, activePreset?.url, activePreset?.model, activePreset?.apiKey, (activePreset as any)?.maxTokens]);+ }, [activePreset?.provider, activePreset?.url, activePreset?.model, activePreset?.apiKey, (activePreset as any)?.maxTokens, activePreset?.prompt]);// Check Pi status on mount — Pi is auto-started at app boot by RustuseEffect(() => {diff --git a/apps/screenpipe-app-tauri/lib/utils/tauri.ts b/apps/screenpipe-app-tauri/lib/utils/tauri.tsindex 9cd3fe6f2..cbe84f2d5 100644--- a/apps/screenpipe-app-tauri/lib/utils/tauri.ts+++ b/apps/screenpipe-app-tauri/lib/utils/tauri.ts@@ -983,7 +983,11 @@ apiKey: string | null;/*** Max output tokens (default 4096)*/-maxTokens?: number }+maxTokens?: number;+/**+ * Optional system prompt from AI preset (appended to Pi's built-in system prompt)+ */+systemPrompt?: string | null }export type PipeSuggestionsSettings = { enabled: boolean; frequencyHours: number }export type SettingsStore =/**diff --git a/apps/screenpipe-app-tauri/src-tauri/src/pi.rs b/apps/screenpipe-app-tauri/src-tauri/src/pi.rsindex 38b5d29f1..f0637c8c4 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/pi.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/pi.rs@@ -678,6 +678,9 @@ pub struct PiProviderConfig {/// Max output tokens (default 4096)#[serde(default = "default_max_tokens")]pub max_tokens: i32,+ /// Optional system prompt from AI preset (appended to Pi's built-in system prompt)+ #[serde(default)]+ pub system_prompt: Option<String>,}fn default_max_tokens() -> i32 {@@ -1189,6 +1192,17 @@ pub async fn pi_start_inner(cmd.args(["--append-system-prompt", api_hint]);}+ // Append the user's AI preset system prompt (enables Anthropic prompt caching —+ // Pi's built-in system prompt + this text form the cached prefix, reducing+ // input costs by 90% on subsequent messages in the same conversation)+ if let Some(ref config) = provider_config {+ if let Some(ref prompt) = config.system_prompt {+ if !prompt.is_empty() {+ cmd.args(["--append-system-prompt", prompt]);+ }+ }+ }+// Bun 1.3+ fixed the readline pipe bug (bun 1.2 needed a PTY workaround).// The bundled bun is 1.3.10, so piped stdin works correctly.// PTY canonical mode has a ~1024-byte line limit on macOS which silently