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
measure Live View retained value
Louis Beaumont19c6547fcfbf
diff --git a/apps/screenpipe-app-tauri/components/settings/__tests__/brain-overview.test.tsx b/apps/screenpipe-app-tauri/components/settings/__tests__/brain-overview.test.tsxindex ea938a213..496c8c2e9 100644--- a/apps/screenpipe-app-tauri/components/settings/__tests__/brain-overview.test.tsx+++ b/apps/screenpipe-app-tauri/components/settings/__tests__/brain-overview.test.tsx@@ -152,6 +152,25 @@ beforeAll(() => {Element.prototype.scrollIntoView ||= () => {};});+function setDocumentVisibility(state: "visible" | "hidden"): () => void {+ const original = Object.getOwnPropertyDescriptor(+ Document.prototype,+ "visibilityState",+ );+ Object.defineProperty(document, "visibilityState", {+ configurable: true,+ get: () => state,+ });+ return () => {+ if (original) {+ Object.defineProperty(document, "visibilityState", original);+ } else {+ delete (document as { visibilityState?: DocumentVisibilityState })+ .visibilityState;+ }+ };+}+const populatedView: ViewDefinition = {id: "my-overview",title: "How I worked today",@@ -457,7 +476,7 @@ describe("BrainOverview", () => {expect(mocks.capture).toHaveBeenCalledWith("live_view_viewed",expect.objectContaining({- analytics_schema_version: 1,+ analytics_schema_version: 2,entry_method: "initial",dashboard_count: 1,block_count: 1,@@ -466,7 +485,10 @@ describe("BrainOverview", () => {source_pipe_count: 1,time_range: "today",has_result: true,+ all_bound_blocks_have_results: true,+ reviewed_block_count: 0,is_onboarding: false,+ onboarding_goal_category: "unknown",}),),);@@ -478,6 +500,64 @@ describe("BrainOverview", () => {expect(JSON.stringify(properties)).not.toContain("daily-summary");});+ it("captures a visible source-backed result separately from a dashboard view", async () => {+ mocks.listBrainViews.mockResolvedValue({+ status: "ok",+ data: [populatedView],+ });+ render(<BrainOverview />);++ await screen.findByText("How I worked today");+ await waitFor(() =>+ expect(mocks.capture).toHaveBeenCalledWith(+ "live_view_result_viewed",+ expect.objectContaining({+ analytics_schema_version: 2,+ entry_method: "initial",+ result_block_count: 1,+ all_bound_blocks_have_results: true,+ positive_feedback_block_count: 0,+ negative_feedback_block_count: 0,+ }),+ ),+ );+ const properties = mocks.capture.mock.calls.find(+ ([event]) => event === "live_view_result_viewed",+ )?.[1];+ expect(JSON.stringify(properties)).not.toContain("my-overview");+ expect(JSON.stringify(properties)).not.toContain("How I worked today");+ expect(JSON.stringify(properties)).not.toContain("daily-summary");+ expect(JSON.stringify(properties)).not.toContain("88");+ });++ it("does not count a result as viewed until the app is visible", async () => {+ const restoreVisibility = setDocumentVisibility("hidden");+ try {+ mocks.listBrainViews.mockResolvedValue({+ status: "ok",+ data: [populatedView],+ });+ render(<BrainOverview />);++ await screen.findByText("How I worked today");+ expect(+ mocks.capture.mock.calls.some(+ ([event]) => event === "live_view_result_viewed",+ ),+ ).toBe(false);+ } finally {+ restoreVisibility();+ }++ fireEvent(document, new Event("visibilitychange"));+ await waitFor(() =>+ expect(mocks.capture).toHaveBeenCalledWith(+ "live_view_result_viewed",+ expect.objectContaining({ entry_method: "initial" }),+ ),+ );+ });+it("switches between named dashboards without changing either one", async () => {const weeklyView: ViewDefinition = {...populatedView,@@ -619,7 +699,7 @@ describe("BrainOverview", () => {expect(mocks.capture).toHaveBeenCalledWith("live_view_generation_started",expect.objectContaining({- analytics_schema_version: 1,+ analytics_schema_version: 2,scope: "dashboard",intent: "new-dashboard",prompt_length: "show my GTM progress this week".length,@@ -674,13 +754,15 @@ describe("BrainOverview", () => {expect(mocks.capture).toHaveBeenCalledWith("live_view_refresh_completed",expect.objectContaining({- analytics_schema_version: 1,+ analytics_schema_version: 2,trigger: "manual",status: "error",requested_block_count: 1,requested_pipe_count: 1,refreshed_block_count: 0,pipe_start_failure_count: 1,+ produced_result: false,+ all_requested_blocks_refreshed: false,}),),);@@ -1595,6 +1677,17 @@ describe("BrainOverview", () => {rating: "up",correction: null,});+ expect(mocks.capture).toHaveBeenCalledWith(+ "live_view_card_feedback",+ expect.objectContaining({+ analytics_schema_version: 2,+ action: "up",+ previous_action: "none",+ is_first_feedback: true,+ result_block_count: 1,+ is_onboarding: false,+ }),+ );fireEvent.click(screen.getByRole("button", { name: "regenerate Focus time" }),diff --git a/apps/screenpipe-app-tauri/components/settings/brain-overview.tsx b/apps/screenpipe-app-tauri/components/settings/brain-overview.tsxindex 6989671f0..7a8149897 100644--- a/apps/screenpipe-app-tauri/components/settings/brain-overview.tsx+++ b/apps/screenpipe-app-tauri/components/settings/brain-overview.tsx@@ -134,7 +134,7 @@ type PreviewDestination = "new" | "replace";const MAX_DASHBOARDS = 12;const STARTER_DASHBOARD_ID = "my-dashboard";const STARTER_DASHBOARD_TITLE = "My dashboard";-const LIVE_VIEW_ANALYTICS_SCHEMA_VERSION = 1;+const LIVE_VIEW_ANALYTICS_SCHEMA_VERSION = 2;function analyticsErrorType(error: unknown): string {return error instanceof Error ? error.name : "unknown";@@ -145,24 +145,50 @@ function liveViewAnalyticsProperties(dashboardCount: number,) {const boundSlots = targetView.slots.filter((slot) => slot.binding);+ const resultSlots = targetView.slots.filter((slot) => slot.value !== null);+ const positiveFeedbackBlockCount = targetView.slots.filter(+ (slot) => slot.feedback?.current?.rating === "up",+ ).length;+ const negativeFeedbackBlockCount = targetView.slots.filter(+ (slot) => slot.feedback?.current?.rating === "down",+ ).length;return {analytics_schema_version: LIVE_VIEW_ANALYTICS_SCHEMA_VERSION,dashboard_count: dashboardCount,block_count: targetView.slots.length,bound_block_count: boundSlots.length,- result_block_count: targetView.slots.filter((slot) => slot.value !== null)- .length,+ result_block_count: resultSlots.length,source_pipe_count: new Set(boundSlots.map((slot) => slot.binding?.pipeName).filter((name): name is string => Boolean(name)),).size,time_range: targetView.timeRange,- has_result: targetView.slots.some((slot) => slot.value !== null),+ has_result: resultSlots.length > 0,+ all_bound_blocks_have_results:+ boundSlots.length > 0 &&+ boundSlots.every((slot) => slot.value !== null),+ reviewed_block_count:+ positiveFeedbackBlockCount + negativeFeedbackBlockCount,+ positive_feedback_block_count: positiveFeedbackBlockCount,+ negative_feedback_block_count: negativeFeedbackBlockCount,is_starter_dashboard: targetView.id === STARTER_DASHBOARD_ID,};}+function liveViewResultSignature(targetView: ViewDefinition): string | null {+ const resultVersions = targetView.slots+ .flatMap((slot) =>+ slot.value+ ? [+ `${slot.id}:${slot.value.artifactOutputId}:${slot.value.artifactVersion}`,+ ]+ : [],+ )+ .sort();+ return resultVersions.length > 0 ? resultVersions.join("|") : null;+}+const COMPONENTS: Array<{value: ViewComponent;label: string;@@ -374,6 +400,10 @@ export function BrainOverview({);const activationViewedRef = useRef(new Set<string>());const lastViewedDashboardRef = useRef<string | null>(null);+ const lastViewedResultRef = useRef<{+ viewId: string;+ signature: string;+ } | null>(null);const lastRefreshOutcomeRef = useRef<number | null>(null);const refreshOnboardingActivation = useCallback(() => setActivationVersion((version) => version + 1),@@ -526,9 +556,46 @@ export function BrainOverview({...liveViewAnalyticsProperties(view, views.length),entry_method,is_onboarding: Boolean(onboardingActivation),+ onboarding_goal_category:+ onboardingActivation?.goalCategory ?? "unknown",});}, [onboardingActivation, view, views.length]);+ useEffect(() => {+ if (!view) return;+ const signature = liveViewResultSignature(view);+ if (!signature) return;++ const captureVisibleResult = () => {+ if (document.visibilityState === "hidden") return;+ const previous = lastViewedResultRef.current;+ if (+ previous?.viewId === view.id &&+ previous.signature === signature+ ) {+ return;+ }+ const entryMethod = !previous+ ? "initial"+ : previous.viewId === view.id+ ? "result_updated"+ : "selection";+ lastViewedResultRef.current = { viewId: view.id, signature };+ posthog.capture("live_view_result_viewed", {+ ...liveViewAnalyticsProperties(view, views.length),+ entry_method: entryMethod,+ is_onboarding: Boolean(onboardingActivation),+ onboarding_goal_category:+ onboardingActivation?.goalCategory ?? "unknown",+ });+ };++ captureVisibleResult();+ document.addEventListener("visibilitychange", captureVisibleResult);+ return () =>+ document.removeEventListener("visibilitychange", captureVisibleResult);+ }, [onboardingActivation, view, views.length]);+useEffect(() => {onViewCountChange?.(views.length);}, [onViewCountChange, views.length]);@@ -896,6 +963,9 @@ export function BrainOverview({requested_pipe_count: dataRefresh.pipeNames.length,refreshed_block_count: dataRefresh.filled,pipe_start_failure_count: dataRefresh.startFailureCount,+ produced_result: dataRefresh.filled > 0,+ all_requested_blocks_refreshed:+ dataRefresh.total > 0 && dataRefresh.filled === dataRefresh.total,is_onboarding: dataRefresh.trigger === "onboarding",});}, [dataRefresh]);@@ -1203,11 +1273,16 @@ export function BrainOverview({: current,);posthog.capture("live_view_card_feedback", {- analytics_schema_version: LIVE_VIEW_ANALYTICS_SCHEMA_VERSION,+ ...liveViewAnalyticsProperties(view, views.length),action: rating ?? "clear",+ previous_action: slot.feedback?.current?.rating ?? "none",+ is_first_feedback: !slot.feedback?.current,component: slot.component,has_pipe: Boolean(slot.binding),has_correction: Boolean(correction?.trim()),+ is_onboarding: Boolean(onboardingActivation),+ onboarding_goal_category:+ onboardingActivation?.goalCategory ?? "unknown",});if (rating) finishOnboardingActivation("feedback");return true;