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: rewind pipe issues (#1483)

shaik-zeeshan3e8753b38b9f
diff --git a/pipes/rewind/src/app/page.tsx b/pipes/rewind/src/app/page.tsx
index feb6fa1f6..f355091c1 100644
--- a/pipes/rewind/src/app/page.tsx
+++ b/pipes/rewind/src/app/page.tsx
@@ -15,6 +15,7 @@ import { TimelineSlider } from "@/components/timeline/timeline";
import { useTimelineStore } from "@/lib/hooks/use-timeline-store";
import { hasFramesForDate } from "@/lib/actions/has-frames-date";
import { CommandShortcut } from "@/components/ui/command";
+import { CurrentFrameTimeline } from "@/components/current-frame-timeline";
export interface StreamTimeSeriesResponse {
timestamp: string;
@@ -151,7 +152,7 @@ export default function Timeline() {
const direction = -Math.sign(e.deltaY);
// Change this if you want limit the index change
- const limitIndexChange = 15;
+ const limitIndexChange = Infinity;
// Adjust index change based on scroll intensity
const indexChange =
@@ -397,13 +398,7 @@ export default function Timeline() {
</div>
</div>
)}
- {currentFrame && (
- <img
- src={`http://localhost:3030/frames/${currentFrame.devices[0].frame_id}`}
- className="absolute inset-0 w-4/5 h-auto max-h-[75vh] object-contain mx-auto border rounded-xl p-2 mt-20"
- alt="Current frame"
- />
- )}
+ {currentFrame && <CurrentFrameTimeline currentFrame={currentFrame} />}
{currentFrame && (
<AudioTranscript
frames={frames}
diff --git a/pipes/rewind/src/app/search/page.tsx b/pipes/rewind/src/app/search/page.tsx
index d942d3a7b..ff1fd5729 100644
--- a/pipes/rewind/src/app/search/page.tsx
+++ b/pipes/rewind/src/app/search/page.tsx
@@ -9,7 +9,7 @@ import { useKeywordSearchStore } from "@/lib/hooks/use-keyword-search-store";
import { endOfDay, startOfDay } from "date-fns";
import { useCallback, useEffect, useRef } from "react";
import { parser } from "@/lib/keyword-parser";
-import { CurrentFrame } from "@/components/current-frame";
+import { CurrentFrame } from "@/components/current-frame-search";
import { useKeywordParams } from "@/lib/hooks/use-keyword-params";
import { AppSelect } from "@/components/search-command";
import { ArrowLeft } from "lucide-react";
@@ -130,11 +130,16 @@ export default function Page() {
</div>
) : null}
- {isSearching &&
- searchResults.length === 0 &&
- Array.from({ length: 6 }).map((_, index) => (
- <SkeletonCard key={`skeleton-${index}`} />
- ))}
+ {isSearching && searchResults.length === 0 && (
+ <div
+ className="flex flex-row gap-4 p-8 overflow-hidden"
+ style={{ direction: "rtl" }}
+ >
+ {Array.from({ length: 8 }).map((_, index) => (
+ <SkeletonCard key={`skeleton-${index}`} />
+ ))}
+ </div>
+ )}
{querys.query && !(searchResults.length === 0) ? (
<div className="h-64 flex items-end">
diff --git a/pipes/rewind/src/components/current-frame.tsx b/pipes/rewind/src/components/current-frame-search.tsx
similarity index 100%
rename from pipes/rewind/src/components/current-frame.tsx
rename to pipes/rewind/src/components/current-frame-search.tsx
diff --git a/pipes/rewind/src/components/current-frame-timeline.tsx b/pipes/rewind/src/components/current-frame-timeline.tsx
new file mode 100644
index 000000000..11e263207
--- /dev/null
+++ b/pipes/rewind/src/components/current-frame-timeline.tsx
@@ -0,0 +1,48 @@
+import { StreamTimeSeriesResponse } from "@/app/page";
+import { FC, useState } from "react";
+
+interface CurrentFrameTimelineProps {
+ currentFrame: StreamTimeSeriesResponse;
+}
+
+export const SkeletonLoader: FC = () => {
+ return (
+ <div className="absolute inset-0 w-4/5 h-[75vh] mx-auto mt-20 border rounded-xl p-2 bg-gray-100 overflow-hidden">
+ <div
+ className="w-full h-full bg-gradient-to-r from-gray-100 via-gray-200 to-gray-100 animate-shimmer"
+ style={{
+ backgroundSize: "200% 100%",
+ animation: "shimmer 1.5s infinite linear",
+ }}
+ />
+ </div>
+ );
+};
+
+export const CurrentFrameTimeline: FC<CurrentFrameTimelineProps> = ({
+ currentFrame,
+}) => {
+ const [isLoading, setIsLoading] = useState(true);
+ const [hasError, setHasError] = useState(false);
+
+ return (
+ <>
+ {(isLoading || hasError) && <SkeletonLoader />}
+ <img
+ src={`http://localhost:3030/frames/${currentFrame.devices[0].frame_id}`}
+ className={`absolute inset-0 w-4/5 h-auto max-h-[75vh] object-contain mx-auto border rounded-xl p-2 mt-20 transition-opacity duration-300 ${
+ isLoading || hasError ? "opacity-0" : "opacity-100"
+ }`}
+ alt="Current frame"
+ onLoad={() => {
+ setIsLoading(false);
+ setHasError(false);
+ }}
+ onError={() => {
+ setIsLoading(false);
+ setHasError(true);
+ }}
+ />
+ </>
+ );
+};
diff --git a/pipes/rewind/src/components/image-card.tsx b/pipes/rewind/src/components/image-card.tsx
index 1c6580a4b..8bf7d1043 100644
--- a/pipes/rewind/src/components/image-card.tsx
+++ b/pipes/rewind/src/components/image-card.tsx
@@ -10,7 +10,7 @@ import { useKeywordParams } from "@/lib/hooks/use-keyword-params";
export const SkeletonCard = () => (
<div className="flex flex-col shrink-0 w-56 h-full relative overflow-hidden rounded-lg bg-white shadow-sm">
<div className="aspect-video bg-neutral-200 animate-pulse" />
- <div className="p-3 space-y-2">
+ <div className="p-3 space-y-2" style={{ direction: "ltr" }}>
<div className="h-4 bg-neutral-200 rounded animate-pulse" />
<div className="h-3 bg-neutral-200 rounded animate-pulse w-3/4" />
<div className="h-3 bg-neutral-200 rounded animate-pulse w-1/2" />
diff --git a/pipes/rewind/src/components/timeline/ai-panel.tsx b/pipes/rewind/src/components/timeline/ai-panel.tsx
index 1ee2bf1a6..b7946ac41 100644
--- a/pipes/rewind/src/components/timeline/ai-panel.tsx
+++ b/pipes/rewind/src/components/timeline/ai-panel.tsx
@@ -219,15 +219,52 @@ export function AIPanel({
setIsStreaming(true);
try {
- const relevantFrames = frames.filter((frame) => {
+ const relevantFrames = frames.reduce((acc, frame) => {
const frameTime = new Date(frame.timestamp).getTime();
const startTime = new Date(selectionRange.start).getTime();
const endTime = new Date(selectionRange.end).getTime();
-
const isInRange = frameTime >= startTime && frameTime <= endTime;
- return isInRange;
- });
+ if (!isInRange) return acc;
+
+ // Get minute timestamp (rounded down to nearest minute)
+ const minuteTimestamp = Math.floor(frameTime / 60000) * 60000;
+
+ // Get unique apps in this frame
+ const frameApps = new Set(
+ frame.devices.map((device) => device.metadata.app_name),
+ );
+
+ // Check if we already have this app in this minute
+ const existingFrameForMinute = acc.find((existing) => {
+ const existingTime = new Date(existing.timestamp).getTime();
+ const existingMinute = Math.floor(existingTime / 60000) * 60000;
+
+ if (existingMinute !== minuteTimestamp) return false;
+
+ // Check if apps are the same
+ const existingApps = new Set(
+ existing.devices.map((device) => device.metadata.app_name),
+ );
+ return (
+ Array.from(frameApps).every((app) => existingApps.has(app)) &&
+ Array.from(existingApps).every((app) => frameApps.has(app))
+ );
+ });
+
+ // If we have multiple apps or haven't seen this app/minute combo, add the frame
+ if (frameApps.size > 1 || !existingFrameForMinute) {
+ acc.push(frame);
+ }
+
+ return acc;
+ }, [] as StreamTimeSeriesResponse[]);
+
+ // Sort frames by timestamp
+ relevantFrames.sort(
+ (a, b) =>
+ new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime(),
+ );
const openai = new OpenAI({
apiKey:
diff --git a/pipes/rewind/src/components/timeline/timeline.tsx b/pipes/rewind/src/components/timeline/timeline.tsx
index f89eec32f..3af1bf2e9 100644
--- a/pipes/rewind/src/components/timeline/timeline.tsx
+++ b/pipes/rewind/src/components/timeline/timeline.tsx
@@ -45,6 +45,8 @@ export const TimelineSlider = ({
onSelectionChange,
}: TimelineSliderProps) => {
const containerRef = useRef<HTMLDivElement>(null);
+ const observerTargetRef = useRef<HTMLDivElement>(null);
+ const lastFetchRef = useRef<Date | null>(null);
const { scrollXProgress } = useScroll({
container: containerRef,
offset: ["start end", "end start"],
@@ -58,12 +60,18 @@ export const TimelineSlider = ({
);
const { setSelectionRange, selectionRange } = useTimelineSelection();
+ const visibleFrames = useMemo(() => {
+ const start = Math.max(0, currentIndex - 100);
+ const end = Math.min(frames.length, currentIndex + 100);
+ return frames.slice(start, end);
+ }, [frames, currentIndex]);
+
const appGroups = useMemo(() => {
const groups: AppGroup[] = [];
let currentApp = "";
let currentGroup: StreamTimeSeriesResponse[] = [];
- frames.forEach((frame) => {
+ visibleFrames.forEach((frame) => {
const appName = frame.devices[0].metadata.app_name;
if (appName !== currentApp) {
if (currentGroup.length > 0) {
@@ -88,9 +96,39 @@ export const TimelineSlider = ({
});
}
return groups;
- }, [frames]);
+ }, [visibleFrames]);
+
+ useEffect(() => {
+ const observerTarget = observerTargetRef.current;
+ if (!observerTarget) return;
+
+ const observer = new IntersectionObserver(
+ (entries) => {
+ const entry = entries[0];
+ if (!entry.isIntersecting) return;
+
+ const lastDate = subDays(currentDate, 1);
+ const now = new Date();
+ const canFetch =
+ !lastFetchRef.current ||
+ now.getTime() - lastFetchRef.current.getTime() > 1000;
+
+ if (isAfter(lastDate, startAndEndDates.start) && canFetch) {
+ lastFetchRef.current = now;
+ fetchNextDayData(lastDate);
+ }
+ },
+ {
+ root: containerRef.current,
+ threshold: 1.0,
+ rootMargin: "0px 20% 0px 0px",
+ },
+ );
+
+ observer.observe(observerTarget);
+ return () => observer.disconnect();
+ }, [fetchNextDayData, currentDate, startAndEndDates]);
- // Add effect to keep current frame in view
useEffect(() => {
const container = containerRef.current;
if (!container || !frames[currentIndex]) return;
@@ -109,47 +147,21 @@ export const TimelineSlider = ({
});
}, [currentIndex, frames.length]);
- useEffect(() => {
- const container = containerRef.current;
- if (!container) return;
-
- const handleScroll = () => {
- const { scrollLeft, scrollWidth, clientWidth } = container;
-
- // Check if we're 20% away from the left end (considering RTL)
- const threshold = scrollWidth * 0.2; // 20% of total scroll width
- const isNearLeftEnd =
- Math.abs(scrollLeft) + clientWidth >= scrollWidth - threshold;
-
- const lastDate = subDays(currentDate, 1);
- if (isNearLeftEnd && isAfter(lastDate, startAndEndDates.start)) {
- console.log("fetching next day's data", currentDate);
- fetchNextDayData(lastDate);
- }
- };
-
- container.addEventListener("scroll", handleScroll);
- return () => container.removeEventListener("scroll", handleScroll);
- }, [fetchNextDayData, currentDate, startAndEndDates]);
-
useEffect(() => {
if (!selectionRange) {
setSelectedIndices(new Set());
}
}, [selectionRange]);
- // Handle drag start
const handleDragStart = (index: number) => {
setIsDragging(true);
setDragStartIndex(index);
setSelectedIndices(new Set([index]));
- // Set initial selection range
const startDate = new Date(frames[index].timestamp);
setSelectionRange({ start: startDate, end: startDate });
};
- // Handle drag over
const handleDragOver = (index: number) => {
if (isDragging && dragStartIndex !== null) {
const start = Math.min(dragStartIndex, index);
@@ -162,13 +174,11 @@ export const TimelineSlider = ({
setSelectedIndices(newSelection);
- // Update selection range
setSelectionRange({
end: new Date(frames[start].timestamp),
start: new Date(frames[end].timestamp),
});
- // Notify parent of selection change
if (onSelectionChange) {
const selectedFrames = Array.from(newSelection).map((i) => frames[i]);
onSelectionChange(selectedFrames);
@@ -176,7 +186,6 @@ export const TimelineSlider = ({
}
};
- // Handle drag end
const handleDragEnd = () => {
setIsDragging(false);
setDragStartIndex(null);
@@ -239,15 +248,15 @@ export const TimelineSlider = ({
backgroundColor: group.color,
height:
frameIndex === currentIndex || isSelected || isInRange
- ? "100%"
- : "70%",
+ ? "60%"
+ : "40%",
opacity:
frameIndex === currentIndex || isSelected || isInRange
? 1
: 0.7,
direction: "ltr",
}}
- whileHover={{ height: "100%", opacity: 1 }}
+ whileHover={{ height: "60%", opacity: 1 }}
onMouseDown={() => handleDragStart(frameIndex)}
onMouseEnter={() => {
setHoveredTimestamp(frame.timestamp);
@@ -260,8 +269,9 @@ export const TimelineSlider = ({
<AudioLinesIcon className="w-full h-full" />
</div>
)}
- {hoveredTimestamp === frame.timestamp && (
- <div className="absolute bottom-full left-1/2 -translate-x-1/2 mb-6 w-max bg-background border rounded-md px-2 py-1 text-xs shadow-lg">
+ {(hoveredTimestamp === frame.timestamp ||
+ frames[currentIndex].timestamp === frame.timestamp) && (
+ <div className="absolute bottom-full left-1/2 z-50 -translate-x-1/2 mb-6 w-max bg-background border rounded-md px-2 py-1 text-xs shadow-lg">
<p className="font-medium">
{frame.devices[0].metadata.app_name}
</p>
@@ -275,6 +285,7 @@ export const TimelineSlider = ({
})}
</div>
))}
+ <div ref={observerTargetRef} className="h-full w-1" />
</motion.div>
</div>
</div>
diff --git a/pipes/rewind/src/lib/hooks/use-current-frame.tsx b/pipes/rewind/src/lib/hooks/use-current-frame.tsx
index 2d9b65391..7baeb95ff 100644
--- a/pipes/rewind/src/lib/hooks/use-current-frame.tsx
+++ b/pipes/rewind/src/lib/hooks/use-current-frame.tsx
@@ -10,7 +10,6 @@ export const useCurrentFrame = (setCurrentIndex: (index: number) => void) => {
const lastFramesLen = useRef<number>(0);
useEffect(() => {
- console.log("current length", lastFramesLen);
if (!currentFrame && frames.length) {
setCurrentFrame(frames[lastFramesLen.current]);
setCurrentIndex(lastFramesLen.current);
diff --git a/pipes/rewind/tailwind.config.ts b/pipes/rewind/tailwind.config.ts
index 5ec9e4e2d..a952e215e 100644
--- a/pipes/rewind/tailwind.config.ts
+++ b/pipes/rewind/tailwind.config.ts
@@ -85,10 +85,15 @@ export default {
height: "0",
},
},
+ shimmer: {
+ "0%": { backgroundPosition: "200% 0" },
+ "100%": { backgroundPosition: "-200% 0" },
+ },
},
animation: {
"accordion-down": "accordion-down 0.2s ease-out",
"accordion-up": "accordion-up 0.2s ease-out",
+ shimmer: "shimmer 1.5s infinite linear",
},
},
},
diff --git a/screenpipe-server/src/db.rs b/screenpipe-server/src/db.rs
index 9cb3d02e2..c698b3d2f 100644
--- a/screenpipe-server/src/db.rs
+++ b/screenpipe-server/src/db.rs
@@ -1,6 +1,7 @@
use chrono::{DateTime, Utc};
use image::DynamicImage;
use libsqlite3_sys::sqlite3_auto_extension;
+use nix::NixPath;
use screenpipe_audio::{AudioDevice, DeviceType};
use screenpipe_vision::OcrEngine;
use sqlite_vec::sqlite3_vec_init;
@@ -122,9 +123,12 @@ impl DatabaseManager {
Ok(id)
}
- pub async fn count_audio_transcriptions(&self, audio_chunk_id: i64) -> Result<i64, sqlx::Error> {
+ pub async fn count_audio_transcriptions(
+ &self,
+ audio_chunk_id: i64,
+ ) -> Result<i64, sqlx::Error> {
let count = sqlx::query_scalar::<_, i64>(
- "SELECT COUNT(*) FROM audio_transcriptions WHERE audio_chunk_id = ?1"
+ "SELECT COUNT(*) FROM audio_transcriptions WHERE audio_chunk_id = ?1",
)
.bind(audio_chunk_id)
.fetch_one(&self.pool)
@@ -1089,10 +1093,10 @@ impl DatabaseManager {
AND (?5 IS NULL OR COALESCE(ocr_text.text_length, LENGTH(ocr_text.text)) <= ?5)
AND (?6 IS NULL OR frames.name LIKE '%' || ?6 || '%')"#,
base_table = if ocr_query.is_empty() {
- "frames
+ "frames
JOIN ocr_text ON frames.id = ocr_text.frame_id"
} else {
- "ocr_text_fts
+ "ocr_text_fts
JOIN ocr_text ON ocr_text_fts.frame_id = ocr_text.frame_id
JOIN frames ON ocr_text.frame_id = frames.id"
},
@@ -1456,30 +1460,20 @@ impl DatabaseManager {
) -> Result<TimeSeriesChunk, SqlxError> {
// Get frames with OCR data, grouped by minute to handle multiple monitors
let frames_query = r#"
- WITH MinuteGroups AS (
- SELECT
- f.id,
- f.timestamp,
- f.offset_index,
- ot.text,
- f.app_name,
- f.window_name,
- vc.device_name as screen_device,
- vc.file_path as video_path,
- strftime('%Y-%m-%d %H:%M', f.timestamp) as minute_group,
- ROW_NUMBER() OVER (
- PARTITION BY strftime('%Y-%m-%d %H:%M', f.timestamp), f.app_name, vc.device_name
- ORDER BY f.timestamp DESC
- ) as rn
- FROM frames f
- JOIN video_chunks vc ON f.video_chunk_id = vc.id
- LEFT JOIN ocr_text ot ON f.id = ot.frame_id
- WHERE f.timestamp >= ?1 AND f.timestamp <= ?2
- )
- SELECT *
- FROM MinuteGroups
- WHERE rn = 1
- ORDER BY timestamp DESC, offset_index DESC
+ SELECT
+ f.id,
+ f.timestamp,
+ f.offset_index,
+ ot.text,
+ COALESCE(f.app_name, ot.app_name) as app_name,
+ COALESCE(f.window_name, ot.window_name) as window_name,
+ vc.device_name as screen_device,
+ vc.file_path as video_path
+ FROM frames f
+ JOIN video_chunks vc ON f.video_chunk_id = vc.id
+ LEFT JOIN ocr_text ot ON f.id = ot.frame_id
+ WHERE f.timestamp >= ?1 AND f.timestamp <= ?2
+ ORDER BY f.timestamp DESC, f.offset_index DESC
"#;
// Get audio data with proper time windows for synchronization
@@ -2271,8 +2265,8 @@ SELECT
f.id,
f.timestamp,
f.browser_url as url,
- f.app_name,
- f.window_name,
+ COALESCE(f.app_name, o.app_name) as app_name,
+ COALESCE(f.window_name, o.window_name) as window_name,
o.text as ocr_text,
o.text_json
FROM frames f
diff --git a/screenpipe-server/src/server.rs b/screenpipe-server/src/server.rs
index d4eea220a..95e618bec 100644
--- a/screenpipe-server/src/server.rs
+++ b/screenpipe-server/src/server.rs
@@ -2388,7 +2388,7 @@ async fn handle_stream_frames_socket(socket: WebSocket, state: Arc<AppState>) {
let db = state.db.clone();
// Create a buffer for batching frames
- let mut frame_buffer = Vec::with_capacity(50);
+ let mut frame_buffer = Vec::with_capacity(100);
let mut buffer_timer = tokio::time::interval(Duration::from_millis(100));
// Handle incoming messages for time range requests
@@ -2450,7 +2450,7 @@ async fn handle_stream_frames_socket(socket: WebSocket, state: Arc<AppState>) {
frame_buffer.push(StreamTimeSeriesResponse::from(timeseries_frame));
// If buffer is full, send immediately
- if frame_buffer.len() >= 50 {
+ if frame_buffer.len() >= 100 {
if let Err(e) = send_batch(&mut sender, &mut frame_buffer).await {
error!("failed to send batch: {}", e);
break;
diff --git a/screenpipe-server/src/video_utils.rs b/screenpipe-server/src/video_utils.rs
index 2e2e56eaf..073dbb3d8 100644
--- a/screenpipe-server/src/video_utils.rs
+++ b/screenpipe-server/src/video_utils.rs
@@ -306,23 +306,42 @@ pub async fn extract_frames_from_video(
}
async fn get_video_fps(ffmpeg_path: &PathBuf, video_path: &str) -> Result<f64> {
- let output = Command::new(ffmpeg_path)
- .args(["-i", video_path])
+ let ffprobe_path = ffmpeg_path.with_file_name("ffprobe");
+
+ let output = Command::new(&ffprobe_path)
+ .args([
+ "-v",
+ "quiet",
+ "-print_format",
+ "json",
+ "-show_format",
+ "-show_streams",
+ video_path,
+ ])
.output()
.await?;
- let metadata = String::from_utf8_lossy(&output.stderr);
+ let stdout = String::from_utf8_lossy(&output.stdout);
+ let metadata: FFprobeOutput = serde_json::from_str(&stdout)?;
+
let fps = metadata
- .lines()
- .find(|line| line.contains("fps") && !line.contains("Stream"))
- .and_then(|line| {
- line.split_whitespace()
- .find(|&word| word.parse::<f64>().is_ok())
- .and_then(|n| n.parse::<f64>().ok())
+ .streams
+ .first()
+ .and_then(|s| {
+ let parts: Vec<f64> = s
+ .r_frame_rate
+ .split('/')
+ .filter_map(|n| n.parse().ok())
+ .collect();
+ if parts.len() == 2 && parts[1] != 0.0 {
+ Some(parts[0] / parts[1])
+ } else {
+ None
+ }
})
.unwrap_or(1.0);
- debug!("detected fps from video metadata: {}", fps);
+ debug!("Video FPS: {}", fps);
Ok(fps)
}
@@ -515,7 +534,7 @@ impl VideoMetadataOverride {
pub async fn extract_frame_from_video(file_path: &str, offset_index: i64) -> Result<String> {
let ffmpeg_path = find_ffmpeg_path().expect("failed to find ffmpeg path");
- let source_fps = match get_video_fps(&ffmpeg_path, &file_path).await {
+ let source_fps = match get_video_fps(&ffmpeg_path, file_path).await {
Ok(fps) => fps,
Err(e) => {
error!("failed to get video fps, using default 1fps: {}", e);