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

refactor(search): remove separate search window, add AI to modal

Louis Beaumontd77dd674405f
diff --git a/screenpipe-app-tauri/app/page.tsx b/screenpipe-app-tauri/app/page.tsx
index 460a65178..c6ec2a91d 100644
--- a/screenpipe-app-tauri/app/page.tsx
+++ b/screenpipe-app-tauri/app/page.tsx
@@ -21,7 +21,6 @@ import { RefreshCw, AlertTriangle } from "lucide-react";
import { PermissionButtons } from "@/components/status/permission-buttons";
import { usePlatform } from "@/lib/hooks/use-platform";
import SplashScreen from "@/components/splash-screen";
-import { SearchCommand } from "@/components/rewind/search-command";
export default function Home() {
const { settings, updateSettings, loadUser, reloadStore, isSettingsLoaded, loadingError } = useSettings();
@@ -152,7 +151,6 @@ export default function Home() {
</div>
)}
<Timeline />
- <SearchCommand />
</div>
) : (
<div className="flex items-center justify-center h-screen p-4 bg-background w-full">
diff --git a/screenpipe-app-tauri/app/search/page.tsx b/screenpipe-app-tauri/app/search/page.tsx
deleted file mode 100644
index cb3dffca8..000000000
--- a/screenpipe-app-tauri/app/search/page.tsx
+++ /dev/null
@@ -1,202 +0,0 @@
-"use client";
-
-import { DatePickerWithRange } from "@/components/rewind/date-range-picker";
-import { ImageGrid, MainImage, SkeletonCard } from "@/components/rewind/image-card";
-import { SearchBar } from "@/components/rewind/search-bar";
-import { Button } from "@/components/ui/button";
-import { useDebounce } from "@/lib/hooks/use-debounce";
-import { useKeywordSearchStore } from "@/lib/hooks/use-keyword-search-store";
-import { endOfDay, startOfDay, format } from "date-fns";
-import { useCallback, useEffect, useRef, Suspense } from "react";
-import { parser } from "@/lib/keyword-parser";
-import { CurrentFrame } from "@/components/rewind/current-frame-search";
-import { useKeywordParams } from "@/lib/hooks/use-keyword-params";
-import { AppSelect } from "@/components/rewind/search-command";
-import { ArrowLeft, Clock, MessageSquare } from "lucide-react";
-import { emit } from "@tauri-apps/api/event";
-import { commands } from "@/lib/utils/tauri";
-
-function SearchPage() {
- const [querys, setQuerys] = useKeywordParams();
- const debounceQuerys = useDebounce(querys, 300);
- const {
- searchKeywords,
- isSearching,
- searchResults,
- currentResultIndex,
- setCurrentResultIndex,
- } = useKeywordSearchStore();
- const pageRef = useRef<HTMLDivElement>(null);
-
- const handleSearch = useCallback(
- async (
- query: string,
- start: Date | undefined,
- end: Date | undefined,
- app_names: string[] | undefined,
- ) => {
- await searchKeywords(query, {
- limit: 20,
- offset: 0,
- start_time: start,
- end_time: end,
- app_names,
- });
- },
- [searchResults],
- );
-
- useEffect(() => {
- if (!debounceQuerys.query || debounceQuerys.query.length === 0) {
- setCurrentResultIndex(-1);
- return;
- }
-
- const keywords = parser.parse(debounceQuerys.query);
- if (keywords.keywords.length === 0) return;
-
- console.log(keywords.keywords);
-
- handleSearch(
- keywords.keywords.join(" "),
- debounceQuerys.start_time ?? undefined,
- debounceQuerys.end_time ?? undefined,
- debounceQuerys.apps?.length ? debounceQuerys.apps : undefined,
- );
- }, [debounceQuerys]);
-
- useEffect(() => {
- console.log(currentResultIndex);
- }, [currentResultIndex]);
-
- return (
- <div
- ref={pageRef}
- className="mx-auto flex flex-col justify-between space-y-4 animate-fade-in p-4 min-h-screen overflow-hidden"
- >
- <div className="space-y-4 ">
- <div className="flex items-center gap-4 justify-center">
- <div className="grid grid-cols-3 gap-4 items-center h-10">
- <SearchBar
- search={querys.query}
- onSearchChange={(query) => {
- setQuerys((prev) => ({
- ...prev,
- query,
- }));
- }}
- autoFocus
- />
- <DatePickerWithRange
- start_time={querys.start_time}
- end_time={querys.end_time}
- setDateRange={(dates) => {
- setQuerys((prev) => ({
- ...prev,
- start_time: dates?.from ? startOfDay(dates?.from) : null,
- end_time: dates?.to ? endOfDay(dates?.to) : null,
- }));
- }}
- />
- <AppSelect
- apps={querys.apps ?? []}
- setApps={(values) => {
- setQuerys((prev) => ({
- ...prev,
- apps: values,
- }));
- }}
- />
- </div>
- </div>
- <div className="relative">
- <CurrentFrame />
- {currentResultIndex >= 0 && searchResults[currentResultIndex] && (
- <div className="absolute bottom-2 right-2 flex gap-2">
- <Button
- variant="secondary"
- size="sm"
- className="gap-1.5"
- onClick={async () => {
- const result = searchResults[currentResultIndex];
- // Build context for AI chat
- const context = `Context from search result:\n${result.app_name} - ${result.window_name}\nTime: ${format(new Date(result.timestamp), "PPpp")}\n\nText:\n${result.text || ""}`;
- // Open AI chat window with context
- await commands.showWindow("Chat");
- await emit("chat-prefill", { context });
- }}
- >
- <MessageSquare className="h-3.5 w-3.5" />
- ask AI
- </Button>
- <Button
- variant="secondary"
- size="sm"
- className="gap-1.5"
- onClick={async () => {
- const timestamp = searchResults[currentResultIndex].timestamp;
- // Show main timeline window
- await commands.showWindow("Main");
- // Emit event to navigate to the timestamp
- await emit("navigate-to-timestamp", timestamp);
- // Close search window
- await commands.closeWindow({ Search: { query: null } });
- }}
- >
- <Clock className="h-3.5 w-3.5" />
- view in timeline
- </Button>
- </div>
- )}
- </div>
- </div>
- {!querys.query && (
- <div className="h-64 w-96 flex mx-auto items-center justify-center">
- <p className="text-sm text-muted-foreground">
- Please provide query for searching
- </p>
- </div>
- )}
-
- {!isSearching && searchResults.length === 0 && querys.query ? (
- <div className="h-64 w-96 flex mx-auto items-center justify-center whitespace-nowrap">
- <p className="text-sm text-muted-foreground">
- No results found for &quot;{querys.query}&quot;
- </p>
- </div>
- ) : null}
-
- {isSearching && searchResults.length === 0 && (
- <div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-4 p-4">
- {Array.from({ length: 15 }).map((_, index) => (
- <SkeletonCard key={`skeleton-${index}`} />
- ))}
- </div>
- )}
-
- {querys.query && !(searchResults.length === 0) ? (
- <div className="flex-1 overflow-hidden">
- <ImageGrid searchResult={searchResults} pageRef={pageRef} />
- </div>
- ) : (
- <div></div>
- )}
-
- {/* Keyboard hints footer */}
- <div className="fixed bottom-0 left-0 right-0 px-4 py-2 border-t border-border bg-background/80 backdrop-blur-sm flex items-center justify-center gap-6 text-[10px] text-muted-foreground font-mono">
- <span>←→↑↓ navigate</span>
- <span>click select</span>
- <span>hover expand</span>
- <span>esc close</span>
- </div>
- </div>
- );
-}
-
-export default function Page() {
- return (
- <Suspense fallback={<div>Loading...</div>}>
- <SearchPage />
- </Suspense>
- );
-}
diff --git a/screenpipe-app-tauri/components/rewind/current-frame-search.tsx b/screenpipe-app-tauri/components/rewind/current-frame-search.tsx
deleted file mode 100644
index 968fe9525..000000000
--- a/screenpipe-app-tauri/components/rewind/current-frame-search.tsx
+++ /dev/null
@@ -1,16 +0,0 @@
-import { MainImage } from "./image-card";
-import { cn } from "@/lib/utils";
-
-export const CurrentFrame = () => {
- return (
- <div
- className={cn(
- "grid md:gap-4 gap-y-4 w-4/5 mx-auto min-h-[40%] max-h-[50%] max-w-[55vw] overflow-hidden",
- )}
- >
- <div className={cn("relative group w-full")}>
- <MainImage />
- </div>
- </div>
- );
-};
diff --git a/screenpipe-app-tauri/components/rewind/search-command.tsx b/screenpipe-app-tauri/components/rewind/search-command.tsx
deleted file mode 100644
index 5cfd2ac7f..000000000
--- a/screenpipe-app-tauri/components/rewind/search-command.tsx
+++ /dev/null
@@ -1,358 +0,0 @@
-"use client";
-
-import * as React from "react";
-import { listen } from "@tauri-apps/api/event";
-import { useState, useEffect } from "react";
-import {
- Tooltip,
- TooltipContent,
- TooltipProvider,
- TooltipTrigger,
-} from "./ui/tooltip";
-import { MultiSelectCombobox } from "./ui/multi-select-combobox";
-import { useSqlAutocomplete } from "@/lib/hooks/use-sql-autocomplete";
-import { Dialog, DialogTitle } from "./ui/dialog";
-import { Input } from "./ui/input";
-import { DatePickerWithRange } from "./date-range-picker";
-import { queryParser, QueryParser, querySerializer, cn } from "@/lib/utils";
-import { CustomDialogContent } from "./custom-dialog-content";
-import { ArrowRight, XIcon, Search, Loader2 } from "lucide-react";
-import { useQueryStates } from "nuqs";
-import { commands } from "@/lib/utils/tauri";
-import { Badge } from "./ui/badge";
-import { usePlatform } from "@/lib/hooks/use-platform";
-import { useSettings } from "@/lib/hooks/use-settings";
-import { formatShortcutDisplay } from "@/components/global-chat";
-
-const SCREENPIPE_API = "http://localhost:3030";
-
-interface SearchResult {
- type: "OCR" | "Audio" | "UI";
- content: {
- text?: string;
- transcription?: string;
- timestamp: string;
- app_name?: string;
- window_name?: string;
- device_name?: string;
- };
-}
-
-export function SearchCommand() {
- const [open, setOpen] = React.useState(false);
- const { isMac } = usePlatform();
- const { settings } = useSettings();
- const inputRef = React.useRef<HTMLInputElement>(null);
-
- const [state] = useQueryStates(queryParser);
- const [options, setOptions] = useState<QueryParser>(
- !state
- ? {
- query: null,
- start_time: null,
- end_time: null,
- apps: [],
- }
- : state,
- );
-
- // Search results state
- const [results, setResults] = useState<SearchResult[]>([]);
- const [isSearching, setIsSearching] = useState(false);
- const [hasSearched, setHasSearched] = useState(false);
-
- // Listen for Rust-level open-search event (Cmd+K / Ctrl+K global shortcut)
- React.useEffect(() => {
- const unlisten = listen("open-search", () => {
- setOpen((open) => !open);
- });
- return () => {
- unlisten.then((fn) => fn());
- };
- }, []);
-
- // Focus input when dialog opens
- React.useEffect(() => {
- if (open) {
- // Use setTimeout to ensure the dialog has rendered
- setTimeout(() => inputRef.current?.focus(), 50);
- }
- }, [open]);
-
- // Close dialog when Tauri window loses focus
- React.useEffect(() => {
- const unlisten = listen<boolean>("window-focused", (event) => {
- if (!event.payload && open) {
- setOpen(false);
- }
- });
- return () => {
- unlisten.then((fn) => fn());
- };
- }, [open]);
-
- // Reset state when dialog closes
- useEffect(() => {
- if (!open) {
- setResults([]);
- setHasSearched(false);
- setOptions({
- query: null,
- start_time: null,
- end_time: null,
- apps: [],
- });
- }
- }, [open]);
-
- // Close search when window is hidden
- React.useEffect(() => {
- const unlisten = listen("window-hidden", () => {
- setOpen(false);
- });
- return () => {
- unlisten.then((fn) => fn());
- };
- }, []);
-
- // Execute search
- async function handleSearch() {
- if (!options.query?.trim()) return;
-
- setIsSearching(true);
- setHasSearched(true);
- setResults([]);
-
- try {
- const params = new URLSearchParams();
- params.append("q", options.query);
- params.append("limit", "10");
-
- if (options.apps && options.apps.length > 0) {
- params.append("app_name", options.apps[0]);
- }
- if (options.start_time) {
- params.append("start_time", options.start_time.toISOString());
- }
- if (options.end_time) {
- params.append("end_time", options.end_time.toISOString());
- }
-
- const response = await fetch(`${SCREENPIPE_API}/search?${params.toString()}`);
- if (!response.ok) throw new Error(`Search failed: ${response.status}`);
-
- const data = await response.json();
- setResults(data.data || []);
- } catch (error) {
- console.error("Search error:", error);
- } finally {
- setIsSearching(false);
- }
- }
-
- const handleKeyDown = (e: React.KeyboardEvent) => {
- if (e.key === "Enter" && !e.shiftKey) {
- e.preventDefault();
- if (options.query?.trim()) {
- commands.openSearchWindow(querySerializer(options));
- setOpen(false);
- }
- }
- };
-
- // Format result for display
- const formatResult = (result: SearchResult) => {
- const content = result.content;
- let text = "";
- if (result.type === "OCR" || result.type === "UI") {
- text = content.text || "";
- } else if (result.type === "Audio") {
- text = content.transcription || "";
- }
- // Truncate to 100 chars
- return text.length > 100 ? text.substring(0, 100) + "..." : text;
- };
-
- return (
- <Dialog open={open} onOpenChange={setOpen}>
- <DialogTitle className="sr-only">Search Command</DialogTitle>
- <CustomDialogContent
- className={cn(
- "p-0 max-w-screen-sm transition-all duration-200",
- hasSearched ? "max-h-[80vh]" : ""
- )}
- customClose={
- options.query ? (
- <button onClick={() => commands.openSearchWindow(querySerializer(options))}>
- <ArrowRight className="w-4 h-4" />
- </button>
- ) : (
- <XIcon className="w-4 h-4" />
- )
- }
- >
- {/* Search Input */}
- <div className="p-2 border-b">
- <div className="flex items-center gap-2">
- <Search className="h-4 w-4 text-muted-foreground shrink-0" />
- <Input
- ref={inputRef}
- value={options?.query || ""}
- className="focus-visible:outline-none focus-visible:ring-0 focus-visible:ring-offset-0 ring-0 outline-none border-0 h-10"
- placeholder="Search your screen activity..."
- onChange={(e) => {
- setOptions((prev) => ({ ...prev, query: e.target.value }));
- }}
- onKeyDown={handleKeyDown}
- />
- {isSearching && <Loader2 className="h-4 w-4 animate-spin" />}
- </div>
- <div className="flex w-full gap-2 mt-2">
- <div className="w-1/2">
- <AppSelect
- apps={options.apps || []}
- setApps={(values) => {
- setOptions((prev) => ({ ...prev, apps: values }));
- }}
- />
- </div>
- <div className="w-1/2">
- <DatePickerWithRange
- start_time={options.start_time}
- end_time={options.end_time}
- setDateRange={(range) => {
- setOptions((prev) => ({
- ...prev,
- start_time: range?.from ?? null,
- end_time: range?.to ?? null,
- }));
- }}
- />
- </div>
- </div>
- </div>
-
- {/* Search Results */}
- {hasSearched && (
- <div className="max-h-[300px] overflow-y-auto">
- {results.length === 0 && !isSearching ? (
- <p className="text-center text-muted-foreground py-4 text-sm">No results found</p>
- ) : (
- <div className="divide-y">
- {results.slice(0, 5).map((result, index) => (
- <div key={index} className="p-2 hover:bg-muted/50">
- <div className="flex items-center gap-2">
- <Badge variant="outline" className="text-xs shrink-0">
- {result.type}
- </Badge>
- <span className="text-xs text-muted-foreground shrink-0">
- {result.content.app_name || result.content.device_name || "Unknown"}
- </span>
- </div>
- <p className="text-sm mt-1 line-clamp-2">{formatResult(result)}</p>
- </div>
- ))}
- {results.length > 5 && (
- <button
- onClick={() => commands.openSearchWindow(querySerializer(options))}
- className="w-full p-2 text-sm text-muted-foreground hover:bg-muted/50 text-center"
- >
- +{results.length - 5} more results - click to view all
- </button>
- )}
- </div>
- )}
- </div>
- )}
-
- {/* Hint for AI chat */}
- <div className="px-3 py-2 border-t text-xs text-muted-foreground flex items-center justify-between">
- <span>Press Enter to search</span>
- <span>{formatShortcutDisplay(settings.showChatShortcut || "", isMac)} for AI chat</span>
- </div>
- </CustomDialogContent>
- </Dialog>
- );
-}
-
-interface AppSelectProps {
- apps: string[];
- setApps: (values: string[]) => void;
-}
-
-export function AppSelect({ apps, setApps }: AppSelectProps) {
- const { items, isLoading } = useSqlAutocomplete("app");
-
- const appItems = React.useMemo(() => {
- return items.map((app) => ({
- value: app.name,
- count: app.count,
- label: app.name,
- }));
- }, [items]);
-
- const renderTech = (option: (typeof appItems)[number]) => (
- <div className="flex items-center gap-2">
- <span className="text-xl">
- <img
- src={`http://localhost:11435/app-icon?name=${option.value}`}
- className="w-6 h-6"
- alt={option.value}
- loading="lazy"
- decoding="async"
- />
- </span>
- <div className="flex flex-col">
- <span>{option.label}</span>
- </div>
- </div>
- );
-
- const renderSelected = (value: string[]) => (
- <TooltipProvider>
- <Tooltip>
- <TooltipTrigger className="h-full">
- <div className="flex gap-1 h-full">
- {value.map((id) => {
- const tech = appItems.find((t) => t.value === id)!;
-
- if (!tech) return;
- return (
- <span key={id}>
- {
- <img
- src={`http://localhost:11435/app-icon?name=${tech.label}`}
- className="w-6 h-6"
- alt={tech.label}
- loading="lazy"
- decoding="async"
- />
- }
- </span>
- );
- })}
- </div>
- </TooltipTrigger>
- <TooltipContent>
- {value.map((id) => {
- const tech = appItems.find((t) => t.value === id)!;
- if (!tech) return;
- return <div key={id}>{tech.label}</div>;
- })}
- </TooltipContent>
- </Tooltip>
- </TooltipProvider>
- );
-
- return (
- <MultiSelectCombobox
- label="Applications"
- options={appItems}
- value={apps}
- onChange={setApps}
- renderItem={renderTech}
- renderSelectedItem={renderSelected}
- isLoading={isLoading}
- />
- );
-}
diff --git a/screenpipe-app-tauri/components/rewind/search-modal.tsx b/screenpipe-app-tauri/components/rewind/search-modal.tsx
index ee76f615a..0107d4eb8 100644
--- a/screenpipe-app-tauri/components/rewind/search-modal.tsx
+++ b/screenpipe-app-tauri/components/rewind/search-modal.tsx
@@ -1,11 +1,13 @@
"use client";
import { useEffect, useState, useRef, useCallback, useMemo } from "react";
-import { Search, X, Loader2, Clock } from "lucide-react";
+import { Search, X, Loader2, Clock, MessageSquare } from "lucide-react";
import { useKeywordSearchStore, SearchMatch } from "@/lib/hooks/use-keyword-search-store";
import { useDebounce } from "@/lib/hooks/use-debounce";
import { format, isToday, isYesterday } from "date-fns";
import { cn } from "@/lib/utils";
+import { commands } from "@/lib/utils/tauri";
+import { emit } from "@tauri-apps/api/event";
interface SearchModalProps {
isOpen: boolean;
@@ -96,6 +98,18 @@ export function SearchModal({ isOpen, onClose, onNavigateToTimestamp }: SearchMo
});
}, [debouncedQuery, searchKeywords, resetSearch]);
+ // Send to AI handler
+ const handleSendToAI = useCallback(async () => {
+ const result = searchResults[selectedIndex];
+ if (!result) return;
+
+ const context = `Context from search result:\n${result.app_name} - ${result.window_name}\nTime: ${format(new Date(result.timestamp), "PPpp")}\n\nText:\n${result.text || ""}`;
+
+ await commands.showWindow("Chat");
+ await emit("chat-prefill", { context });
+ onClose();
+ }, [searchResults, selectedIndex, onClose]);
+
// Keyboard navigation
useEffect(() => {
if (!isOpen) return;
@@ -125,7 +139,11 @@ export function SearchModal({ isOpen, onClose, onNavigateToTimestamp }: SearchMo
break;
case "Enter":
e.preventDefault();
- if (searchResults[selectedIndex]) {
+ if (e.metaKey || e.ctrlKey) {
+ // Cmd+Enter = send to AI
+ handleSendToAI();
+ } else if (searchResults[selectedIndex]) {
+ // Enter = navigate to timestamp
onNavigateToTimestamp(searchResults[selectedIndex].timestamp);
onClose();
}
@@ -135,7 +153,7 @@ export function SearchModal({ isOpen, onClose, onNavigateToTimestamp }: SearchMo
window.addEventListener("keydown", handleKeyDown);
return () => window.removeEventListener("keydown", handleKeyDown);
- }, [isOpen, searchResults, selectedIndex, onClose, onNavigateToTimestamp]);
+ }, [isOpen, searchResults, selectedIndex, onClose, onNavigateToTimestamp, handleSendToAI]);
// Scroll selected item into view
useEffect(() => {
@@ -286,7 +304,10 @@ export function SearchModal({ isOpen, onClose, onNavigateToTimestamp }: SearchMo
<div className="flex items-center gap-4">
<span>←→↑↓ navigate</span>
<span>⏎ go to timeline</span>
- <span>hover for details</span>
+ <span className="flex items-center gap-1">
+ <MessageSquare className="w-3 h-3" />
+ ⌘⏎ ask AI
+ </span>
</div>
<span>esc close</span>
</div>