Skip to content
4 changes: 3 additions & 1 deletion src/web-ui/AGENTS-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

Peer Device Mode(同账号远程完整客户端)的边界见 `docs/architecture/peer-device-mode.md`。
前端不变量见 `src/infrastructure/peer-device/README.md`。不要重新引入内嵌会话/聊天壳;
应从设备列表(Remote Connect 的「我的 OpenBitFun」组)进入 peer mode。
从侧边栏对应设备的分区打开工作区或会话。Remote Connect 的账号设备列表只管理
显示状态、别名和移除设备,点击设备行不切换当前设备。拖动顺序只保存在控制端本机,
由账号列表、侧边栏分区和设备预览轮播共用;重命名、在线状态变化和远控切换不改变设备 ID。

Remote Connect 使用共享 OpenBitFun 账号(GitHub 或邮箱验证码登录)和官方版本化 Relay。账户控件复用 account-identity
服务,不再提供独立 Relay 账户、自定义服务器或自建部署入口。SSH 与 Docker 远程工作区
Expand Down
23 changes: 18 additions & 5 deletions src/web-ui/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ Most changes start in:
Peer Device Mode (same-account remote full client) is documented in
`docs/architecture/peer-device-mode.md`. Frontend invariants:
`src/infrastructure/peer-device/README.md`. Do not reintroduce nested
sessions/chat shells; enter peer mode from the device list (Remote Connect →
My OpenBitFun) instead.
sessions/chat shells; open a device’s workspace or session from its sidebar section.
Remote Connect’s account device list manages visibility, aliases, and removal;
its rows do not switch the rendered device. Device order is a controller-local
preference shared by this list, sidebar sections, and the device preview carousel;
keep device IDs stable through renames, presence changes, and Peer switches.

Remote Connect uses the shared OpenBitFun account (GitHub or email-code sign-in)
and the official versioned Relay.
Expand Down Expand Up @@ -412,17 +415,27 @@ pnpm --dir src/web-ui run test:run src/app/components/panels/content-canvas/edit

These local DOM/store fixtures do not establish native rendering or live remote behavior.

For device preview motion, linked sidebar visibility controls, and controller-owned theme selection:
For device preview motion, linked sidebar visibility and ordering, and controller-owned theme selection:

```bash
pnpm --dir src/web-ui run test:run src/app/components/NavPanel/components/DeviceStatusControl.test.tsx src/app/components/NavPanel/sections/devices/DeviceWorkspaceSections.test.tsx src/app/components/RemoteConnectDialog/AccountPanel.test.tsx src/app/navigation/deviceVisibilityPreferences.test.ts src/infrastructure/appearance/runtime/AppearanceService.test.ts
pnpm --dir src/web-ui run test:run src/app/components/NavPanel/components/DeviceStatusControl.test.tsx src/app/components/NavPanel/sections/devices/DeviceWorkspaceSections.test.tsx src/app/components/RemoteConnectDialog/AccountPanel.test.tsx src/app/navigation/deviceVisibilityPreferences.test.ts src/app/navigation/deviceOrderPreferences.test.ts src/app/components/NavPanel/sections/devices/useSidebarDevices.test.tsx src/infrastructure/appearance/runtime/AppearanceService.test.ts
```

These DOM/store and transport fixtures cover interrupted motion, reduced motion,
legacy preference loading, visibility across device activation, and local theme
legacy preference loading, drag ordering, visibility across device activation, and local theme
reads/writes during simulated Peer switches. They do not establish native
WebView frame rate or live SSH, Remote Control, Peer Device or Detached Dispatch behavior.

For cross-device session prewarm, native event routing and subscription handover:

```bash
pnpm --dir src/web-ui run test:run src/flow_chat/services/RelaySessionHistory.test.ts src/flow_chat/services/RelaySessionHistory.routing.test.ts src/infrastructure/api/service-api/RemoteConnectAPI.test.ts src/infrastructure/api/adapters/tauri-adapter.test.ts src/infrastructure/peer-device/deviceSurfaceRouting.test.ts
```

These fixtures route tagged native events before and after a simulated Peer
activation, including same-ID sessions on other devices and cached replay.
They do not establish live Relay reconnect or remote-host performance.

For workspace icon editing, host capability gates, persistence requests and device-switch fences:

```bash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '../deviceInterconnectionOverview';
import { getDeviceArtworkKind } from './deviceArtworkKind';
import DeviceStatusControl from './DeviceStatusControl';
import { useDeviceOrderPreferences } from '@/app/navigation/deviceOrderPreferences';
import { useDeviceVisibilityPreferences } from '@/app/navigation/deviceVisibilityPreferences';

const state = vi.hoisted(() => ({
Expand Down Expand Up @@ -172,6 +173,7 @@ function installMotionPreference(initial = false) {
}

async function renderBrowseableDevices() {
useDeviceOrderPreferences.setState({ order: ['local', 'peer-1', 'peer-2', 'peer-3'] });
state.overview = overview({ peer: { deviceId: 'peer-1', deviceName: 'Current host' } });
state.identity = { status: 'signed-in', me: { user: { accountId: 'acct' } } };
state.getDeviceInfo.mockResolvedValue({ device_id: 'local', device_name: 'This computer' });
Expand All @@ -191,6 +193,7 @@ async function renderBrowseableDevices() {
beforeEach(() => {
vi.clearAllMocks();
useDeviceVisibilityPreferences.setState({ hidden: {} });
useDeviceOrderPreferences.setState({ order: [] });
state.disconnectDevice.mockReset().mockResolvedValue(undefined);
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
state.identity = { status: 'signed-out', me: null };
Expand Down Expand Up @@ -397,6 +400,7 @@ describe('device status card', () => {
});

it('opens on the current peer without sliding when the directory arrives, including after browsing and reopening', async () => {
useDeviceOrderPreferences.setState({ order: ['local', 'peer-1', 'peer-2'] });
state.overview = overview({ peer: { deviceId: 'peer-1', deviceName: 'Current host' } });
state.identity = { status: 'signed-in', me: { user: { accountId: 'acct' } } };
state.getDeviceInfo.mockResolvedValue({ device_id: 'local', device_name: 'This computer' });
Expand Down Expand Up @@ -985,3 +989,32 @@ describe('device status card', () => {
expect(state.switchToDevice).not.toHaveBeenCalled();
});
});


it('updates preview ordering immediately from the controller preference without switching the displayed host', async () => {
const { next } = await renderBrowseableDevices();
expect(element('nav-device-status-name').textContent).toBe('Current host');
act(() => useDeviceOrderPreferences.getState().move('peer-3', 'peer-1', 'after', ['local', 'peer-1', 'peer-2', 'peer-3']));
expect(element('nav-device-status-name').textContent).toBe('Current host');
await act(async () => next.click());
expect(element('nav-device-status-name').textContent).toBe('Third host');
expect(element('nav-device-status-pagination').textContent).toBe('3 / 4');
expect(state.switchToDevice).not.toHaveBeenCalled();
expect(state.switchToLocal).not.toHaveBeenCalled();
});


it('preserves a missing live peer in its saved position and removes it when the window leaves that peer', async () => {
useDeviceOrderPreferences.setState({ order: ['local', 'peer-1'] });
state.overview = overview({ peer: { deviceId: 'peer-1', deviceName: 'Current host' } });
state.identity = { status: 'signed-in', me: { user: { accountId: 'acct' } } };
state.getDeviceInfo.mockResolvedValue({ device_id: 'local', device_name: 'This computer' });
state.accountListDevices.mockResolvedValue([{ device_id: 'local', device_name: 'This computer', online: true }]);
await act(async () => { render(); });
expect(element('nav-device-status-name').textContent).toBe('Current host');
expect(element('nav-device-status-pagination').textContent).toBe('2 / 2');
state.overview = overview();
await act(async () => { render(); });
expect(document.querySelector('[data-testid="nav-device-status-pagination"]')).toBeNull();
expect(state.switchToDevice).not.toHaveBeenCalled();
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { applyDeviceOrder, sortAccountDevices, useDeviceOrderPreferences } from '@/app/navigation/deviceOrderPreferences';
import { useDeviceDirectory, resolveDeviceName, isDeviceControllable, deviceClientVersion, refreshDeviceDirectory } from '@/infrastructure/account/deviceDirectory';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { subscribeOverlayInteraction, createOverlayPortal, OverflowText, Button, Card, CardBody, CardHeader, Icon, IconButton, Input, ScrollArea, type IconSize } from '@openbitfun/ui';
Expand Down Expand Up @@ -103,6 +104,7 @@ const DeviceStatusControl: React.FC<DeviceStatusControlProps> = ({
onManageDevices,
}) => {
useDeviceDirectory();
const deviceOrder = useDeviceOrderPreferences(state => state.order);
const { t, formatNumber } = useI18n('common');
const { warning, error: notifyError } = useNotification();
const peerContext = usePeerDeviceModeOptional();
Expand Down Expand Up @@ -148,11 +150,14 @@ const DeviceStatusControl: React.FC<DeviceStatusControlProps> = ({
}, [accountId, open, warning]);

const availableTargets = switchTargets?.accountId === accountId ? switchTargets : null;
const carouselDeviceIds = availableTargets?.devices.map(device => device.device_id) ?? [];
// Presence can lag behind a live control link; keep its disconnect entry reachable.
if (availableTargets && activePeerId && !carouselDeviceIds.includes(activePeerId)) {
carouselDeviceIds.unshift(activePeerId);
}
const carouselDeviceIds = useMemo(() => {
if (!availableTargets) return [];
const ids = sortAccountDevices(availableTargets.devices, availableTargets.localId, []).map(device => device.device_id);
// Presence can lag behind a live link. Retain that peer, in its saved
// position, only for as long as it remains the rendered device.
if (activePeerId && !ids.includes(activePeerId)) ids.unshift(activePeerId);
return applyDeviceOrder(ids, deviceOrder, id => id);
}, [availableTargets, activePeerId, deviceOrder]);
const currentId = peerContext?.peerMode.active ? peerContext.peerMode.deviceId : availableTargets?.localId;
const previewTarget = availableTargets?.devices.find(device => device.device_id === previewId);
const platformHint = typeof navigator === 'undefined'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export function DeviceVisibilityButton({ surfaceId, name, compact = false, disab
icon={<Icon glyph={visible ? Eye : EyeOff} size={compact ? 'xs' : 'md'} />}
aria-label={label}
aria-pressed={visible}
title={label}
disabled={disabled}
data-testid="device-sidebar-visibility"
data-device-surface={surfaceId}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// @vitest-environment jsdom
import React, { act } from 'react';
import { createRoot } from 'react-dom/client';
import { expect, it, vi } from 'vitest';
import { useSidebarDevices } from './useSidebarDevices';
import { useDeviceDirectory } from '@/infrastructure/account/deviceDirectory';
import { useDeviceOrderPreferences } from '@/app/navigation/deviceOrderPreferences';
import { activateSurface } from '@/infrastructure/peer-device/deviceSurface';
import type { AccountDeviceInfo } from '@/infrastructure/api/service-api/RemoteConnectAPI';

vi.mock('@/infrastructure/api/service-api/ApiClient', () => ({ api: { listen: () => () => {} } }));
vi.mock('@/infrastructure/peer-device/peerDeviceContextState', () => ({ usePeerDeviceModeOptional: () => null }));

it('uses saved device IDs for sidebar order across remote activation, offline recovery, and renames', () => {
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
useDeviceOrderPreferences.setState({ order: ['peer', 'local-id', 'offline'] });
const devices = [
{ device_id: 'local-id', device_name: 'Local', online: true },
{ device_id: 'peer', device_name: 'Peer', online: true },
{ device_id: 'offline', device_name: 'Offline', online: false },
] as AccountDeviceInfo[];
useDeviceDirectory.setState({ localId: 'local-id', devices, status: 'ready' });
activateSurface('local');
const host = document.createElement('div');
const root = createRoot(host);
function Probe() { return <>{useSidebarDevices('This computer').map(slot => <span key={slot.surfaceId} data-id={slot.deviceId} data-rendered={slot.rendered} />)}</>; }
const order = () => [...host.querySelectorAll('span')].map(node => node.dataset.id);
try {
act(() => root.render(<Probe />));
expect(order()).toEqual(['peer', 'local-id']);
act(() => activateSurface('peer'));
expect(order()).toEqual(['peer', 'local-id']);
expect(host.querySelector('[data-rendered="true"]')?.getAttribute('data-id')).toBe('peer');
act(() => useDeviceDirectory.setState({ devices: devices.map(device => ({ ...device, online: true, device_alias: 'Renamed' })) }));
expect(order()).toEqual(['peer', 'local-id', 'offline']);
act(() => useDeviceOrderPreferences.getState().move('offline', 'peer', 'before', ['peer', 'local-id', 'offline']));
expect(order()).toEqual(['offline', 'peer', 'local-id']);
} finally {
act(() => root.unmount());
activateSurface('local');
useDeviceOrderPreferences.setState({ order: [] });
}
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useMemo, useSyncExternalStore } from 'react';
import { create } from 'zustand';
import { applyDeviceOrder, useDeviceOrderPreferences } from '@/app/navigation/deviceOrderPreferences';
import { createJSONStorage, persist } from 'zustand/middleware';
import { useDeviceDirectory, isDeviceControllable, resolveDeviceNameFrom } from '@/infrastructure/account/deviceDirectory';
import { getActiveSurfaceId, LOCAL_SURFACE_ID, onSurfaceActivated, surfaceIdForDevice, type DeviceSurfaceId } from '@/infrastructure/peer-device/deviceSurface';
Expand Down Expand Up @@ -37,15 +38,16 @@ export function devicePlatform(os: string | null | undefined): DevicePlatform |
const CONTROLLER_KINDS = new Set(['mobile', 'watch']);

/**
* The sidebar's device order: this machine first, then every online host of
* the account by name. The order never depends on which device is rendered,
* The controller's saved order, falling back to this machine then online hosts
* by name for devices the user has not arranged. The order never depends on which device is rendered,
* so opening something on another device does not move any section.
*
* Returns a single slot when there is nothing else to show, so a signed-out or
* single-device window renders exactly the plain workspace list.
*/
export function useSidebarDevices(localLabel: string): SidebarDeviceSlot[] {
const directory = useDeviceDirectory();
const deviceOrder = useDeviceOrderPreferences(state => state.order);
const peer = usePeerDeviceModeOptional();
const activeSurfaceId = useSyncExternalStore(onSurfaceActivated, getActiveSurfaceId, getActiveSurfaceId);
const renderedPeer = peer?.peerMode.active ? peer.peerMode : null;
Expand Down Expand Up @@ -95,8 +97,8 @@ export function useSidebarDevices(localLabel: string): SidebarDeviceSlot[] {
});
}
peers.sort((a, b) => a.name.localeCompare(b.name) || a.surfaceId.localeCompare(b.surfaceId));
return [...slots, ...peers];
}, [activeSurfaceId, attachments, directory.devices, directory.localId, localLabel, renderedPeer]);
return applyDeviceOrder([...slots, ...peers], deviceOrder, slot => slot.deviceId);
}, [deviceOrder, activeSurfaceId, attachments, directory.devices, directory.localId, localLabel, renderedPeer]);
}

interface DeviceSectionDisclosureState {
Expand Down
71 changes: 24 additions & 47 deletions src/web-ui/src/app/components/RemoteConnectDialog/AccountPanel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -144,34 +144,41 @@
align-items: center;
gap: var(--openbitfun-space-2);
padding: var(--openbitfun-space-3) surface.$row-inline;
transition: background-color var(--openbitfun-motion-duration-fast) var(--openbitfun-motion-easing-standard);

// An offline device recedes; nothing else changes colour.
&.offline .account-panel__device-glyph { color: var(--openbitfun-color-content-muted); }

& + & {
@include surface.card-divider(calc(40px + #{surface.$row-gap}));
@include surface.card-divider;
}

&.selectable:has(> .account-panel__device-select:hover) {
background: color-mix(in srgb, var(--openbitfun-color-content-primary) 4%, transparent);
}

// Row actions stay quiet until the row is in hand.
// Row actions appear with the row in hand; at rest the list is just names.
// Visibility stays available; rename and remove appear on hover or focus.
&:not(:hover, :focus-within) .account-panel__device-action:not(.account-panel__device-visibility) { opacity: 0; }
}

&.selectable:has(> .account-panel__device-select:active) {
background: var(--openbitfun-color-action-neutral-surface-pressed);
}
&__device-card[data-drop-position='before'] { box-shadow: inset 0 2px var(--openbitfun-color-accent-default); }
&__device-card[data-drop-position='after'] { box-shadow: inset 0 -2px var(--openbitfun-color-accent-default); }

&.selectable:has(> .account-panel__device-select:focus-visible) {
outline: var(--openbitfun-focus-width) solid var(--openbitfun-color-focus-ring);
outline-offset: calc(0px - var(--openbitfun-focus-width));
}
&__device-drag-handle {
display: inline-flex;
flex-shrink: 0;
align-items: center;
justify-content: center;
width: 24px;
height: 32px;
padding: 0;
border: 0;
border-radius: var(--openbitfun-radius-sm);
background: transparent;
color: var(--openbitfun-color-content-muted);
cursor: grab;

&:active { cursor: grabbing; }
}

&__device-select {
&__device-card[draggable='false'] &__device-drag-handle { opacity: 0.4; cursor: default; }

&__device-summary {
display: flex;
min-width: 0;
flex: 1;
Expand All @@ -183,26 +190,7 @@
color: var(--openbitfun-color-content-secondary);
font: inherit;
text-align: start;
cursor: default;

&:is(button) {
cursor: pointer;

// The whole row opens the device; row actions sit above this layer.
&::after {
position: absolute;
inset: 0;
content: '';
}
}

&:is(button):disabled {
cursor: default;
}

&:focus-visible {
outline: 0;
}
cursor: grab;
}

&__device-glyph {
Expand Down Expand Up @@ -291,13 +279,6 @@
gap: var(--openbitfun-space-1);
}

&__device-chevron {
@include surface.chevron;
display: inline-flex;
inline-size: 16px;
justify-content: center;
}

&__device-alias-editor {
position: relative;
z-index: 1;
Expand Down Expand Up @@ -393,10 +374,6 @@
}

@media (prefers-reduced-motion: reduce) {
.account-panel__device-card {
transition: none;
}

.account-panel .spinning {
animation: none;
}
Expand Down
Loading
Loading