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(brain): preload tab counts
Louis Beaumontca6c8319aeab
diff --git a/apps/screenpipe-app-tauri/components/settings/__tests__/brain-section.filter.test.tsx b/apps/screenpipe-app-tauri/components/settings/__tests__/brain-section.filter.test.tsxindex 3bdd4aadb..cecc5a909 100644--- a/apps/screenpipe-app-tauri/components/settings/__tests__/brain-section.filter.test.tsx+++ b/apps/screenpipe-app-tauri/components/settings/__tests__/brain-section.filter.test.tsx@@ -107,6 +107,10 @@ vi.mock("@/lib/api", () => ({vi.mock("@/lib/utils/tauri", () => ({commands: {+ listBrainViews: vi.fn(async () => ({+ status: "ok",+ data: [{ id: "daily" }, { id: "meetings" }, { id: "processes" }],+ })),readViewerFile: vi.fn(async () => ({ status: "ok", data: { kind: "text", text: "full" } })),openViewerWindow: vi.fn(async () => undefined),},@@ -162,6 +166,16 @@ const artifactRows = () =>screen.queryAllByTestId(/^brain-item-artifact-/);describe("BrainSection type filter", () => {+ it("loads all tab totals before the user opens each tab", async () => {+ render(<BrainSection />);++ await waitFor(() => {+ expect(screen.getByTestId("brain-filter-overview")).toHaveTextContent("Live Views3");+ expect(screen.getByTestId("brain-filter-memories")).toHaveTextContent("Memories8");+ expect(screen.getByTestId("brain-filter-artifacts")).toHaveTextContent("Artifacts5");+ });+ });+it("shows memories by default", async () => {render(<BrainSection />);await waitFor(() => expect(memoryRows().length).toBe(8));diff --git a/apps/screenpipe-app-tauri/components/settings/brain-overview.tsx b/apps/screenpipe-app-tauri/components/settings/brain-overview.tsxindex 76e42080b..6921b07d1 100644--- a/apps/screenpipe-app-tauri/components/settings/brain-overview.tsx+++ b/apps/screenpipe-app-tauri/components/settings/brain-overview.tsx@@ -279,7 +279,11 @@ function uniqueDashboardTitle(title: string, views: ViewDefinition[]): string {return `${title} ${suffix}`;}-export function BrainOverview() {+export function BrainOverview({+ onViewCountChange,+}: {+ onViewCountChange?: (count: number) => void;+} = {}) {const { toast } = useToast();const { pipes, refetch: refetchPipes } = usePipes();const { settings } = useSettings();@@ -406,6 +410,10 @@ export function BrainOverview() {});}, [view]);+ useEffect(() => {+ onViewCountChange?.(views.length);+ }, [onViewCountChange, views.length]);+useEffect(() => {void load();const interval = setInterval(() => void load(true), 30_000);diff --git a/apps/screenpipe-app-tauri/components/settings/brain-section.tsx b/apps/screenpipe-app-tauri/components/settings/brain-section.tsxindex 08d6eda71..95c22d031 100644--- a/apps/screenpipe-app-tauri/components/settings/brain-section.tsx+++ b/apps/screenpipe-app-tauri/components/settings/brain-section.tsx@@ -347,6 +347,9 @@ export function BrainSection() {const initialTypeFilterRef = useRef<TypeFilter>(brainViewState.typeFilter);const [memories, setMemories] = useState<MemoryRecord[]>([]);const [total, setTotal] = useState(0);+ const [liveViewsTabCount, setLiveViewsTabCount] = useState<number | null>(null);+ const [memoriesTabCount, setMemoriesTabCount] = useState<number | null>(null);+ const [artifactsTabCount, setArtifactsTabCount] = useState<number | null>(null);const [loading, setLoading] = useState(true);const [loadingMore, setLoadingMore] = useState(false);const [deletingId, setDeletingId] = useState<number | null>(null);@@ -390,6 +393,32 @@ export function BrainSection() {});}, []);+ const refreshTabCounts = useCallback(async () => {+ const [viewsResult, memoriesResult, artifactsResult] = await Promise.allSettled([+ commands.listBrainViews(),+ localFetch("/memories?limit=1&offset=0"),+ localFetch("/artifacts?limit=1&offset=0"),+ ]);++ if (viewsResult.status === "fulfilled" && viewsResult.value.status === "ok") {+ setLiveViewsTabCount(viewsResult.value.data.length);+ }+ if (memoriesResult.status === "fulfilled" && memoriesResult.value.ok) {+ const data: MemoryListResponse = await memoriesResult.value.json();+ setMemoriesTabCount(data.pagination.total);+ }+ if (artifactsResult.status === "fulfilled" && artifactsResult.value.ok) {+ const data = await artifactsResult.value.json();+ setArtifactsTabCount(data.pagination?.total ?? 0);+ }+ }, []);++ useEffect(() => {+ void refreshTabCounts();+ const interval = window.setInterval(refreshTabCounts, 30_000);+ return () => window.clearInterval(interval);+ }, [refreshTabCounts]);+const loadArtifactContent = async (key: string, path: string) => {if (!artifactContents.has(key)) {try {@@ -588,6 +617,11 @@ export function BrainSection() {typeFilter === "artifacts",);+ useEffect(() => {+ if (typeFilter !== "artifacts" || artifactsLoading || artifactsError) return;+ setArtifactsTabCount(artifactsTotal);+ }, [artifactsError, artifactsLoading, artifactsTotal, typeFilter]);+// Fetch only the currently visible filter options; do not load every memory// label up front because large memory stores can have many distinct tags.useEffect(() => {@@ -658,6 +692,7 @@ export function BrainSection() {append ? [...prev, ...data.data] : data.data,);setTotal(data.pagination.total);+ setMemoriesTabCount(data.pagination.total);} catch (err) {if (offset === 0) {toast({@@ -1231,9 +1266,9 @@ export function BrainSection() {<div className="inline-flex items-center gap-1 border-b border-border">{([- { value: "overview", label: "Live Views" },- { value: "memories", label: "Memories", count: total },- { value: "artifacts", label: "Artifacts", count: artifactsTotal },+ { value: "overview", label: "Live Views", count: liveViewsTabCount ?? undefined },+ { value: "memories", label: "Memories", count: memoriesTabCount ?? undefined },+ { value: "artifacts", label: "Artifacts", count: artifactsTabCount ?? undefined },] as { value: TypeFilter; label: string; count?: number }[]).map(({ value, label, count }) => (<button@@ -1349,7 +1384,7 @@ export function BrainSection() {</div>{typeFilter === "overview" ? (- <BrainOverview />+ <BrainOverview onViewCountChange={setLiveViewsTabCount} />) : (<>