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: timeline always resets to latest when window opens
Louis Beaumontca45485a0528
diff --git a/apps/screenpipe-app-tauri/components/rewind/timeline.tsx b/apps/screenpipe-app-tauri/components/rewind/timeline.tsxindex a1d38c590..ed15e5d56 100644--- a/apps/screenpipe-app-tauri/components/rewind/timeline.tsx+++ b/apps/screenpipe-app-tauri/components/rewind/timeline.tsx@@ -188,6 +188,15 @@ export default function Timeline() {debounceTimer = setTimeout(() => {debounceTimer = null;console.log("Window focused, refreshing timeline...");++ // Reset position to latest (index 0 = newest frame)+ // Window is hidden/shown not destroyed, so old position persists+ setCurrentIndex(0);+ setCurrentFrame(frames.length > 0 ? frames[0] : null);+ isNavigatingRef.current = false;+ pendingNavigationRef.current = null;+ setSeekingTimestamp(null);+onWindowFocus();}, 500);}@@ -197,7 +206,7 @@ export default function Timeline() {if (debounceTimer) clearTimeout(debounceTimer);unlisten.then((fn) => fn());};- }, [onWindowFocus]);+ }, [onWindowFocus, frames, setCurrentFrame]);// Hide timeline when mouse moves to a different screenuseEffect(() => {@@ -705,25 +714,31 @@ export default function Timeline() {}let currentDateEffect = new Date(currentDate);+ const isToday = isSameDay(currentDateEffect, new Date());const checkIfThereAreFrames = async () => {- const checkFramesForDate = await hasFramesForDate(currentDateEffect);- console.log("checkFramesForDate", currentDateEffect, checkFramesForDate);- // Only auto-navigate to previous day if NOT during intentional navigation- // (e.g., user clicking day arrows). During navigation, handleDateChange- // already handles finding dates with frames.- if (!checkFramesForDate && !isNavigatingRef.current) {- // Prevent infinite loop: stop walking back after MAX_DATE_RETRIES days- if (dateRetryCountRef.current >= MAX_DATE_RETRIES) {- console.warn("no frames found after checking", MAX_DATE_RETRIES, "days back, stopping");- dateRetryCountRef.current = 0;- return;+ // For today, always fetch — live polling will push new frames.+ // The 5-minute buffer in hasFramesForDate can falsely return false+ // when the user just started recording or recently opened the app.+ if (!isToday) {+ const checkFramesForDate = await hasFramesForDate(currentDateEffect);+ console.log("checkFramesForDate", currentDateEffect, checkFramesForDate);+ // Only auto-navigate to previous day if NOT during intentional navigation+ // (e.g., user clicking day arrows). During navigation, handleDateChange+ // already handles finding dates with frames.+ if (!checkFramesForDate && !isNavigatingRef.current) {+ // Prevent infinite loop: stop walking back after MAX_DATE_RETRIES days+ if (dateRetryCountRef.current >= MAX_DATE_RETRIES) {+ console.warn("no frames found after checking", MAX_DATE_RETRIES, "days back, stopping");+ dateRetryCountRef.current = 0;+ return;+ }+ dateRetryCountRef.current += 1;+ setCurrentDate(subDays(currentDateEffect, 1));+ return; // Don't fetch frames for a date we're leaving}- dateRetryCountRef.current += 1;- setCurrentDate(subDays(currentDateEffect, 1));- return; // Don't fetch frames for a date we're leaving}- // Found frames — reset retry counter+ // Found frames (or today) — reset retry counterdateRetryCountRef.current = 0;const startTime = new Date(currentDateEffect);diff --git a/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-search-v2.tsx b/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-search-v2.tsxdeleted file mode 100644index e73bb2eac..000000000--- a/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-search-v2.tsx+++ /dev/null@@ -1,309 +0,0 @@-"use client";--import { useState, useCallback } from "react";-import { Search, Loader2 } from "lucide-react";-import { Button } from "@/components/ui/button";-import { Input } from "@/components/ui/input";-import {- Dialog,- DialogContent,- DialogTitle,- DialogPortal,- DialogOverlay,-} from "@/components/ui/dialog";-import { motion } from "framer-motion";-import { StreamTimeSeriesResponse } from "@/components/rewind/timeline";--interface TimelineSearchProps {- frames: StreamTimeSeriesResponse[];- onResultSelect: (index: number) => void;- onSearchResults?: (results: number[]) => void;-}--// Extract meaningful keywords from frames-function extractKeywords(frames: StreamTimeSeriesResponse[]): string[] {- const keywords = new Map<string, number>();-- // Common words to filter out- const stopWords = new Set([- "the",- "be",- "to",- "of",- "and",- "a",- "in",- "that",- "have",- "i",- "it",- "for",- "not",- "on",- "with",- "he",- "as",- "you",- "do",- "at",- "this",- "but",- "his",- "by",- "from",- "they",- "we",- "say",- "her",- "she",- "or",- "an",- "will",- "my",- "one",- "all",- "would",- "there",- "their",- "what",- "so",- "up",- "out",- "if",- "about",- "who",- "get",- "which",- "go",- "me",- "when",- "make",- "can",- "like",- "time",- "no",- "just",- "him",- "know",- "take",- "people",- "into",- "year",- "your",- "good",- "some",- "could",- "them",- "see",- "other",- "than",- "then",- "now",- "look",- "only",- "come",- "its",- "over",- "think",- "also",- "back",- "after",- "use",- "two",- "how",- "our",- "work",- "first",- "well",- "way",- "even",- "new",- "want",- "because",- "any",- "these",- "give",- "day",- "most",- "us",- ]);-- // Patterns for valuable information- const patterns = {- email: /\b[\w\.-]+@[\w\.-]+\.\w+\b/g,- url: /https?:\/\/[^\s]+/g,- date: /\b\d{1,2}[-/]\d{1,2}[-/]\d{2,4}\b|\b(?:jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]* \d{1,2}(?:st|nd|rd|th)?\b/gi,- time: /\b(?:1[0-2]|0?[1-9])(?::[0-5][0-9])?\s*(?:am|pm)\b/gi,- properNoun: /\b[A-Z][a-z]+(?:\s+[A-Z][a-z]+)*\b/g,- appName:- /\b(?:vscode|chrome|firefox|safari|slack|discord|zoom|teams|figma|notion|github)\b/gi,- codeTerms:- /\b(?:function|class|const|let|var|import|export|async|await|return|if|else|for|while)\b/g,- numbers: /\b\d+(?:\.\d+)?[kmbt]?\b/gi,- };-- frames.forEach((frame) => {- frame.devices.forEach((device) => {- const text = [- device.metadata.ocr_text,- device.metadata.window_name,- ...device.audio.map((a) => a.transcription),- ].join(" ");-- // Extract patterns- Object.entries(patterns).forEach(([type, pattern]) => {- const matches = text.match(pattern) || [];- matches.forEach((match) => {- const key = `${match.toLowerCase()}`;- if (!stopWords.has(key) && key.length > 2) {- keywords.set(key, (keywords.get(key) || 0) + 1);- }- });- });-- // Extract potential important phrases (2-3 words)- const words = text.split(/\s+/);- for (let i = 0; i < words.length - 1; i++) {- const phrase = words- .slice(i, i + 2)- .join(" ")- .toLowerCase();- if (phrase.split(" ").every((word) => !stopWords.has(word))) {- keywords.set(phrase, (keywords.get(phrase) || 0) + 1);- }- }- });- });-- // Score and rank keywords- const scoredKeywords = Array.from(keywords.entries()).map(([word, count]) => {- let score = count;-- // Boost certain types of keywords- if (word.match(patterns.email)) score *= 2;- if (word.match(patterns.properNoun)) score *= 1.5;- if (word.match(patterns.date)) score *= 1.3;- if (word.match(patterns.appName)) score *= 1.2;-- // Penalize very common words- if (count > frames.length / 2) score *= 0.5;-- return { word, score };- });-- // Return top 10 most valuable keywords- return scoredKeywords- .sort((a, b) => b.score - a.score)- .slice(0, 10)- .map((k) => k.word);-}--export function TimelineSearch2({- frames,- onResultSelect,- onSearchResults,-}: TimelineSearchProps) {- const [open, setOpen] = useState(false);- const [searchQuery, setSearchQuery] = useState("");- const [isSearching, setIsSearching] = useState(false);-- const keywords = extractKeywords(frames);-- const handleSearch = useCallback(- (query: string) => {- setIsSearching(true);-- // Find all matching frames- const results = frames.reduce<number[]>((matches, frame, index) => {- const hasMatch = frame.devices.some((device) => {- const searchText = [- device.metadata.ocr_text,- device.metadata.window_name,- ...device.audio.map((a) => a.transcription),- ]- .join(" ")- .toLowerCase();-- return searchText.includes(query.toLowerCase());- });-- if (hasMatch) matches.push(index);- return matches;- }, []);-- // Instead of jumping, send results to parent- if (results.length > 0) {- onSearchResults?.(results);- setOpen(false);- }-- setIsSearching(false);- },- [frames, onSearchResults]- );-- return (- <>- <Button- variant="ghost"- size="icon"- onClick={() => setOpen(true)}- className="rounded-full"- >- <Search className="h-4 w-4" />- </Button>-- <Dialog open={open} onOpenChange={setOpen}>- <DialogPortal>- <DialogOverlay className="bg-background/50" />- <DialogContent className="sm:max-w-[500px]">- <DialogTitle>search your timeline</DialogTitle>- <div className="p-6">- <div className="relative">- <Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />- <Input- autoFocus- placeholder="search in your timeline..."- className="pl-9 h-12"- value={searchQuery}- onChange={(e) => setSearchQuery(e.target.value)}- onKeyDown={(e) => {- if (e.key === "Enter" && !isSearching) {- handleSearch(searchQuery);- }- }}- />- {isSearching && (- <Loader2 className="absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 animate-spin" />- )}- </div>-- <motion.div- initial={{ opacity: 0 }}- animate={{ opacity: 1 }}- className="mt-6"- >- <p className="text-sm text-muted-foreground mb-3">- common keywords- </p>- <div className="flex flex-wrap gap-2">- {keywords.map((keyword) => (- <Button- key={keyword}- variant="outline"- size="sm"- onClick={() => handleSearch(keyword)}- className="text-xs"- >- {keyword}- </Button>- ))}- </div>- </motion.div>- </div>- </DialogContent>- </DialogPortal>- </Dialog>- </>- );-}diff --git a/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-search.tsx b/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-search.tsxdeleted file mode 100644index f2dfd7c68..000000000--- a/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-search.tsx+++ /dev/null@@ -1,861 +0,0 @@-"use client";--import { useState, useMemo, useCallback, useEffect, useRef } from "react";-import { Search, RefreshCw, Loader2, Square } from "lucide-react";-import { Button } from "@/components/ui/button";-import { Input } from "@/components/ui/input";-import {- Dialog,- DialogContent,- DialogTitle,- DialogPortal,- DialogOverlay,-} from "@/components/ui/dialog";-import { motion, AnimatePresence } from "framer-motion";-import { StreamTimeSeriesResponse } from "@/components/rewind/timeline";-import OpenAI from "openai";-import { useSettings } from "@/lib/hooks/use-settings";-import {- Tooltip,- TooltipContent,- TooltipProvider,- TooltipTrigger,-} from "@/components/ui/tooltip";-import posthog from "posthog-js";--interface TimelineSearchProps {- frames: StreamTimeSeriesResponse[];- onResultSelect: (index: number) => void;-}--interface SearchParams {- keywords: string[];-}--interface AppStats {- apps: Record<string, number>;- windows: Record<string, number>;- maxItems: number;-}--function isValidSearchParams(obj: any): obj is SearchParams {- return (- obj &&- typeof obj === "object" &&- Array.isArray(obj.keywords) &&- obj.keywords.every((keyword: string) => typeof keyword === "string")- );-}--async function validateFrameContext(- frames: StreamTimeSeriesResponse[],- centerIndex: number,- searchParams: SearchParams,- openai: OpenAI,- model: string,- systemPrompt: string,-): Promise<{ isRelevant: boolean; confidence: number; reason: string }> {- console.log("validating context for frame:", {- centerIndex,- searchParams,- model,- });-- const windowSize = 1000;- const start = Math.max(0, centerIndex - windowSize);- const end = Math.min(frames.length - 1, centerIndex + windowSize);-- const contextFrames = frames.slice(start, end + 1);- const contextData = contextFrames.map((frame) => ({- ocr: frame.devices.map((d) => d.metadata.ocr_text || "").join(" "),- transcripts: frame.devices- .flatMap((d) => d.audio.map((a) => a.transcription || ""))- .join(" "),- apps: frame.devices.map((d) => d.metadata.app_name || "").join(", "),- windows: frame.devices.map((d) => d.metadata.window_name || "").join(", "),- }));-- console.log("context data being sent to AI:", contextData);-- const response = await openai.chat.completions.create({- model,- messages: [- {- role: "system",- content: systemPrompt,- },- {- role: "user",- content: `given the search parameters: ${JSON.stringify(searchParams)}- and these surrounding frames: ${JSON.stringify(contextData)}-- determine if this is truly a relevant match.- output format: {- "isRelevant": boolean,- "confidence": number, // 0-1- "reason": string // brief explanation- }`,- },- ],- response_format: { type: "json_object" },- });-- console.log(- "validation response from AI:",- response.choices[0]?.message?.content,- );-- if (!response.choices?.[0]?.message?.content) {- throw new Error(- "invalid or empty response from ai:" + JSON.stringify(response, null, 2),- );- }-- return JSON.parse(response.choices[0].message.content);-}--async function findRelevantFrame(- query: string,- frames: StreamTimeSeriesResponse[],- openai: OpenAI,- model: string,- onProgress: (status: string) => void,- systemPrompt: string,- recursionDepth: number = 0,- previousValidation?: { reason: string },- signal?: AbortSignal,-): Promise<number | null> {- if (signal?.aborted) {- throw new Error("AbortError");- }-- console.log("starting search with:", {- query,- model,- recursionDepth,- previousValidation,- });-- // prevent infinite recursion- if (recursionDepth >= 2) {- return null;- }-- onProgress("analyzing your search query to understand what to look for...");-- // enhance query with previous validation feedback- const enhancedQuery = previousValidation- ? `${query} (considering: ${previousValidation.reason})`- : query;-- try {- const response = await openai.chat.completions.create({- model: model,- messages: [- {- role: "system",- content: systemPrompt,- },- {- role: "user",- content: `analyze this search query and extract key information: "${enhancedQuery}"- output format: {- "keywords": string[] // important keywords to match, must be non-empty array- }-- for example, if the user asks "when i was doing annual reflections in obsidian", the output should be:- {- "keywords": ["obsidian", "annual reflections"]- }-- if the user asks "when i was watching a youtube video about rust", the output should be:- {- "keywords": ["youtube", "rust", "video"]- }- `,- },- ],- response_format: { type: "json_object" },- });-- console.log(- "search params response from AI:",- response.choices[0]?.message?.content,- );-- if (!response.choices?.[0]?.message?.content) {- throw new Error(- "invalid or empty response from ai:" +- JSON.stringify(response, null, 2),- );- }-- const jsonContent = response.choices[0].message.content;- const parsed = JSON.parse(jsonContent);- console.log("parsed search params:", parsed);-- if (!isValidSearchParams(parsed)) {- throw new Error(- "invalid or malformed search parameters from ai response",- );- }-- const searchParams = parsed;-- onProgress(- `searching for moments containing: ${searchParams.keywords.join(", ")}...`,- );-- await new Promise((resolve) => setTimeout(resolve, 1000));-- // Add early return after checking N frames- const MAX_FRAMES_TO_CHECK = 1000; // Adjust this number- let framesChecked = 0;-- const BATCH_SIZE = 2000; // Adjust based on performance needs- for (let i = 0; i < frames.length; i += BATCH_SIZE) {- if (signal?.aborted) {- throw new Error("AbortError");- }-- if (framesChecked >= MAX_FRAMES_TO_CHECK) {- onProgress("reached search limit. try being more specific.");- return null;- }-- // Process frames in batches- const batchFrames = frames.slice(i, i + BATCH_SIZE);- const potentialMatches: number[] = [];-- // First pass: quick keyword matching on the batch- batchFrames.forEach((frame, batchIndex) => {- const globalIndex = i + batchIndex;-- const hasMatch = frame.devices.some((device) =>- searchParams.keywords.some((keyword) => {- const keywordLower = keyword.toLowerCase();- return (- device.metadata.app_name?.toLowerCase().includes(keywordLower) ||- device.metadata.window_name- ?.toLowerCase()- .includes(keywordLower) ||- device.metadata.ocr_text?.toLowerCase().includes(keywordLower) ||- device.audio.some((a) =>- a.transcription?.toLowerCase().includes(keywordLower),- )- );- }),- );-- if (hasMatch) {- potentialMatches.push(globalIndex);- }- });-- // If we found matches in this batch, validate them- if (potentialMatches.length > 0) {- onProgress(- `found ${potentialMatches.length} potential matches, analyzing context...`,- );-- // Validate the most promising matches first (you could add scoring here)- for (const matchIndex of potentialMatches) {- const validation = await validateFrameContext(- frames,- matchIndex,- searchParams,- openai,- model,- systemPrompt,- );-- if (validation.isRelevant && validation.confidence > 0.7) {- onProgress(- `found a highly relevant match! jumping to that moment...`,- );- return matchIndex;- }- }-- framesChecked += potentialMatches.length;- console.log("frames checked:", framesChecked);- }- }-- onProgress(- `couldn't find an exact match. try being more specific about the app or content you're looking for.`,- );- return null;- } catch (error: any) {- if (error.includes("AbortError")) {- console.log("search aborted");- } else {- console.error("search parameter parsing error:", error);- onProgress(- `oops! something went wrong with the search. please try again.`,- );- }- throw new Error(`failed to parse search parameters: ${error}`);- }-}--async function generateSuggestions(- openai: OpenAI,- model: string,- systemPrompt: string,- appStats: AppStats,-): Promise<string[]> {- console.log("generating suggestions with stats:", {- model,- appStats,- });-- try {- const response = await openai.chat.completions.create({- model,- messages: [- {- role: "system",- content: systemPrompt,- },- {- role: "user",- content: `generate 5 natural search suggestions based on the most common apps and activities in the user's data.- use this app statistics:- apps: ${JSON.stringify(appStats.apps)}- windows: ${JSON.stringify(appStats.windows)}-- output format: {- "suggestions": string[] // array of 5 natural language search queries- }-- make them specific and varied, focusing on different types of activities.- example output:- {- "suggestions": [- "when i was coding rust in vscode yesterday",- "that meeting about product roadmap in google meet",- "when i was watching youtube tutorials about typescript",- "my obsidian notes about system design",- "that time i was debugging in chrome devtools"- ]- }`,- },- ],- response_format: { type: "json_object" },- });-- console.log("suggestions response from AI:", response);-- if (!response.choices?.[0]?.message?.content) {- throw new Error("invalid or empty response from ai");- }-- const parsed = JSON.parse(response.choices[0].message.content);- return parsed.suggestions || [];- } catch (error) {- console.warn("failed to generate suggestions:", error);- return [- "when i was coding in vscode",- "that meeting in google meet",- "when i opened figma",- "that youtube video about rust",- "when i was writing in notion",- ];- }-}--const CACHE_KEY = "timeline_search_suggestions";-const CACHE_DURATION_MS = 24 * 60 * 60 * 1000; // 24 hours--interface CachedSuggestions {- suggestions: string[];- timestamp: number;- appsHash: string; // to invalidate if apps change significantly-}--function generateAppsHash(appStats: AppStats): string {- // create a hash of top 5 apps to detect major changes- const topApps = Object.entries(appStats.apps)- .sort(([, a], [, b]) => b - a)- .slice(0, 5)- .map(([app]) => app)- .join("|");- return topApps;-}--async function getCachedOrGenerateSuggestions(- openai: OpenAI,- model: string,- systemPrompt: string,- appStats: AppStats,-): Promise<string[]> {- try {- const cached = localStorage?.getItem(CACHE_KEY);- if (cached) {- const parsedCache: CachedSuggestions = JSON.parse(cached);- const isExpired = Date.now() - parsedCache.timestamp > CACHE_DURATION_MS;- const appsChanged = generateAppsHash(appStats) !== parsedCache.appsHash;-- if (!isExpired && !appsChanged) {- console.log("using cached suggestions");- return parsedCache.suggestions;- }- }-- const suggestions = await generateSuggestions(- openai,- model,- systemPrompt,- appStats,- );-- // cache the new suggestions- const cacheData: CachedSuggestions = {- suggestions,- timestamp: Date.now(),- appsHash: generateAppsHash(appStats),- };- try { localStorage?.setItem(CACHE_KEY, JSON.stringify(cacheData)); } catch {}-- return suggestions;- } catch (error) {- console.warn("failed to handle suggestions:", error);- return [- "when i was coding in vscode",- "that meeting in google meet",- "when i opened figma",- "that youtube video about rust",- "when i was writing in notion",- ];- }-}--export function TimelineSearch({- frames,- onResultSelect,-}: TimelineSearchProps) {- const [open, setOpen] = useState(false);- const [searchQuery, setSearchQuery] = useState("");- const [searchStatus, setSearchStatus] = useState("");- const [isSearching, setIsSearching] = useState(false);- const { settings } = useSettings();- const [suggestions, setSuggestions] = useState<string[] | null>(null);- const [isLoadingSuggestions, setIsLoadingSuggestions] = useState(false);- const hasLoadedSuggestions = useRef(false);- const [abortController, setAbortController] =- useState<AbortController | null>(null);-- // Compute app statistics once when component mounts or frames update- const appStats = useMemo(() => {- const stats: AppStats = {- apps: {},- windows: {},- maxItems: 10, // Keep top N most common- };-- frames.forEach((frame) => {- frame.devices.forEach((device) => {- if (device.metadata.app_name) {- stats.apps[device.metadata.app_name] =- (stats.apps[device.metadata.app_name] || 0) + 1;- }- if (device.metadata.window_name) {- stats.windows[device.metadata.window_name] =- (stats.windows[device.metadata.window_name] || 0) + 1;- }- });- });-- // Sort and keep only top N- const topApps = Object.entries(stats.apps)- .sort(([, a], [, b]) => b - a)- .slice(0, stats.maxItems)- .reduce((obj, [key, val]) => ({ ...obj, [key]: val }), {});-- const topWindows = Object.entries(stats.windows)- .sort(([, a], [, b]) => b - a)- .slice(0, stats.maxItems)- .reduce((obj, [key, val]) => ({ ...obj, [key]: val }), {});-- return {- ...stats,- apps: topApps,- windows: topWindows,- };- }, [frames]);-- // Generate system prompt with app statistics- const getSystemPrompt = useCallback(() => {- const appsList = Object.entries(appStats.apps)- .map(([app, count]) => `${app} (${count} occurrences)`)- .join(", ");-- const windowsList = Object.entries(appStats.windows)- .map(([window, count]) => `${window} (${count} occurrences)`)- .join(", ");-- return `you are a search assistant for screenpipe, a system that continuously records screens & mics.--your task is to analyze search queries and extract key information to find specific moments in the timeline.-be extremely strict about matches - all keywords must be present in the correct context.--common applications in user's data:-${appsList}--common window titles:-${windowsList}--the data you're searching through includes:-- screen content (OCR text)-- audio transcriptions-- application names-- window titles-- device metadata--each frame contains:-- timestamp-- multiple devices data-- metadata (ocr_text, app_name, window_name)-- audio transcriptions--search guidelines:-1. all keywords must be present in the same timeframe or adjacent frames-2. context must match exactly (e.g. if searching for "coding db.rs in cursor", must find frames where:- - app_name contains "cursor"- - window_name or ocr_text contains "db.rs"- - there's evidence of active coding)-3. temporal context matters (e.g. "last time" means most recent match)-4. activity context matters (e.g. "coding" requires code editor, relevant window titles)--examples of strict matching:-- query: "coding db.rs in cursor"- ✓ good match: {app_name: "Cursor", window_name: "db.rs - screenpipe", ocr_text: "fn main() {..."}- ✗ bad match: {app_name: "Cursor", window_name: "meeting notes", ocr_text: "discussing db.rs"}--- query: "watching rust video on youtube"- ✓ good match: {app_name: "Chrome", window_name: "Rust Tutorial - YouTube", transcription: "today we'll learn rust"}- ✗ bad match: {app_name: "Chrome", window_name: "YouTube", transcription: "discussing databases"}--focus on extracting:-- key activities (coding, watching, reading)-- specific applications (vscode, chrome, slack)-- content keywords (rust, meeting, video)-- contextual hints (time references, related activities)--output only valid json with the exact structure requested.-prioritize precision over recall - better to return no match than a wrong match.`;- }, [appStats]);-- const loadSuggestionsIfNeeded = useCallback(() => {- const defaultPreset = settings?.aiPresets?.find(p => p.defaultPreset) || settings?.aiPresets?.[0];- if (!defaultPreset?.model) {- setSuggestions([]);- return;- }- if (- !hasLoadedSuggestions.current &&- frames.length > 1_000 &&- !suggestions- ) {- hasLoadedSuggestions.current = true;- setIsLoadingSuggestions(true);-- const openai = new OpenAI({- apiKey: defaultPreset.apiKey || undefined,- baseURL: defaultPreset.url,- dangerouslyAllowBrowser: true,- });-- getCachedOrGenerateSuggestions(- openai,- defaultPreset.model,- getSystemPrompt(),- appStats,- )- .then(setSuggestions)- .catch((error) => {- console.warn("failed to load suggestions:", error);- setSuggestions([- "last meeting in google meet",- "last time i was working on linkedin",- "last youtube video i watched",- "last time i was writing in notion",- ]);- })- .finally(() => setIsLoadingSuggestions(false));- }- }, [frames.length, appStats, settings, suggestions]);-- // Only call when dialog opens- const handleOpen = useCallback(() => {- setOpen(true);- loadSuggestionsIfNeeded();- }, [loadSuggestionsIfNeeded]);-- const cancelSearch = useCallback(() => {- if (abortController) {- abortController.abort();- setIsSearching(false);- setSearchStatus("search cancelled");- }- }, [abortController]);-- const handleSearch = async (query: string) => {- const controller = new AbortController();- setAbortController(controller);-- setIsSearching(true);- setSearchStatus("");-- // Track search- posthog.capture("timeline_search", {- query_length: query.length,- frames_count: frames.length,- });-- const defaultPreset = settings?.aiPresets?.find(p => p.defaultPreset) || settings?.aiPresets?.[0];-- const openai = new OpenAI({- apiKey: defaultPreset?.apiKey || undefined,- baseURL: defaultPreset?.url,- dangerouslyAllowBrowser: true,- });-- try {- const systemPrompt = getSystemPrompt();-- const frameIndex = await findRelevantFrame(- query,- frames,- openai,- defaultPreset?.model || "mistral",- (status) => setSearchStatus(status),- systemPrompt,- 0,- undefined,- controller.signal,- );-- if (frameIndex !== null) {- posthog.capture("timeline_search_result_found", {- query_length: query.length,- });- onResultSelect(frameIndex);- setOpen(false);- } else {- posthog.capture("timeline_search_no_result", {- query_length: query.length,- });- setSearchStatus(- "couldn't find that moment. try being more specific about the app or content you're looking for.",- );- }- } catch (error: any) {- if (error.includes("AbortError")) {- console.log("search aborted");- } else {- console.warn("search error:", error);- setSearchStatus("search failed. please try again.");- }- } finally {- setIsSearching(false);- setAbortController(null);- }- };-- const regenerateSuggestions = useCallback(async () => {- setIsLoadingSuggestions(true);- const defaultPreset = settings?.aiPresets?.find(p => p.defaultPreset) || settings?.aiPresets?.[0];-- const openai = new OpenAI({- apiKey: defaultPreset?.apiKey || undefined,- baseURL: defaultPreset?.url,- dangerouslyAllowBrowser: true,- });-- try {- // Clear cache first- try { localStorage?.removeItem(CACHE_KEY); } catch {}-- const newSuggestions = await generateSuggestions(- openai,- defaultPreset?.model || "mistral",- getSystemPrompt(),- appStats,- );- setSuggestions(newSuggestions);-- // Update cache- const cacheData: CachedSuggestions = {- suggestions: newSuggestions,- timestamp: Date.now(),- appsHash: generateAppsHash(appStats),- };- try { localStorage?.setItem(CACHE_KEY, JSON.stringify(cacheData)); } catch {}- } catch (error) {- console.warn("failed to regenerate suggestions:", error);- } finally {- setIsLoadingSuggestions(false);- }- }, [settings, appStats, getSystemPrompt]);-- return (- <>- <Button- variant="ghost"- size="icon"- onClick={handleOpen}- className="rounded-full"- >- <Search className="h-4 w-4" />- </Button>-- <Dialog- open={open}- onOpenChange={(newOpen) => {- if (!isSearching) {- setOpen(newOpen);- }- }}- >- <DialogPortal>- <DialogOverlay- className="bg-background/50"- style={{- opacity: isSearching ? 0 : 0.8,- }}- />- <motion.div- animate={{- x: isSearching ? 200 : 0,- transition: { duration: 0.3, ease: "easeInOut" },- }}- >- <DialogContent className="sm:max-w-[500px]">- <DialogTitle>Search your timeline</DialogTitle>- <motion.div- initial={{ opacity: 0, y: -20 }}- animate={{ opacity: 1, y: 0 }}- exit={{ opacity: 0, y: -20 }}- className="p-6"- >- <div className="relative">- <Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />- <Input- autoFocus- placeholder="search in your timeline..."- className="pl-9 h-12"- value={searchQuery}- onChange={(e) => setSearchQuery(e.target.value)}- onKeyDown={(e) => {- if (e.key === "Enter" && !isSearching) {- handleSearch(searchQuery);- }- }}- disabled={isSearching}- />- {isSearching && (- <Button- variant="ghost"- size="icon"- onClick={cancelSearch}- className="absolute right-2 top-1/2 -translate-y-1/2"- >- <Square className="h-4 w-4" />- </Button>- )}- </div>-- {searchStatus && (- <motion.div- initial={{ opacity: 0, y: 5 }}- animate={{ opacity: 1, y: 0 }}- className="mt-3 flex items-center gap-2 text-sm"- >- {isSearching && (- <Loader2 className="h-3 w-3 animate-spin text-primary" />- )}- <span- className={- isSearching ? "text-primary" : "text-muted-foreground"- }- >- {searchStatus}- </span>- </motion.div>- )}-- <motion.div- initial={{ opacity: 0 }}- animate={{ opacity: 1 }}- transition={{ delay: 0.1 }}- className="mt-4"- >- {suggestions && (- <div className="flex items-center justify-between mb-3">- <p className="text-sm text-muted-foreground">- suggested searches- </p>- <Button- variant="ghost"- size="icon"- onClick={regenerateSuggestions}- disabled={isLoadingSuggestions}- className="h-6 w-6"- >- <RefreshCw className="h-4 w-4" />- </Button>- </div>- )}- <div className="space-y-2">- {isLoadingSuggestions ? (- // Skeleton loading state- <>- {[1, 2, 3, 4, 5].map((i) => (- <div- key={i}- className="h-10 bg-muted rounded-md animate-pulse"- />- ))}- </>- ) : suggestions ? (- suggestions.map((suggestion, i) => (- <motion.div- key={suggestion}- initial={{ opacity: 0, x: -20 }}- animate={{ opacity: 1, x: 0 }}- transition={{ delay: 0.1 + i * 0.05 }}- >- <TooltipProvider>- <Tooltip>- <TooltipTrigger asChild>- <Button- variant="ghost"- className="w-full justify-start text-left h-auto py-2 px-3 overflow-hidden"- onClick={() => handleSearch(suggestion)}- disabled={isSearching}- >- <div className="max-w-[400px] overflow-hidden text-ellipsis whitespace-nowrap">- {suggestion}- </div>- </Button>- </TooltipTrigger>- <TooltipContent side="top" align="start">- {suggestion}- </TooltipContent>- </Tooltip>- </TooltipProvider>- </motion.div>- ))- ) : null}- </div>- </motion.div>- </motion.div>- </DialogContent>- </motion.div>- </DialogPortal>- </Dialog>- </>- );-}diff --git a/apps/screenpipe-app-tauri/components/settings/account-section.tsx b/apps/screenpipe-app-tauri/components/settings/account-section.tsxindex 8e93fb27d..34b510d73 100644--- a/apps/screenpipe-app-tauri/components/settings/account-section.tsx+++ b/apps/screenpipe-app-tauri/components/settings/account-section.tsx@@ -8,18 +8,22 @@ import {Sparkles,Zap,Shield,+ Coins,} from "lucide-react";import { toast } from "@/components/ui/use-toast";import { open as openUrl } from "@tauri-apps/plugin-shell";import { Card } from "../ui/card";import { onOpenUrl } from "@tauri-apps/plugin-deep-link";import { PricingToggle } from "./pricing-toggle";+import { UpgradeDialog } from "@/components/upgrade-dialog";import posthog from "posthog-js";export function AccountSection() {const { settings, updateSettings, loadUser } = useSettings();const [isAnnual, setIsAnnual] = useState(true);+ const [showUpgrade, setShowUpgrade] = useState(false);+ const creditsBalance = settings.user?.credits_balance;useEffect(() => {if (!settings.user?.email) {@@ -190,6 +194,34 @@ export function AccountSection() {</div></div>+ {/* Credits card — show for any logged-in user */}+ {settings.user?.token && creditsBalance != null && (+ <Card className="p-5">+ <div className="flex items-center justify-between">+ <div className="flex items-center gap-3">+ <Coins className="h-5 w-5" />+ <div>+ <div className="flex items-baseline gap-2">+ <span className="text-2xl font-bold font-mono">{creditsBalance}</span>+ <span className="text-sm text-muted-foreground">credits</span>+ </div>+ <p className="text-xs text-muted-foreground mt-0.5">+ each credit = 1 AI query after your free daily limit+ </p>+ </div>+ </div>+ <Button+ variant="outline"+ size="sm"+ onClick={() => setShowUpgrade(true)}+ >+ <Coins className="w-3.5 h-3.5 mr-1.5" />+ buy credits+ </Button>+ </div>+ </Card>+ )}+{/* Subscribed view */}{settings.user?.cloud_subscribed ? (<Card className="p-5">@@ -379,6 +411,12 @@ export function AccountSection() {`}</style></>)}++ <UpgradeDialog+ open={showUpgrade}+ onOpenChange={setShowUpgrade}+ reason="daily_limit"+ /></div>);}diff --git a/apps/screenpipe-app-tauri/components/settings/pipes-section.tsx b/apps/screenpipe-app-tauri/components/settings/pipes-section.tsxindex 7acf350d4..498524d5f 100644--- a/apps/screenpipe-app-tauri/components/settings/pipes-section.tsx+++ b/apps/screenpipe-app-tauri/components/settings/pipes-section.tsx@@ -259,7 +259,7 @@ export function PipesSection() {variant="outline"size="sm"className="h-6 text-[11px] px-2"- onClick={() => openUrl("https://screenpi.pe/onboarding?tab=pricing")}+ onClick={() => setShowUpgrade(true)}>get more queries →</Button>diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx b/apps/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsxindex aed66fe11..c9403d375 100644--- a/apps/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx+++ b/apps/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx@@ -590,23 +590,39 @@ export const useTimelineStore = create<TimelineState>((set, get) => ({},onWindowFocus: () => {- const { currentDate, websocket, fetchTimeRange, connectWebSocket } = get();+ const { websocket, fetchTimeRange, connectWebSocket } = get();++ // Always reset to today when the window is focused.+ // The window is hidden/shown (not destroyed), so stale dates persist.+ const today = new Date();++ // Clear sentRequests for today so we re-fetch fresh data+ const todayKey = `${today.getDate()}-${today.getMonth()}-${today.getFullYear()}`;++ // Also clear the old date's sentRequests in case it was different+ const { currentDate: oldDate } = get();+ const oldDateKey = `${oldDate.getDate()}-${oldDate.getMonth()}-${oldDate.getFullYear()}`;- // Clear current date from sentRequests to allow re-fetch- const dateKey = `${currentDate.getDate()}-${currentDate.getMonth()}-${currentDate.getFullYear()}`;set((state) => {const newSentRequests = new Set(state.sentRequests);- newSentRequests.delete(dateKey);- return { sentRequests: newSentRequests };+ newSentRequests.delete(todayKey);+ newSentRequests.delete(oldDateKey);+ return {+ sentRequests: newSentRequests,+ currentDate: today,+ // Signal that position should reset to latest (index 0)+ // by clearing pendingNavigation and setting a flag+ pendingNavigation: null,+ };});- console.log("Window focused, cleared sentRequests for:", dateKey);+ console.log("Window focused, cleared sentRequests for:", todayKey);- // If WebSocket is open, fetch fresh data+ // If WebSocket is open, fetch today's dataif (websocket && websocket.readyState === WebSocket.OPEN) {- const startTime = new Date(currentDate);+ const startTime = new Date(today);startTime.setHours(0, 0, 0, 0);- const endTime = new Date(currentDate);+ const endTime = new Date(today);endTime.setHours(23, 59, 59, 999);fetchTimeRange(startTime, endTime);} else {diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lockindex 57723e596..3ffb43ec3 100755--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock@@ -8719,7 +8719,7 @@ dependencies = [[[package]]name = "screenpipe-app"-version = "2.0.435"+version = "2.0.436"dependencies = ["anyhow","async-stream",