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

feat: fix hooks crash, add ask AI button to tag toolbar, improve chat context UX

Louis Beaumont525b9ece5955
diff --git a/apps/screenpipe-app-tauri/components/rewind/timeline.tsx b/apps/screenpipe-app-tauri/components/rewind/timeline.tsx
index 6e9f352ae..d7c7010e8 100644
--- a/apps/screenpipe-app-tauri/components/rewind/timeline.tsx
+++ b/apps/screenpipe-app-tauri/components/rewind/timeline.tsx
@@ -541,98 +541,105 @@ export default function Timeline() {
};
}, [showSearchModal]);
- // Pass selection context to chat when chat shortcut is pressed with a selection
- useEffect(() => {
- const handleChatShortcut = (e: KeyboardEvent) => {
- // Check for Ctrl+Cmd+L (macOS) or Alt+L (Windows)
- const isMac = navigator.platform.toLowerCase().includes("mac");
- const isChatShortcut = isMac
- ? e.ctrlKey && e.metaKey && e.key.toLowerCase() === "l"
- : e.altKey && e.key.toLowerCase() === "l";
+ // Send timeline selection context to chat
+ const sendSelectionToChat = useCallback(async () => {
+ if (!selectionRange) return;
- if (isChatShortcut && selectionRange) {
- // Build context from the selection
- const startTime = selectionRange.start.toLocaleString();
- const endTime = selectionRange.end.toLocaleString();
+ const startTime = selectionRange.start.toLocaleString();
+ const endTime = selectionRange.end.toLocaleString();
- // Get OCR/audio context from frames in the selection range
- const selectedFrames = frames.filter((frame) => {
- const frameTime = new Date(frame.timestamp).getTime();
- return (
- frameTime >= selectionRange.start.getTime() &&
- frameTime <= selectionRange.end.getTime()
- );
- });
+ // Get OCR/audio context from frames in the selection range
+ const selectedFrames = frames.filter((frame) => {
+ const frameTime = new Date(frame.timestamp).getTime();
+ return (
+ frameTime >= selectionRange.start.getTime() &&
+ frameTime <= selectionRange.end.getTime()
+ );
+ });
- // Build context string
- const contextParts: string[] = [];
- contextParts.push(`Time range: ${startTime} - ${endTime}`);
+ // Build context string
+ const contextParts: string[] = [];
+ contextParts.push(`Time range: ${startTime} - ${endTime}`);
- // Add app names
- const apps = new Set<string>();
- selectedFrames.forEach((frame) => {
- frame.devices.forEach((device) => {
- if (device.metadata.app_name) {
- apps.add(device.metadata.app_name);
- }
- });
- });
- if (apps.size > 0) {
- contextParts.push(`Apps: ${Array.from(apps).join(", ")}`);
+ // Add app names
+ const apps = new Set<string>();
+ selectedFrames.forEach((frame) => {
+ frame.devices.forEach((device) => {
+ if (device.metadata.app_name) {
+ apps.add(device.metadata.app_name);
}
+ });
+ });
+ if (apps.size > 0) {
+ contextParts.push(`Apps: ${Array.from(apps).join(", ")}`);
+ }
- // Add sample OCR text (first few frames)
- const ocrSamples: string[] = [];
- selectedFrames.slice(0, 3).forEach((frame) => {
- frame.devices.forEach((device) => {
- if (device.metadata.ocr_text && device.metadata.ocr_text.length > 0) {
- const sample = device.metadata.ocr_text.slice(0, 200);
- if (sample.trim()) {
- ocrSamples.push(sample);
- }
- }
- });
- });
- if (ocrSamples.length > 0) {
- contextParts.push(`Screen text samples:\n${ocrSamples.join("\n---\n")}`);
+ // Add sample OCR text (first few frames)
+ const ocrSamples: string[] = [];
+ selectedFrames.slice(0, 3).forEach((frame) => {
+ frame.devices.forEach((device) => {
+ if (device.metadata.ocr_text && device.metadata.ocr_text.length > 0) {
+ const sample = device.metadata.ocr_text.slice(0, 200);
+ if (sample.trim()) {
+ ocrSamples.push(sample);
+ }
}
+ });
+ });
+ if (ocrSamples.length > 0) {
+ contextParts.push(`Screen text samples:\n${ocrSamples.join("\n---\n")}`);
+ }
- // Add audio transcriptions if any
- const audioSamples: string[] = [];
- selectedFrames.slice(0, 3).forEach((frame) => {
- frame.devices.forEach((device) => {
- device.audio?.forEach((audio) => {
- if (audio.transcription && audio.transcription.trim()) {
- audioSamples.push(audio.transcription.slice(0, 200));
- }
- });
- });
+ // Add audio transcriptions if any
+ const audioSamples: string[] = [];
+ selectedFrames.slice(0, 3).forEach((frame) => {
+ frame.devices.forEach((device) => {
+ device.audio?.forEach((audio) => {
+ if (audio.transcription && audio.transcription.trim()) {
+ audioSamples.push(audio.transcription.slice(0, 200));
+ }
});
- if (audioSamples.length > 0) {
- contextParts.push(`Audio transcriptions:\n${audioSamples.join("\n---\n")}`);
- }
+ });
+ });
+ if (audioSamples.length > 0) {
+ contextParts.push(`Audio transcriptions:\n${audioSamples.join("\n---\n")}`);
+ }
- const context = contextParts.join("\n\n");
+ const context = contextParts.join("\n\n");
- // Emit the chat-prefill event to the chat window
- // Use a small delay to ensure chat window is open first
- setTimeout(() => {
- emit("chat-prefill", {
- context,
- prompt: `Based on my activity from ${startTime} to ${endTime}, `,
- });
- }, 200);
+ // Open chat window first, then emit context
+ await commands.showWindow("Chat");
+ setTimeout(() => {
+ emit("chat-prefill", {
+ context,
+ prompt: `Based on my activity from ${startTime} to ${endTime}, `,
+ source: "timeline",
+ });
+ }, 200);
- posthog.capture("timeline_selection_to_chat", {
- selection_duration_ms: selectionRange.end.getTime() - selectionRange.start.getTime(),
- frames_in_selection: selectedFrames.length,
- });
+ posthog.capture("timeline_selection_to_chat", {
+ selection_duration_ms: selectionRange.end.getTime() - selectionRange.start.getTime(),
+ frames_in_selection: selectedFrames.length,
+ });
+ }, [selectionRange, frames]);
+
+ // Pass selection context to chat when chat shortcut is pressed with a selection
+ useEffect(() => {
+ const handleChatShortcut = (e: KeyboardEvent) => {
+ // Check for Ctrl+Cmd+L (macOS) or Alt+L (Windows)
+ const isMac = navigator.platform.toLowerCase().includes("mac");
+ const isChatShortcut = isMac
+ ? e.ctrlKey && e.metaKey && e.key.toLowerCase() === "l"
+ : e.altKey && e.key.toLowerCase() === "l";
+
+ if (isChatShortcut && selectionRange) {
+ sendSelectionToChat();
}
};
window.addEventListener("keydown", handleChatShortcut);
return () => window.removeEventListener("keydown", handleChatShortcut);
- }, [selectionRange, frames]);
+ }, [selectionRange, sendSelectionToChat]);
// Also listen for "/" key (not intercepted by Rust)
useEffect(() => {
@@ -1503,6 +1510,7 @@ export default function Timeline() {
zoomLevel={zoomLevel}
targetZoom={targetZoom}
setTargetZoom={setTargetZoom}
+ onAskAI={sendSelectionToChat}
/>
) : (
<div className="bg-card/80 backdrop-blur-sm p-4 border-t border-border">
diff --git a/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-tag-toolbar.tsx b/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-tag-toolbar.tsx
index 5e8f3b08d..1eb40d979 100644
--- a/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-tag-toolbar.tsx
+++ b/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-tag-toolbar.tsx
@@ -4,8 +4,8 @@
import { useTimelineSelection } from "@/lib/hooks/use-timeline-selection";
import { cn } from "@/lib/utils";
import { format } from "date-fns";
-import { Tag, Plus } from "lucide-react";
-import { useState, useRef, useMemo } from "react";
+import { Tag, Plus, MessageSquare } from "lucide-react";
+import { useState, useRef, useMemo, useCallback } from "react";
import { createPortal } from "react-dom";
import { toast } from "@/components/ui/use-toast";
import posthog from "posthog-js";
@@ -15,31 +15,19 @@ const QUICK_TAGS = ["deep work", "meeting", "admin", "break"];
interface TimelineTagToolbarProps {
/** Bounding rect of the selection range for positioning */
anchorRect: { x: number; y: number; width: number } | null;
+ /** Called when user clicks "ask AI" — parent handles building context and opening chat */
+ onAskAI?: () => void;
}
-export function TimelineTagToolbar({ anchorRect }: TimelineTagToolbarProps) {
+export function TimelineTagToolbar({ anchorRect, onAskAI }: TimelineTagToolbarProps) {
const { selectionRange, tagFrames, setSelectionRange, tags } = useTimelineSelection();
const [customTag, setCustomTag] = useState("");
const [isApplying, setIsApplying] = useState(false);
const inputRef = useRef<HTMLInputElement>(null);
- if (!selectionRange || !anchorRect || selectionRange.frameIds.length === 0) {
- return null;
- }
-
- const { start, end, frameIds } = selectionRange;
-
- // Format the selection time range
- const startTime = format(start, "h:mm a");
- const endTime = format(end, "h:mm a");
- const durationMs = end.getTime() - start.getTime();
- const durationMins = Math.round(durationMs / 60000);
- const durationStr =
- durationMins >= 60
- ? `${Math.floor(durationMins / 60)}h ${durationMins % 60}m`
- : `${durationMins}m`;
+ const frameIds = selectionRange?.frameIds ?? [];
- // Collect existing tags on selected frames
+ // Collect existing tags on selected frames — must be called before any early return
const existingTags = useMemo(() => {
const tagSet = new Set<string>();
for (const id of frameIds) {
@@ -49,8 +37,8 @@ export function TimelineTagToolbar({ anchorRect }: TimelineTagToolbarProps) {
return [...tagSet];
}, [frameIds, tags]);
- const handleApplyTag = async (tag: string) => {
- if (!tag.trim() || isApplying) return;
+ const handleApplyTag = useCallback(async (tag: string) => {
+ if (!tag.trim() || isApplying || frameIds.length === 0) return;
setIsApplying(true);
try {
await tagFrames(frameIds, tag.trim());
@@ -74,12 +62,29 @@ export function TimelineTagToolbar({ anchorRect }: TimelineTagToolbarProps) {
} finally {
setIsApplying(false);
}
- };
+ }, [isApplying, frameIds, tagFrames, setSelectionRange]);
- const handleCustomSubmit = (e: React.FormEvent) => {
+ const handleCustomSubmit = useCallback((e: React.FormEvent) => {
e.preventDefault();
handleApplyTag(customTag);
- };
+ }, [handleApplyTag, customTag]);
+
+ // Early return AFTER all hooks
+ if (!selectionRange || !anchorRect || frameIds.length === 0) {
+ return null;
+ }
+
+ const { start, end } = selectionRange;
+
+ // Format the selection time range
+ const startTime = format(start, "h:mm a");
+ const endTime = format(end, "h:mm a");
+ const durationMs = end.getTime() - start.getTime();
+ const durationMins = Math.round(durationMs / 60000);
+ const durationStr =
+ durationMins >= 60
+ ? `${Math.floor(durationMins / 60)}h ${durationMins % 60}m`
+ : `${durationMins}m`;
// Center the toolbar above the selection
const left = anchorRect.x + anchorRect.width / 2;
@@ -95,12 +100,23 @@ export function TimelineTagToolbar({ anchorRect }: TimelineTagToolbarProps) {
}}
>
<div className="bg-popover border border-border rounded-xl shadow-2xl px-3 py-2.5 flex flex-col gap-2 min-w-[280px]">
- {/* Selection info */}
- <div className="flex items-center gap-2 text-xs text-muted-foreground">
- <Tag className="w-3 h-3" />
- <span>
- {startTime} → {endTime} ({durationStr}, {frameIds.length} frames)
- </span>
+ {/* Selection info + ask AI */}
+ <div className="flex items-center justify-between gap-2">
+ <div className="flex items-center gap-2 text-xs text-muted-foreground">
+ <Tag className="w-3 h-3" />
+ <span>
+ {startTime} → {endTime} ({durationStr})
+ </span>
+ </div>
+ {onAskAI && (
+ <button
+ onClick={onAskAI}
+ className="flex items-center gap-1 text-xs px-2 py-1 rounded-md bg-foreground text-background hover:bg-foreground/90 transition-colors font-medium"
+ >
+ <MessageSquare className="w-3 h-3" />
+ ask ai
+ </button>
+ )}
</div>
{/* Existing tags on selection */}
diff --git a/apps/screenpipe-app-tauri/components/rewind/timeline/timeline.tsx b/apps/screenpipe-app-tauri/components/rewind/timeline/timeline.tsx
index d35390aa1..ba07fdfda 100644
--- a/apps/screenpipe-app-tauri/components/rewind/timeline/timeline.tsx
+++ b/apps/screenpipe-app-tauri/components/rewind/timeline/timeline.tsx
@@ -27,6 +27,7 @@ interface TimelineSliderProps {
zoomLevel: number;
targetZoom: number;
setTargetZoom: (fn: (prev: number) => number) => void;
+ onAskAI?: () => void;
}
interface AppGroup {
@@ -139,6 +140,7 @@ export const TimelineSlider = ({
zoomLevel,
targetZoom,
setTargetZoom,
+ onAskAI,
}: TimelineSliderProps) => {
const containerRef = useRef<HTMLDivElement>(null);
const observerTargetRef = useRef<HTMLDivElement>(null);
@@ -794,7 +796,7 @@ export const TimelineSlider = ({
{/* Tag toolbar — floating above selection */}
{selectedIndices.size > 1 && selectionRange && (
- <TimelineTagToolbar anchorRect={selectionRect} />
+ <TimelineTagToolbar anchorRect={selectionRect} onAskAI={onAskAI} />
)}
</div>
);
diff --git a/apps/screenpipe-app-tauri/components/standalone-chat.tsx b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
index 835f4e618..7e69accc2 100644
--- a/apps/screenpipe-app-tauri/components/standalone-chat.tsx
+++ b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
@@ -471,6 +471,7 @@ export function StandaloneChat() {
const [upgradeReason, setUpgradeReason] = useState<"daily_limit" | "model_not_allowed" | "rate_limit">("daily_limit");
const [upgradeResetsAt, setUpgradeResetsAt] = useState<string | undefined>();
const [prefillContext, setPrefillContext] = useState<string | null>(null);
+ const [prefillSource, setPrefillSource] = useState<string>("search");
const [prefillFrameId, setPrefillFrameId] = useState<number | null>(null);
const [pastedImage, setPastedImage] = useState<string | null>(null); // Base64 data URL
const [isDragging, setIsDragging] = useState(false);
@@ -814,8 +815,8 @@ export function StandaloneChat() {
// Listen for chat-prefill events from search modal and pipe creation
useEffect(() => {
- const unlisten = listen<{ context: string; prompt?: string; frameId?: number; autoSend?: boolean }>("chat-prefill", (event) => {
- const { context, prompt, frameId, autoSend } = event.payload;
+ const unlisten = listen<{ context: string; prompt?: string; frameId?: number; autoSend?: boolean; source?: string }>("chat-prefill", (event) => {
+ const { context, prompt, frameId, autoSend, source } = event.payload;
if (autoSend && prompt && context) {
// Auto-send: compose full message (context above, user text below) and send immediately
@@ -846,6 +847,7 @@ export function StandaloneChat() {
}
setPrefillContext(context);
+ setPrefillSource(source || "search");
if (frameId) {
setPrefillFrameId(frameId);
}
@@ -1639,8 +1641,9 @@ export function StandaloneChat() {
// Clear prefill context banner (was only cleared in non-Pi path)
if (prefillContext) {
- // Prepend search context to the user message so Pi sees it
- userMessage = `[Context from search: ${prefillContext}]\n\n${userMessage}`;
+ // Prepend context to the user message so Pi sees it
+ const contextLabel = prefillSource === "timeline" ? "timeline selection" : "search";
+ userMessage = `[Context from ${contextLabel}: ${prefillContext}]\n\n${userMessage}`;
setPrefillContext(null);
}
@@ -2215,7 +2218,7 @@ export function StandaloneChat() {
{prefillContext && (
<div className="flex-1 min-w-0">
<div className="text-[10px] font-medium text-muted-foreground uppercase tracking-wider mb-1">
- context from search
+ context from {prefillSource === "timeline" ? "timeline selection" : "search"}
</div>
<p className="text-xs text-foreground font-mono line-clamp-2">
{prefillContext.slice(0, 150)}{prefillContext.length > 150 ? "..." : ""}
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
index d7c1c8751..a9634e429 100755
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -8097,7 +8097,7 @@ dependencies = [
[[package]]
name = "screenpipe-app"
-version = "2.0.474"
+version = "2.0.477"
dependencies = [
"anyhow",
"arboard",