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

eval: cover hidden search focus lifecycle

Louis Beaumont7274f29b6b1b
diff --git a/evals/coding-agent/README.md b/evals/coding-agent/README.md
index d1950ddf7..fc7aa98e4 100644
--- a/evals/coding-agent/README.md
+++ b/evals/coding-agent/README.md
@@ -9,6 +9,19 @@ This is an agent eval suite, not a unit-test suite. Every case contains:
- saved prompt, transcript, candidate patch, grader output, runtime fingerprint, and result;
- repeated-trial reporting with success rate, `pass@k`, and `pass^k`.
+`app-search-focus-lifecycle` runs the actual search page, focus hook and DOM
+listener hook with synthetic native events and a small search-view shell. Ten
+outcomes cover hidden prewarm, hide/show cycles, focus recovery, query resets,
+navigation, close and unmount. The parent fails three hidden-focus outcomes and
+preserves seven; the historical page fix and current source pass ten. Run
+`bun test evals/coding-agent/calibrate-search-focus.test.js` for twelve controls,
+including a mounted-but-inactive equivalent, unused correct code, blanket
+inactivity, ignored hide events and lost query/focus/handoff behavior. Missing
+source is a setup failure. Fixtures and runtime links appear only at grading.
+This does not execute the full search modal, native window events, macOS focus,
+real IPC, execution isolation or model trials. Current cache prewarm is checked
+separately and is allowed while the view is hidden.
+
The current app corpus contains 80 git-mined regressions. See
[DESIGN.md](./DESIGN.md) for the Anthropic guidance, source contract, and
history-mining workflow. The companion website manifest uses this same harness.
diff --git a/evals/coding-agent/calibrate-search-focus.test.js b/evals/coding-agent/calibrate-search-focus.test.js
new file mode 100644
index 000000000..8af47ea11
--- /dev/null
+++ b/evals/coding-agent/calibrate-search-focus.test.js
@@ -0,0 +1,57 @@
+// screenpipe — AI that knows everything you've seen, said, or heard
+// https://screenpipe.com
+import { afterAll, expect, test } from 'bun:test';
+import { execFileSync, spawnSync } from 'node:child_process';
+import { dirname, join, resolve } from 'node:path';
+import { mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+const repo = resolve(import.meta.dir, '../..'), app = 'apps/screenpipe-app-tauri';
+const item = JSON.parse(readFileSync(join(import.meta.dir, 'cases.json'), 'utf8')).cases.find(c => c.id === 'app-search-focus-lifecycle');
+const hook = `${app}/app/search/page.tsx`;
+const root = mkdtempSync(join(tmpdir(), 'search-focus-calibration-')), archives = new Map();
+const receipts = process.env.SCREENPIPE_EVAL_CALIBRATION_RECEIPTS;
+afterAll(() => rmSync(root, {recursive: true, force: true}));
+function replace(cwd, file, from, to) {
+ const p = join(cwd, file), text = readFileSync(p, 'utf8');
+ expect(text.split(from)).toHaveLength(2);
+ writeFileSync(p, text.replace(from, to));
+}
+function grade(name, ref = item.oracle_ref, mutate = () => {}) {
+ const cwd = join(root, name); mkdirSync(cwd);
+ if (!archives.has(ref)) {
+ // Archive historical frontend source/config, never node_modules, credentials,
+ // native build outputs or future source. No evaluated agent runs here.
+ const children = execFileSync('git', ['ls-tree', '--name-only', `${ref}:${app}`], {cwd: repo, encoding: 'utf8'}).trim().split('\n');
+ const paths = children.filter(n => !['src-tauri', 'public', 'e2e', '.e2e'].includes(n) && !n.startsWith('.env')).map(n => `${app}/${n}`);
+ for (const path of ['packages/workflows-ui', 'crates/screenpipe-core/assets']) { if (execFileSync('git', ['ls-tree', ref, path], {cwd:repo, encoding:'utf8'}).trim()) paths.push(path); }
+ archives.set(ref, execFileSync('git', ['archive', ref, ...paths], {cwd: repo, maxBuffer: 128 * 1024 * 1024}));
+ }
+ execFileSync('tar', ['-x', '-C', cwd], {input: archives.get(ref)});
+ for (const f of item.grader.fixtures) { const dest = join(cwd, f.destination_path); mkdirSync(dirname(dest), {recursive:true}); writeFileSync(dest, readFileSync(join(import.meta.dir, f.local_path))); }
+ symlinkSync(join(repo, app, 'node_modules'), join(cwd, app, 'node_modules'), 'dir');
+ mutate(cwd);
+ const r = spawnSync('/bin/bash', ['-c', item.grader.command], {cwd, encoding:'utf8', timeout:60000, maxBuffer:4*1024*1024, env:{PATH:process.env.PATH, HOME:cwd, CI:'true', TZ:'UTC', NO_COLOR:'1'}});
+ if (receipts) { mkdirSync(receipts,{recursive:true}); writeFileSync(join(receipts, name+'.stdout'), r.stdout||''); writeFileSync(join(receipts,name+'.stderr'),r.stderr||''); writeFileSync(join(receipts,name+'.json'),JSON.stringify({ref,command:item.grader.command,exit_code:r.status,signal:r.signal,error:r.error?.message},null,2)); }
+ expect(r.error).toBeUndefined(); expect(r.signal).toBeNull(); return r;
+}
+function passes(r) { expect(r.status).toBe(0); expect(r.stdout).toContain('10 passed'); expect(r.stdout+r.stderr).not.toMatch(/Unhandled|Uncaught/); }
+function fails(r) { expect(r.status).toBe(1); expect(r.stderr).toMatch(/AssertionError|TestingLibraryElementError|Error: expect\(element\)\.toHaveFocus\(\)/); expect(r.stdout+r.stderr).not.toMatch(/Unhandled|Uncaught|Failed to resolve import|Failed to load url|Cannot find module/); }
+test('parent fails three hidden-focus outcomes and preserves seven',()=>{const r=grade('parent',item.base_ref);fails(r);expect(r.stdout).toContain('3 failed | 7 passed');},60000);
+test('historical reference passes ten outcomes',()=>passes(grade('reference')),60000);
+test('current page and focus hook pass ten outcomes',()=>passes(grade('current','HEAD')),60000);
+test('keeping the child mounted but inactive is an equivalent solution',()=>passes(grade('equivalent',item.oracle_ref,cwd=>{
+ replace(cwd,hook,'{isSearchActive && (\n\t\t\t\t<SearchModal','<SearchModal');
+ replace(cwd,hook,'\t\t\t\t\tisOpen\n','\t\t\t\t\tisOpen={isSearchActive}\n');
+ replace(cwd,hook,'\n\t\t\t)}','');
+})),60000);
+test('unused correct page cannot hide the broken imported page',()=>fails(grade('unused',item.oracle_ref,cwd=>{
+ writeFileSync(join(cwd,`${app}/unused-correct-search.tsx`),readFileSync(join(cwd,hook)));
+ writeFileSync(join(cwd,hook),execFileSync('git',['show',`${item.base_ref}:${hook}`],{cwd:repo}));
+})),60000);
+test('blanket inactivity fails normal visible behavior',()=>fails(grade('always-hidden',item.oracle_ref,cwd=>replace(cwd,hook,'{isSearchActive && (','{false && ('))),60000);
+test('ignoring hidden notification leaves active focus work',()=>fails(grade('no-hide',item.oracle_ref,cwd=>replace(cwd,hook,'listen("search-hidden",','listen("unused-hidden",'))),60000);
+test('discarding reset queries fails preserved search context',()=>fails(grade('no-query',item.oracle_ref,cwd=>replace(cwd,hook,'const q = event.payload?.query ?? "";','const q = "";'))),60000);
+test('suppressing close fails native handoff',()=>fails(grade('no-close',item.oracle_ref,cwd=>replace(cwd,hook,'onClose={handleClose}','onClose={() => {}}'))),60000);
+test('suppressing navigation fails result handoff',()=>fails(grade('no-navigate',item.oracle_ref,cwd=>replace(cwd,hook,'onNavigateToTimestamp={handleNavigate}','onNavigateToTimestamp={() => {}}'))),60000);
+test('suppressing the real focus watchdog fails visible recovery',()=>fails(grade('no-focus-guard',item.oracle_ref,cwd=>replace(cwd,`${app}/components/rewind/hooks/use-search-focus.ts`,'const interval = setInterval(() => focusInput(), 500);','const interval = setInterval(() => {}, 500);'))),60000);
+test('missing active page is setup failure, not regression evidence',()=>{const r=grade('missing',item.oracle_ref,cwd=>rmSync(join(cwd,hook)));expect(r.status).toBe(1);expect(r.stdout).toContain('no tests');expect(r.stdout+r.stderr).toMatch(/Failed to resolve import|Failed to load url/);},60000);
diff --git a/evals/coding-agent/cases.json b/evals/coding-agent/cases.json
index 17ae8d4c4..baeb4edd9 100644
--- a/evals/coding-agent/cases.json
+++ b/evals/coding-agent/cases.json
@@ -4714,6 +4714,50 @@
],
"command": "\"${BUN_BIN:-bun}\" test evals/coding-agent/graders/gateway-auth-log-privacy.test.js"
}
+ },
+ {
+ "id": "app-search-focus-lifecycle",
+ "name": "Suspend hidden search focus work and preserve reopening",
+ "source": {
+ "kind": "git_regression",
+ "fix_commit": "27fef88bae7c56bb6bce58e98d8b97c28d7f7aac"
+ },
+ "base_ref": "073c54cba78b42719b909733fe151083baff3fed",
+ "oracle_ref": "27fef88bae7c56bb6bce58e98d8b97c28d7f7aac",
+ "oracle_paths": [
+ "apps/screenpipe-app-tauri/app/search/page.tsx"
+ ],
+ "gate": "advisory",
+ "trigger_paths": [
+ "apps/screenpipe-app-tauri/app/search/page.tsx",
+ "apps/screenpipe-app-tauri/components/rewind/hooks/use-search-focus.ts",
+ "apps/screenpipe-app-tauri/lib/hooks/use-event-listener.ts"
+ ],
+ "tags": [
+ "regression",
+ "escaped-failure",
+ "search",
+ "lifecycle",
+ "focus"
+ ],
+ "prompt": "The retained search webview keeps reclaiming input focus while hidden. Fix the React search-page lifecycle: a page opened at /search?prewarm=1 must remain inactive until the native search-reset event; search-hidden must suspend focus work, even before the first show. An ordinary /search open must still focus the input and recover focus from a non-input element while visible. Reopening after hiding must restore usable focus and the supplied query, including Unicode and URL-special characters; a null or absent reset query clears the old query. Preserve result navigation with its timestamp, frame ID and search context, explicit native window-close handoff, and removal of listeners and focus work on unmount. Preserve public component/hook interfaces and any intentional recent-chat cache warming. This task covers the actual page and focus hook with synthetic native events and a small search-view shell, not native window-server execution or the full search-results UI. No particular mount strategy or private helper is prescribed.",
+ "agent_timeout_seconds": 900,
+ "grader_dependency_links": [
+ {
+ "source_path": "apps/screenpipe-app-tauri/node_modules",
+ "destination_path": "apps/screenpipe-app-tauri/node_modules"
+ }
+ ],
+ "grader": {
+ "timeout_seconds": 60,
+ "fixtures": [
+ {
+ "local_path": "graders/search-focus-lifecycle.fixture.tsx.txt",
+ "destination_path": "apps/screenpipe-app-tauri/eval-search-lifecycle.test.tsx"
+ }
+ ],
+ "command": "cd apps/screenpipe-app-tauri && node node_modules/vitest/vitest.mjs run --config vitest.config.ts eval-search-lifecycle.test.tsx"
+ }
}
]
}
diff --git a/evals/coding-agent/graders/search-focus-lifecycle.fixture.tsx.txt b/evals/coding-agent/graders/search-focus-lifecycle.fixture.tsx.txt
new file mode 100644
index 000000000..86acc83af
--- /dev/null
+++ b/evals/coding-agent/graders/search-focus-lifecycle.fixture.tsx.txt
@@ -0,0 +1,79 @@
+// screenpipe — AI that knows everything you've seen, said, or heard
+// https://screenpipe.com
+import React from 'react';
+import { act, cleanup, fireEvent, render, screen } from '@testing-library/react';
+import { afterEach, beforeEach, expect, it, vi } from 'vitest';
+const ports = vi.hoisted(() => ({
+ events: new Map<string, Set<(e: {payload: any}) => void>>(),
+ close: vi.fn(async () => undefined), navigate: vi.fn(async () => undefined),
+ prefetch: vi.fn(async () => undefined), clear: vi.fn(), invalidate: vi.fn(),
+}));
+vi.mock('@tauri-apps/api/event', () => ({
+ emit: vi.fn(async () => undefined),
+ listen: vi.fn(async (name: string, callback: (e: {payload: any}) => void) => {
+ const set = ports.events.get(name) || new Set(); set.add(callback); ports.events.set(name,set);
+ return () => { set.delete(callback); if (!set.size) ports.events.delete(name); };
+ }),
+}));
+vi.mock('@/lib/utils/tauri', () => ({commands: {closeWindow: ports.close, searchNavigateToTimeline: ports.navigate}}));
+vi.mock('@/lib/chat-utils', () => ({RECENT_CHAT_SEARCH_HANDOFF_EVENT: 'recent-chat-search-handoff', readSearchOpenedFromChatSurface: () => null}));
+vi.mock('@/lib/chat-storage', () => ({prefetchRecentChats: ports.prefetch, clearRecentChatsCache: ports.clear, invalidateConversationListCache: ports.invalidate}));
+vi.mock('@/lib/experimental-features', () => ({useExperimentalFeaturesEnabled: () => false}));
+vi.mock('@/components/rewind/search-modal', async () => {
+ const { useSearchFocus } = await import('@/components/rewind/hooks/use-search-focus');
+ return { SearchModal: (props: any) => {
+ const {inputRef} = useSearchFocus(props.isOpen);
+ if (!props.isOpen) return null;
+ return <div><input aria-label="Search fixture" ref={inputRef}/>
+ <button onClick={() => props.onClose()}>Close search</button>
+ <button onClick={() => props.onNavigateToTimestamp('2026-01-01T00:00:00Z', 7, ['synthetic'], '[]', 'sample')}>Open result</button>
+ </div>;
+ }};
+});
+import SearchPage from './app/search/page';
+let focus: ReturnType<typeof vi.spyOn>;
+beforeEach(() => {
+ vi.useFakeTimers(); vi.clearAllMocks(); ports.events.clear();
+ window.history.replaceState(null,'','/search?prewarm=1');
+ focus=vi.spyOn(HTMLElement.prototype,'focus');
+});
+afterEach(async () => {cleanup(); await act(async () => {}); document.body.replaceChildren(); vi.clearAllTimers(); vi.useRealTimers(); vi.restoreAllMocks();});
+async function event(name: string, payload: any = undefined) { await act(async () => { for(const f of ports.events.get(name)||[]) f({payload}); }); }
+async function tick() { await act(async () => {vi.advanceTimersByTime(2100);}); }
+function moveFocusAway() { const button=document.createElement('button');document.body.append(button);button.focus();focus.mockClear();return button; }
+it('hidden prewarm never focuses or runs the active focus guard', async () => {
+ render(<SearchPage/>);await tick();expect(focus).not.toHaveBeenCalled();
+});
+it('hiding an opened view stops periodic focus reclamation', async () => {
+ render(<SearchPage/>);await event('search-reset',{query:'first'});expect(screen.getByLabelText('Search fixture')).toHaveFocus();
+ await event('search-hidden');const other=moveFocusAway();await tick();expect(focus).not.toHaveBeenCalled();expect(other).toHaveFocus();other.remove();
+});
+it('a hide before first show leaves the prewarm inactive', async () => {
+ render(<SearchPage/>);await event('search-hidden');focus.mockClear();const other=moveFocusAway();await tick();expect(focus).not.toHaveBeenCalled();other.remove();
+});
+it('normal visible open activates real input focus', async () => {
+ window.history.replaceState(null,'','/search');render(<SearchPage/>);await tick();expect(screen.getByLabelText('Search fixture')).toHaveFocus();
+});
+it('visible focus guard still recovers focus from a non-input element', async () => {
+ window.history.replaceState(null,'','/search');render(<SearchPage/>);const other=moveFocusAway();await tick();expect(screen.getByLabelText('Search fixture')).toHaveFocus();other.remove();
+});
+it('reopening after hide restores focus and a fresh encoded query', async () => {
+ render(<SearchPage/>);await event('search-reset',{query:'first'});await event('search-hidden');await event('search-reset',{query:'a & b/雪'});await tick();
+ expect(screen.getByLabelText('Search fixture')).toHaveFocus();expect(new URLSearchParams(window.location.search).get('q')).toBe('a & b/雪');expect(new URLSearchParams(window.location.search).has('prewarm')).toBe(false);
+});
+it('empty reset clears the prior query while keeping the view usable', async () => {
+ render(<SearchPage/>);await event('search-reset',{query:'old'});await event('search-reset',{query:null});
+ expect(new URLSearchParams(window.location.search).get('q')).toBeNull();expect(screen.getByLabelText('Search fixture')).toHaveFocus();
+});
+it('result navigation preserves timestamp, frame and search context', async () => {
+ render(<SearchPage/>);await event('search-reset',{query:'sample'});fireEvent.click(screen.getByText('Open result'));await act(async()=>{});
+ expect(ports.navigate).toHaveBeenCalledTimes(1);expect(ports.navigate.mock.calls[0].slice(0,5)).toEqual(['2026-01-01T00:00:00Z',7,['synthetic'],'[]','sample']);
+});
+it('explicit close preserves the native close handoff', async () => {
+ render(<SearchPage/>);await event('search-reset');fireEvent.click(screen.getByText('Close search'));await act(async()=>{});
+ expect(ports.close).toHaveBeenCalledWith({Search:{query:null}});
+});
+it('unmount removes subscriptions and focus activity', async () => {
+ const view=render(<SearchPage/>);await event('search-reset');view.unmount();await act(async()=>{});focus.mockClear();await tick();
+ expect(ports.events.size).toBe(0);expect(focus).not.toHaveBeenCalled();
+});