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: use frame_id for exact navigation from search results
Louis Beaumonta98fa29912b7
diff --git a/apps/screenpipe-app-tauri/app/search/page.tsx b/apps/screenpipe-app-tauri/app/search/page.tsxindex 9d91da965..b355c473c 100644--- a/apps/screenpipe-app-tauri/app/search/page.tsx+++ b/apps/screenpipe-app-tauri/app/search/page.tsx@@ -10,9 +10,9 @@ import { invoke } from "@tauri-apps/api/core";import { commands } from "@/lib/utils/tauri";export default function SearchPage() {- const handleNavigate = useCallback(async (timestamp: string) => {+ const handleNavigate = useCallback(async (timestamp: string, frameId?: number) => {// Rust command: shows Main, emits navigation event from app handle, closes Search- invoke("search_navigate_to_timeline", { timestamp }).catch(console.error);+ invoke("search_navigate_to_timeline", { timestamp, frameId }).catch(console.error);}, []);const handleClose = useCallback(async () => {diff --git a/apps/screenpipe-app-tauri/components/rewind/hooks/use-date-navigation.ts b/apps/screenpipe-app-tauri/components/rewind/hooks/use-date-navigation.tsindex 0d5c26726..540a08eb2 100644--- a/apps/screenpipe-app-tauri/components/rewind/hooks/use-date-navigation.ts+++ b/apps/screenpipe-app-tauri/components/rewind/hooks/use-date-navigation.ts@@ -66,6 +66,9 @@ export function useDateNavigation(opts: {// Seeking state for UX feedback when navigating from searchconst [seekingTimestamp, setSeekingTimestamp] = useState<string | null>(null);+ // Frame ID to match when pending navigation resolves (exact match > timestamp)+ const pendingFrameIdRef = useRef<number | undefined>(undefined);+// Navigation in progress — disables day arrows to prevent double-clicksconst [isNavigating, setIsNavigating] = useState(false);@@ -75,13 +78,30 @@ export function useDateNavigation(opts: {// Ref to hold navigateToSearchResult so arrow-key effect doesn't depend on it directlyconst navigateToSearchResultRef = useRef<(index: number) => void>(() => {});- const jumpToTime = useCallback((targetDate: Date) => {+ const jumpToTime = useCallback((targetDate: Date, frameId?: number) => {// Find the closest frame to the target dateif (frames.length === 0) {console.warn("[jumpToTime] No frames loaded, cannot jump");return;}+ // If we have a frame_id, try exact match first — this avoids+ // off-by-one errors when multiple frames share similar timestamps+ if (frameId != null) {+ const exactIdx = frames.findIndex((f) =>+ f.devices.some((d) => String(d.frame_id) === String(frameId))+ );+ if (exactIdx >= 0) {+ const snapped = snapToDevice(exactIdx);+ setCurrentIndex(snapped);+ if (frames[snapped]) {+ setCurrentFrame(frames[snapped]);+ }+ return;+ }+ }++ // Fallback: find closest by timestampconst targetTime = targetDate.getTime();let closestIndex = -1;let closestDiff = Infinity;@@ -110,7 +130,8 @@ export function useDateNavigation(opts: {// Fast navigation to a date we already know has frames (e.g. from search results).// Skips the hasFramesForDate() HTTP round-trip and adjacent-date probing.- const navigateDirectToDate = useCallback((targetDate: Date) => {+ const navigateDirectToDate = useCallback((targetDate: Date, frameId?: number) => {+ pendingFrameIdRef.current = frameId;isNavigatingRef.current = true;setIsNavigating(true);@@ -165,16 +186,18 @@ export function useDateNavigation(opts: {setSeekingTimestamp(result.timestamp);if (!isSameDay(targetDate, currentDate)) {- navigateDirectToDate(targetDate);+ navigateDirectToDate(targetDate, result.frame_id);} else {pendingNavigationRef.current = targetDate;+ pendingFrameIdRef.current = result.frame_id;const hasTargetDayFrames = frames.some((f) =>isSameDay(new Date(f.timestamp), targetDate));if (hasTargetDayFrames) {setSearchNavFrame(true);- jumpToTime(targetDate);+ jumpToTime(targetDate, result.frame_id);pendingNavigationRef.current = null;+ pendingFrameIdRef.current = undefined;setSeekingTimestamp(null);}}@@ -325,23 +348,33 @@ export function useDateNavigation(opts: {isSameDay(new Date(frame.timestamp), targetDate));if (isSameDay(targetDate, currentDate) && hasFramesForTargetDate) {+ const pendingFrameId = pendingFrameIdRef.current;++ // Try exact frame_id match first (avoids off-by-one from timestamp rounding)+ let closestIndex = -1;+ if (pendingFrameId != null) {+ closestIndex = frames.findIndex((f) =>+ isSameDay(new Date(f.timestamp), targetDate) &&+ f.devices.some((d) => String(d.frame_id) === String(pendingFrameId))+ );+ }- // Find the closest frame to the target timestamp — only consider- // frames from the target date (old-date frames may still be in- // the array during pendingDateSwap transitions)- const targetTime = targetDate.getTime();- let closestIndex = 0;- let closestDiff = Infinity;-- frames.forEach((frame, index) => {- if (!isSameDay(new Date(frame.timestamp), targetDate)) return;- const frameTime = new Date(frame.timestamp).getTime();- const diff = Math.abs(frameTime - targetTime);- if (diff < closestDiff) {- closestDiff = diff;- closestIndex = index;- }- });+ // Fallback: find the closest frame by timestamp+ if (closestIndex < 0) {+ const targetTime = targetDate.getTime();+ let closestDiff = Infinity;+ closestIndex = 0;++ frames.forEach((frame, index) => {+ if (!isSameDay(new Date(frame.timestamp), targetDate)) return;+ const frameTime = new Date(frame.timestamp).getTime();+ const diff = Math.abs(frameTime - targetTime);+ if (diff < closestDiff) {+ closestDiff = diff;+ closestIndex = index;+ }+ });+ }resetFilters();const snapped = snapToDevice(closestIndex);@@ -352,6 +385,7 @@ export function useDateNavigation(opts: {// Clear pending navigation and UI statependingNavigationRef.current = null;+ pendingFrameIdRef.current = undefined;setSeekingTimestamp(null);setPendingNavigation(null);setIsNavigating(false);diff --git a/apps/screenpipe-app-tauri/components/rewind/search-modal.tsx b/apps/screenpipe-app-tauri/components/rewind/search-modal.tsxindex 4c5b06759..60c8a9055 100644--- a/apps/screenpipe-app-tauri/components/rewind/search-modal.tsx+++ b/apps/screenpipe-app-tauri/components/rewind/search-modal.tsx@@ -40,7 +40,7 @@ interface TaggedFrame {interface SearchModalProps {isOpen: boolean;onClose: () => void;- onNavigateToTimestamp: (timestamp: string) => void;+ onNavigateToTimestamp: (timestamp: string, frameId?: number) => void;embedded?: boolean;/** When true, this is rendered in its own Tauri window (no backdrop, always open) */standalone?: boolean;@@ -1045,7 +1045,7 @@ export function SearchModal({ isOpen, onClose, onNavigateToTimestamp, embedded =// Track which result was selected so timeline arrow keys can cycle from hereconst idx = searchResults.findIndex((r) => r.frame_id === result.frame_id);if (idx >= 0) setCurrentResultIndex(idx);- onNavigateToTimestamp(result.timestamp);+ onNavigateToTimestamp(result.timestamp, result.frame_id);onClose();}, [onNavigateToTimestamp, onClose, queryTokens, setHighlight, searchResults, setCurrentResultIndex]);@@ -1378,7 +1378,7 @@ export function SearchModal({ isOpen, onClose, onNavigateToTimestamp, embedded =<divkey={frame.frame_id}onClick={() => {- onNavigateToTimestamp(frame.timestamp);+ onNavigateToTimestamp(frame.timestamp, frame.frame_id);if (!embedded) onClose();}}className="cursor-pointer rounded overflow-hidden border border-border hover:border-foreground/50 transition-all duration-150"diff --git a/apps/screenpipe-app-tauri/components/rewind/timeline.tsx b/apps/screenpipe-app-tauri/components/rewind/timeline.tsxindex a8a38db01..ec3f67379 100644--- a/apps/screenpipe-app-tauri/components/rewind/timeline.tsx+++ b/apps/screenpipe-app-tauri/components/rewind/timeline.tsx@@ -910,8 +910,9 @@ export default function Timeline({ embedded = false }: { embedded?: boolean }) {// a fresh fetch and uses pendingNavigationRef to jump once frames arrive.useEffect(() => {let lastHandledTs = "";- const unlisten = listen<{ timestamp: string }>("search-navigate-to-timestamp", (event) => {+ const unlisten = listen<{ timestamp: string; frame_id?: number }>("search-navigate-to-timestamp", (event) => {const timestamp = event.payload.timestamp;+ const frameId = event.payload.frame_id;// Deduplicate — Rust emits multiple times to survive mount raceif (timestamp === lastHandledTs) return;lastHandledTs = timestamp;@@ -919,7 +920,7 @@ export default function Timeline({ embedded = false }: { embedded?: boolean }) {lastSearchNavRef.current = Date.now();setSeekingTimestamp(timestamp);setSearchNavFrame(true);- navigateDirectToDate(targetDate);+ navigateDirectToDate(targetDate, frameId);});return () => { unlisten.then(fn => fn()); };}, [navigateDirectToDate]);@@ -1420,12 +1421,12 @@ export default function Timeline({ embedded = false }: { embedded?: boolean }) {isOpen={true}embeddedonClose={() => setShowSearchModal(false)}- onNavigateToTimestamp={(timestamp) => {+ onNavigateToTimestamp={(timestamp, frameId) => {setShowSearchModal(false);const targetDate = new Date(timestamp);setSeekingTimestamp(timestamp);if (!isSameDay(targetDate, currentDate)) {- navigateDirectToDate(targetDate);+ navigateDirectToDate(targetDate, frameId);} else {pendingNavigationRef.current = targetDate;const hasTargetDayFrames = frames.some(f =>@@ -1433,7 +1434,7 @@ export default function Timeline({ embedded = false }: { embedded?: boolean }) {);if (hasTargetDayFrames) {setSearchNavFrame(true);- jumpToTime(targetDate);+ jumpToTime(targetDate, frameId);pendingNavigationRef.current = null;setSeekingTimestamp(null);}diff --git a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs b/apps/screenpipe-app-tauri/src-tauri/src/commands.rsindex e8a320c81..b5a3b69e5 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs@@ -542,6 +542,7 @@ pub async fn ensure_webview_focus(app_handle: tauri::AppHandle) -> Result<(), Stpub async fn search_navigate_to_timeline(app_handle: tauri::AppHandle,timestamp: String,+ frame_id: Option<i64>,) -> Result<(), String> {// Show the Main timelineShowRewindWindow::Main.show(&app_handle).map_err(|e| e.to_string())?;@@ -553,7 +554,7 @@ pub async fn search_navigate_to_timeline(tokio::spawn(async move {for i in 0..5 {tokio::time::sleep(tokio::time::Duration::from_millis(if i == 0 { 200 } else { 200 })).await;- let _ = app.emit("search-navigate-to-timestamp", serde_json::json!({ "timestamp": timestamp }));+ let _ = app.emit("search-navigate-to-timestamp", serde_json::json!({ "timestamp": timestamp, "frame_id": frame_id }));}tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;let _ = ShowRewindWindow::Search { query: None }.close(&app);