Skip to content

HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.

console: a window narrowed to a phone's width keeps the task it had open (#586)

jju1sedca78bffa40
diff --git a/ui/src/app/(app)/studio/[id]/page.test.tsx b/ui/src/app/(app)/studio/[id]/page.test.tsx
new file mode 100644
index 00000000..b582811c
--- /dev/null
+++ b/ui/src/app/(app)/studio/[id]/page.test.tsx
@@ -0,0 +1,163 @@
+/** @jest-environment jsdom */
+// A setup's Tasks at every width: on a wide window the open task sits beside the list, and at 860 px
+// and below the two take turns (hrui.css). A window narrowed from desktop width keeps the task it had
+// open, whether it was picked from the list, opened by itself as the newest, or gone back to from
+// Settings; a page that opens at a phone's width starts on the list, as before (#576).
+import { act, createContext } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import type { TraceCard } from '@/lib/revamp-data';
+
+// the address: what useSearchParams reads, and what the page's router.replace writes
+let search = '';
+const replace = jest.fn((href: string) => { search = href.includes('?') ? href.slice(href.indexOf('?') + 1) : ''; });
+jest.mock('next/navigation', () => ({
+ useParams: () => ({ id: 'h1' }),
+ useRouter: () => ({ replace, push: jest.fn() }),
+ useSearchParams: () => new URLSearchParams(search),
+}));
+
+const card = (sid: string, title: string, at: number): TraceCard => ({ session_id: sid, title, status: 'completed', finished_at: at } as TraceCard);
+const CARDS = [card('t2', 'The newest task', 2000), card('t1', 'An older task', 1000)];
+const mockList = {
+ all: CARDS, byId: new Map(CARDS.map((c) => [c.session_id, c])), ready: true, failed: false, stale: false,
+ more: false, reading: false, paused: false, pending: [],
+ older: () => {}, refresh: () => {}, reconnect: () => {}, drop: () => {}, add: () => {},
+};
+jest.mock('@/components/hrui/setups', () => ({
+ useSetup: () => ({
+ row: { h: { id: 'h1', name: 'My setup', source: '', createdAt: 1 }, binding: null },
+ cards: [], missing: false, failed: false, reload: () => {},
+ }),
+}));
+jest.mock('@/components/hrui/setup/TaskRail', () => {
+ const actual = jest.requireActual('@/components/hrui/setup/TaskRail');
+ return {
+ filterTasks: actual.filterTasks, NO_FILTER: actual.NO_FILTER,
+ useTaskList: () => mockList,
+ useLinkedTask: () => ({ failed: false, retry: () => {} }),
+ TaskList: ({ onOpen }: { onOpen: (sid: string) => void }) => (
+ <div className="tk-l">{CARDS.map((c) => <button key={c.session_id} type="button" id={`row-${c.session_id}`} onClick={() => onOpen(c.session_id)}>{c.title}</button>)}</div>
+ ),
+ };
+});
+jest.mock('@/components/hrui/setup/parts', () => ({
+ useMedia: jest.requireActual('@/components/hrui/setup/parts').useMedia,
+ useSideOff: () => [false, () => {}],
+ AgentHead: ({ onTab }: { onTab: (t: 'tasks' | 'settings') => void }) => (
+ <header><button type="button" id="tab-tasks" onClick={() => onTab('tasks')}>Tasks</button>
+ <button type="button" id="tab-settings" onClick={() => onTab('settings')}>Settings</button></header>
+ ),
+ StackPanel: () => null,
+}));
+jest.mock('@/components/hrui/setup/Playground', () => ({ Playground: () => null }));
+jest.mock('@/components/hrui/setup/SetupSettings', () => ({ SetupSettings: () => <div id="settings" /> }));
+jest.mock('@/components/hrui/setup/settingsModel', () => ({ hasSettingsDraft: () => false, layerOf: () => undefined, useBrickNav: () => {} }));
+jest.mock('@/components/hrui/SetUpApp', () => ({ SetUpApp: () => null }));
+jest.mock('@/components/hrui/Skel', () => ({ Skel: () => null, SkLine: () => null, SkRows: () => null, SkThread: () => null }));
+jest.mock('@/components/hrui/setup/TaskDetail', () => ({
+ TaskHead: ({ card: c }: { card: TraceCard }) => <h1 id="task-title">{c.title}</h1>,
+ RecordedHead: () => null, NewTaskHead: () => null,
+}));
+jest.mock('@/components/hrui/setup/TurnFiles', () => ({ FilesPanel: () => null }));
+jest.mock('@/components/hrui/setup/PreviewGrip', () => ({ PreviewGrip: () => null, usePreviewWidth: () => ({ width: 480 }) }));
+jest.mock('@/components/hrui/setup/BrowserSlot', () => ({
+ BrowserControl: () => null, BrowserSlot: () => null, browserStepsOf: () => [], stepOf: () => null,
+ useTaskBrowser: () => ({ pane: { open: false }, live: undefined, step: null, show: () => {}, close: () => {} }),
+}));
+jest.mock('@/components/hrui/setup/AgentTurns', () => ({ TurnSteps: createContext(null) }));
+jest.mock('@/lib/conversation', () => ({ getPaneState: () => ({ open: false }), setPaneState: () => {}, useConvState: () => ({ msgs: [] }) }));
+jest.mock('@/components/hrui/start/check', () => ({ takeFirstTest: () => null }));
+jest.mock('@/components/hrui/start/build', () => ({ useBuildOf: () => null }));
+jest.mock('@/components/hrui/start/seed', () => ({ seededSetup: () => null }));
+jest.mock('@/components/hrui/start/buildStack', () => ({ useBuildStack: () => ({ r: null, now: null, drops: null }) }));
+jest.mock('@/components/hrui/start/replay', () => ({ useRecordedRunState: () => ({ run: null, failed: false, retry: () => {} }) }));
+jest.mock('@/components/hrui/toast', () => ({ toast: jest.fn() }));
+
+import SetupPage from './page';
+
+Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
+
+// a window whose width the test sets: every (max-width: N px) query answers it, and hears a change
+// only when its answer flips, as a browser's does
+let width = 1440;
+const queries: { q: string; max: number; on: Set<() => void>; was: boolean }[] = [];
+function matchMedia(q: string) {
+ const max = Number(/max-width:\s*(\d+)px/.exec(q)?.[1] ?? Infinity);
+ const entry = { q, max, on: new Set<() => void>(), was: width <= max };
+ queries.push(entry);
+ return {
+ get matches() { return width <= max; }, media: q,
+ addEventListener: (_: string, fn: () => void) => entry.on.add(fn),
+ removeEventListener: (_: string, fn: () => void) => entry.on.delete(fn),
+ };
+}
+async function resize(w: number) {
+ width = w;
+ await act(async () => {
+ for (const e of queries) {
+ const now = width <= e.max;
+ if (now !== e.was) { e.was = now; e.on.forEach((fn) => fn()); }
+ }
+ });
+}
+
+let root: Root;
+let el: HTMLElement;
+const split = () => el.querySelector('.tk-split') as HTMLElement;
+/** what a phone-width window shows: the open task, or the list (the 860 px rule is `.show-d`) */
+const narrowShows = () => (split().classList.contains('show-d') ? 'task' : 'list');
+async function open(at: number, address = '') {
+ width = at; search = address;
+ await act(async () => { root.render(<SetupPage />); });
+ for (let i = 0; i < 4; i++) await act(async () => { await Promise.resolve(); });
+}
+const rerender = async () => { await act(async () => { root.render(<SetupPage />); }); };
+const click = async (id: string) => { await act(async () => { (document.getElementById(id) as HTMLButtonElement).click(); }); await rerender(); };
+
+beforeEach(() => {
+ queries.length = 0; replace.mockClear();
+ window.matchMedia = matchMedia as unknown as typeof window.matchMedia;
+ el = document.createElement('div'); document.body.appendChild(el);
+ root = createRoot(el);
+});
+afterEach(() => { act(() => root.unmount()); el.remove(); });
+
+test('the newest task, opened by itself at desktop width, stays open as the window narrows to a phone’s', async () => {
+ await open(1440);
+ expect(document.getElementById('task-title')?.textContent).toBe('The newest task');
+ await resize(1024);
+ expect(narrowShows()).toBe('list'); // 1024 px is above the phone rule: both still show, nothing flips yet
+ await resize(768);
+ expect(narrowShows()).toBe('task');
+ await resize(390);
+ expect(narrowShows()).toBe('task');
+ expect(document.getElementById('task-title')?.textContent).toBe('The newest task');
+});
+
+test('the task Settings went back to, named in the address, stays open as the window narrows', async () => {
+ await open(1440, 'test=t1');
+ await click('tab-settings');
+ await click('tab-tasks');
+ expect(search).toBe('test=t1');
+ expect(document.getElementById('task-title')?.textContent).toBe('An older task');
+ await resize(768);
+ expect(narrowShows()).toBe('task');
+ expect(document.getElementById('task-title')?.textContent).toBe('An older task');
+});
+
+test('a task picked from the list stays open as the window narrows, as it always did', async () => {
+ await open(1440);
+ await click('row-t1');
+ await resize(390);
+ expect(narrowShows()).toBe('task');
+ expect(document.getElementById('task-title')?.textContent).toBe('An older task');
+});
+
+test('a page opened at a phone’s width starts on the list, and only a pick opens a task', async () => {
+ await open(390);
+ expect(narrowShows()).toBe('list');
+ await resize(375);
+ expect(narrowShows()).toBe('list');
+ await click('row-t2');
+ expect(narrowShows()).toBe('task');
+});
diff --git a/ui/src/app/(app)/studio/[id]/page.tsx b/ui/src/app/(app)/studio/[id]/page.tsx
index 6a53e694..45ba3656 100644
--- a/ui/src/app/(app)/studio/[id]/page.tsx
+++ b/ui/src/app/(app)/studio/[id]/page.tsx
@@ -11,7 +11,8 @@
// task, or on its recorded first task when it was saved from a demo's recorded run, start/replay.ts,
// drawn whole; a recording that could not be read is said, with Try again, never swapped for a live
// task). The open task is always one the list shows: filtering to Failed opens a failed one. On a
-// phone the list and the open task take turns, with a back between. The address carries the tab
+// phone the list and the open task take turns, with a back between; a wider window narrowed to a
+// phone's width keeps the task it had open. The address carries the tab
// (?tab=settings), Settings' open layer (?layer=), Capabilities' tab (?cap=) and a task opened by its
// link or sent from here (?test=); an older link to the Tasks tab (?tab=tasks&task=) opens that task
// here.
@@ -40,6 +41,8 @@ import { useRecordedRunState } from '@/components/hrui/start/replay';
import { toast } from '@/components/hrui/toast';
const enc = encodeURIComponent;
+// at and below this width the list and the open task take turns (hrui.css: the 860 px rules)
+const PHONE_MAX = 860;
export default function SetupPage() {
const { id } = useParams<{ id: string }>();
@@ -71,6 +74,18 @@ export default function SetupPage() {
const [testSid, setTestSid] = useState<string | null>(() => params.get('test') || linkTask);
// on a phone: the open task shows instead of the list (picked from it, New task, or a link)
const [picked, setPicked] = useState(() => !!(params.get('test') || linkTask || first));
+ // a wide window shows the open task beside the list whether or not it was picked from it (the newest
+ // one, opened by itself; the one Settings went back to), so a window narrowed into the phone layout
+ // keeps that task instead of switching to the list. A window already that narrow as the page opens
+ // is a phone's, and starts on the list as before
+ const slotOpen = !!slot;
+ useEffect(() => {
+ if (!slotOpen) return;
+ const mq = window.matchMedia(`(max-width: ${PHONE_MAX}px)`);
+ const narrowed = () => { if (mq.matches) setPicked(true); };
+ mq.addEventListener('change', narrowed);
+ return () => mq.removeEventListener('change', narrowed);
+ }, [slotOpen]);
// when the task shown was opened: a new test's own entry in the list is one sent after it
const slotAt = useRef(0);
useEffect(() => { slotAt.current = Date.now(); }, [slot?.key]);