Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

feat(workbench): toggle session visibility from the chat menu and add a desktop session menu (#2960)

Call White76b99a6c5b6f
diff --git a/ui/e2e/workbench-general/desktop-window-chrome.spec.ts b/ui/e2e/workbench-general/desktop-window-chrome.spec.ts
index 5fb8fd014..4ab0122df 100644
--- a/ui/e2e/workbench-general/desktop-window-chrome.spec.ts
+++ b/ui/e2e/workbench-general/desktop-window-chrome.spec.ts
@@ -45,6 +45,16 @@ for (const desktop of [false, true]) {
await expect(header.getByRole('button', { name: 'Visualize', exact: true })).toBeVisible();
await expect(header.getByRole('button', { name: 'Back', exact: true })).toBeVisible();
await expect(header).toHaveCount(1);
+ // Desktop carries the session menu right after the title, ahead of the route
+ // picker — not among the page-level controls on the right.
+ const sessionMenu = header.getByRole('button', { name: 'Session actions', exact: true });
+ await expect(sessionMenu).toHaveCount(1);
+ await expect(sessionMenu).toBeVisible();
+ const titleBox = await header.getByRole('button', { name: '中文窗口会话' }).boundingBox();
+ const menuBox = await sessionMenu.boundingBox();
+ const pickerBox = await header.getByRole('button', { name: /gpt-fixture/ }).boundingBox();
+ expect(menuBox!.x).toBeGreaterThanOrEqual(titleBox!.x + titleBox!.width - 1);
+ expect(menuBox!.x + menuBox!.width).toBeLessThan(pickerBox!.x);
if (desktop) {
await expect(page.locator('[data-desktop-window-chrome] [data-chat-header]')).toHaveCount(1);
diff --git a/ui/src/components/workbench/ChatPage.tsx b/ui/src/components/workbench/ChatPage.tsx
index 104e5bafa..94adbfbc6 100644
--- a/ui/src/components/workbench/ChatPage.tsx
+++ b/ui/src/components/workbench/ChatPage.tsx
@@ -4,7 +4,7 @@ import { useDesktopWindowChrome } from '../../context/DesktopWindowChromeContext
import { Fragment, forwardRef, memo, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Link, useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom';
-import { Activity, ArrowLeft, ArrowRight, ArrowUpRight, Bell, Bot, ChevronDown, ChevronRight, Clock, Eye, GitFork, Image as ImageIcon, Info, Loader2, MapPin, MessageSquare, MessageSquareQuote, Pencil, Terminal, Undo2, UploadCloud, X } from 'lucide-react';
+import { Activity, ArrowLeft, ArrowRight, ArrowUpRight, Bell, Bot, ChevronDown, ChevronRight, Clock, Eye, GitFork, Image as ImageIcon, Info, Loader2, MapPin, MessageSquare, MessageSquareQuote, Terminal, Undo2, UploadCloud, X } from 'lucide-react';
import type { LucideIcon } from 'lucide-react';
import clsx from 'clsx';
@@ -86,7 +86,7 @@ import {
} from './chatShortcuts';
import { bindFrameChord } from '../apps/windowChords';
import {
- MobileChatSessionActionMenu,
+ ChatSessionActionMenu,
type SessionActionDescriptor,
} from './sessionActions';
import { useSessionActions } from './useSessionActions';
@@ -3661,9 +3661,10 @@ interface ChatHeaderBarProps {
canManageShowPage?: boolean;
canManageInstance?: boolean;
canPinToDock?: boolean;
- // Shared session actions, rendered behind the mobile-only ⋯ at the far right.
- // Empty (or absent) withdraws the trigger — which is what a read-only session
- // yields, since every one of those writes is refused.
+ // Shared session actions, rendered behind a ⋯ beside the title on desktop and
+ // at the far right of the compact mobile bar. Empty (or absent) withdraws the
+ // trigger — which is what a read-only session yields, since every one of those
+ // writes is refused.
sessionActions?: SessionActionDescriptor[];
// Lets the menu's Rename row focus the title field that already lives here.
titleFieldRef?: React.Ref<TitleFieldHandle>;
@@ -3687,8 +3688,8 @@ export const ChatHeaderBar: React.FC<ChatHeaderBarProps> = ({ session, agents, d
// ``!readOnly`` twice over: useSessionActions already yields an empty list for a
// read-only session, and the withdrawal is re-stated here so this header cannot
// grow a ⋯ full of guaranteed-409 rows if a future caller passes actions anyway.
- const mobileSessionActions = sessionActions ?? [];
- const hasMobileSessionActions = writable && mobileSessionActions.length > 0;
+ const headerSessionActions = sessionActions ?? [];
+ const hasSessionActions = writable && headerSessionActions.length > 0;
const defaultAgent = defaultAgentName ? agents.find((agent) => agent.name === defaultAgentName) : null;
const sessionAgentLabel = sessionAgentDisplayName(session, agents);
// Mirrors update_session's guard. A session with a NATIVE conversation can
@@ -3760,6 +3761,16 @@ export const ChatHeaderBar: React.FC<ChatHeaderBarProps> = ({ session, agents, d
onCommit={(title) => onPatch({ title })}
readOnly={readOnly}
/>
+ {/* Desktop: the session menu belongs to the session's name, so it sits
+ right after the title rather than among the page-level controls on
+ the right. Mobile keeps its own trigger at the far right below. */}
+ {hasSessionActions && (
+ <ChatSessionActionMenu
+ actions={headerSessionActions}
+ label={t('workbench.sessionActions')}
+ viewport="wide"
+ />
+ )}
{/* Hidden while the Show Page is open so the view gets the full width.
On a read-only session the route is frozen, so show it as static text
plus a badge naming WHY instead of an interactive picker. A runtime-owned
@@ -3811,7 +3822,7 @@ export const ChatHeaderBar: React.FC<ChatHeaderBarProps> = ({ session, agents, d
back-to-chat button. */}
{/* In Show Page mode the order is: annotation control, launch/back, Share.
Share exists only there — never on the plain chat header. */}
- {(showLaunchControl || showShareControl || hasMobileSessionActions) && (
+ {(showLaunchControl || showShareControl || hasSessionActions) && (
<div className="ml-auto flex items-center gap-1.5">
{showPageActions.annotate && writable && (
<ShowPageAnnotateControl
@@ -3843,13 +3854,11 @@ export const ChatHeaderBar: React.FC<ChatHeaderBarProps> = ({ session, agents, d
onOpenChange={onShareOpenChange}
/>
)}
- {/* The chat-level session menu is a compact-mobile affordance. Desktop
- keeps these operations in the sidebar instead of duplicating a
- second menu in the page header. */}
- {hasMobileSessionActions && (
- <MobileChatSessionActionMenu
- actions={mobileSessionActions}
+ {hasSessionActions && (
+ <ChatSessionActionMenu
+ actions={headerSessionActions}
label={t('workbench.sessionActions')}
+ viewport="compact"
/>
)}
</div>
@@ -3905,14 +3914,16 @@ const TitleField = forwardRef<TitleFieldHandle, TitleFieldProps>(({ title, onCom
}
if (!editing) {
+ // A hover surface, not a trailing pencil, says "click to rename": the session
+ // menu sits right after the title, and a hidden pencil would hold a blank gap
+ // between the two.
return (
<button
type="button"
onClick={() => setEditing(true)}
- className="group inline-flex min-w-0 items-center gap-2 truncate text-left text-[16px] font-bold text-foreground hover:text-foreground"
+ className="-mx-1.5 inline-flex min-w-0 items-center truncate rounded-md px-1.5 py-0.5 text-left text-[16px] font-bold text-foreground transition-colors hover:bg-foreground/[0.05]"
>
<span className="truncate">{title || t('chat.untitled')}</span>
- <Pencil className="size-3.5 shrink-0 text-muted opacity-0 transition-opacity group-hover:opacity-100" />
</button>
);
}
diff --git a/ui/src/components/workbench/chatSessionActions.ts b/ui/src/components/workbench/chatSessionActions.ts
index bf6b8f99f..e030a55f8 100644
--- a/ui/src/components/workbench/chatSessionActions.ts
+++ b/ui/src/components/workbench/chatSessionActions.ts
@@ -5,5 +5,10 @@ import type { SessionActionDescriptor } from './sessionActions';
export const mobileSessionActions = (actions: SessionActionDescriptor[]): SessionActionDescriptor[] =>
actions.map((action) => (action.id === 'archive' ? { ...action, hint: undefined } : action));
+// The chat header's title is already click-to-edit, so its menu never repeats
+// Rename on any viewport.
+export const chatHeaderSessionActions = (actions: SessionActionDescriptor[]): SessionActionDescriptor[] =>
+ actions.filter((action) => action.id !== 'rename');
+
export const mobileChatSessionActions = (actions: SessionActionDescriptor[]): SessionActionDescriptor[] =>
- mobileSessionActions(actions).filter((action) => action.id !== 'rename');
+ chatHeaderSessionActions(mobileSessionActions(actions));
diff --git a/ui/src/components/workbench/sessionActions.test.tsx b/ui/src/components/workbench/sessionActions.test.tsx
index 6fa8b0c65..b2431e063 100644
--- a/ui/src/components/workbench/sessionActions.test.tsx
+++ b/ui/src/components/workbench/sessionActions.test.tsx
@@ -4,12 +4,12 @@ import { describe, expect, it } from 'vitest';
import { Popover, PopoverTrigger } from '../ui/popover';
import {
- MobileChatSessionActionMenu,
+ ChatSessionActionMenu,
SessionActionMenu,
SessionActionsTrigger,
type SessionActionDescriptor,
} from './sessionActions';
-import { mobileChatSessionActions, mobileSessionActions } from './chatSessionActions';
+import { chatHeaderSessionActions, mobileChatSessionActions, mobileSessionActions } from './chatSessionActions';
const row = (over: Partial<SessionActionDescriptor> & Pick<SessionActionDescriptor, 'id' | 'group' | 'label'>) =>
({ icon: Pin, onSelect: () => undefined, ...over }) as SessionActionDescriptor;
@@ -19,7 +19,7 @@ const fullMenu = (): SessionActionDescriptor[] => [
row({ id: 'pin', group: 'organize', label: 'Pin to top', icon: Pin }),
row({ id: 'rename', group: 'organize', label: 'Rename', icon: Pencil }),
row({ id: 'fork', group: 'continue', label: 'Fork session', icon: GitFork }),
- row({ id: 'hide', group: 'continue', label: 'Hide to background', icon: EyeOff }),
+ row({ id: 'visibility', group: 'continue', label: 'Hide to background', icon: EyeOff }),
row({ id: 'archive', group: 'lifecycle', label: 'Archive session', icon: Archive, danger: true, hint: '⇧⌘D' }),
];
@@ -52,7 +52,7 @@ describe('SessionActionMenu', () => {
it('draws one hairline divider per group change, never above the first row', () => {
const html = renderMenu(fullMenu());
- // organize → continue and continue → lifecycle; pin/rename and fork/hide pair up.
+ // organize → continue and continue → lifecycle; pin/rename and fork/visibility pair up.
expect(html.match(/border-t border-border/g)).toHaveLength(2);
expect(html.indexOf('border-t border-border')).toBeGreaterThan(html.indexOf('Pin to top'));
});
@@ -159,27 +159,43 @@ describe('SessionActionsTrigger', () => {
});
});
-describe('MobileChatSessionActionMenu', () => {
- it('removes rename and the archive shortcut hint from the mobile Chat surface', () => {
+describe('ChatSessionActionMenu', () => {
+ it('drops rename on every viewport and the archive shortcut hint only on mobile', () => {
const actions = fullMenu();
- const visibleActions = mobileChatSessionActions(actions);
+ const mobile = mobileChatSessionActions(actions);
+ const desktop = chatHeaderSessionActions(actions);
- expect(visibleActions.map((action) => action.id)).toEqual(['pin', 'fork', 'hide', 'archive']);
- expect(visibleActions.find((action) => action.id === 'archive')?.hint).toBeUndefined();
+ expect(mobile.map((action) => action.id)).toEqual(['pin', 'fork', 'visibility', 'archive']);
+ expect(mobile.find((action) => action.id === 'archive')?.hint).toBeUndefined();
+ expect(desktop.map((action) => action.id)).toEqual(['pin', 'fork', 'visibility', 'archive']);
+ expect(desktop.find((action) => action.id === 'archive')?.hint).toBe('⇧⌘D');
expect(actions.find((action) => action.id === 'archive')?.hint).toBe('⇧⌘D');
});
- it('renders the chat trigger only below the desktop breakpoint', () => {
- const html = renderToStaticMarkup(
- <MobileChatSessionActionMenu actions={fullMenu()} label="Session actions" />,
+ // The header mounts one trigger per viewport: beside the title on desktop and at
+ // the far right of the compact bar. Exactly one may show at any width.
+ it('shows the compact trigger only below the desktop breakpoint and the wide one only above it', () => {
+ const compact = renderToStaticMarkup(
+ <ChatSessionActionMenu actions={fullMenu()} label="Session actions" viewport="compact" />,
+ );
+ const wide = renderToStaticMarkup(
+ <ChatSessionActionMenu actions={fullMenu()} label="Session actions" viewport="wide" />,
);
- expect(html).toContain('md:hidden');
- expect(html).toContain('aria-label="Session actions"');
+ const rootClasses = (html: string) => html.match(/^<div class="([^"]*)"/)?.[1].split(' ') ?? [];
+ expect(rootClasses(compact)).toEqual(['md:hidden']);
+ expect(rootClasses(wide)).toEqual(expect.arrayContaining(['hidden', 'md:block']));
+ expect(rootClasses(wide)).not.toContain('md:hidden');
+ expect(compact).toContain('aria-label="Session actions"');
+ expect(wide).toContain('aria-label="Session actions"');
});
it('withdraws the trigger when the surface offers no actions', () => {
- expect(renderToStaticMarkup(<MobileChatSessionActionMenu actions={[]} label="Session actions" />)).toBe('');
+ for (const viewport of ['compact', 'wide'] as const) {
+ expect(
+ renderToStaticMarkup(<ChatSessionActionMenu actions={[]} label="Session actions" viewport={viewport} />),
+ ).toBe('');
+ }
});
});
diff --git a/ui/src/components/workbench/sessionActions.tsx b/ui/src/components/workbench/sessionActions.tsx
index 8218ad4c2..4d48768aa 100644
--- a/ui/src/components/workbench/sessionActions.tsx
+++ b/ui/src/components/workbench/sessionActions.tsx
@@ -6,7 +6,7 @@ import type { LucideIcon } from 'lucide-react';
import { Button } from '../ui/button';
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover';
-import { mobileChatSessionActions } from './chatSessionActions';
+import { chatHeaderSessionActions, mobileChatSessionActions } from './chatSessionActions';
import { SESSION_ROW_ACTION_BUTTON_CLASS } from './sessionRowLayout';
// Presentation half of the shared session action menu: the ⋯ trigger and the menu
@@ -14,7 +14,7 @@ import { SESSION_ROW_ACTION_BUTTON_CLASS } from './sessionRowLayout';
// header. The actions themselves (labels, writes, pending state) come from
// useSessionActions.tsx; surfaces opt into only the capabilities they can render.
-export type SessionActionId = 'pin' | 'reference' | 'fork' | 'pet' | 'rename' | 'hide' | 'archive';
+export type SessionActionId = 'pin' | 'reference' | 'fork' | 'pet' | 'rename' | 'visibility' | 'archive';
/** Menu grouping — rendered with a hairline divider between groups. */
export type SessionActionGroup = 'organize' | 'continue' | 'lifecycle';
@@ -247,20 +247,27 @@ export const SessionActionMenuContent: React.FC<{
);
};
-// Chat keeps this compact action entry point on mobile only. Owning the responsive
-// wrapper here makes the breakpoint part of the tested component contract instead
-// of an incidental class buried in the large ChatPage render tree. Rename is also
-// removed at this presentation boundary so future callers cannot reintroduce it.
-export const MobileChatSessionActionMenu: React.FC<{
+// The chat header's session menu. It sits in a different place per viewport —
+// beside the title on desktop, at the far right of the compact mobile bar — so the
+// header mounts one of each and this wrapper owns which breakpoint shows which.
+// Owning the responsive wrapper here makes the breakpoint part of the tested
+// component contract instead of an incidental class buried in the large ChatPage
+// render tree. Rename is also removed at this presentation boundary so future
+// callers cannot reintroduce it.
+export const ChatSessionActionMenu: React.FC<{
actions: SessionActionDescriptor[];
label: string;
-}> = ({ actions, label }) => {
+ /** ``compact``: the mobile bar (below ``md``). ``wide``: desktop, beside the title. */
+ viewport: 'compact' | 'wide';
+}> = ({ actions, label, viewport }) => {
const [open, setOpen] = useState(false);
- const visibleActions = mobileChatSessionActions(actions);
+ const compact = viewport === 'compact';
+ const visibleActions = compact ? mobileChatSessionActions(actions) : chatHeaderSessionActions(actions);
if (visibleActions.length === 0) return null;
return (
- <div className="md:hidden">
+ // ``wide`` pulls in against the title so the trigger reads as part of it.
+ <div className={compact ? 'md:hidden' : '-ml-1.5 hidden shrink-0 md:block'}>
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<SessionActionsTrigger label={label} open={open} variant="bar" />
@@ -268,7 +275,7 @@ export const MobileChatSessionActionMenu: React.FC<{
<SessionActionMenuContent
actions={visibleActions}
label={label}
- align="end"
+ align={compact ? 'end' : 'start'}
onClose={() => setOpen(false)}
/>
</Popover>
diff --git a/ui/src/components/workbench/useSessionActions.test.tsx b/ui/src/components/workbench/useSessionActions.test.tsx
index f573c5c6e..d87d61789 100644
--- a/ui/src/components/workbench/useSessionActions.test.tsx
+++ b/ui/src/components/workbench/useSessionActions.test.tsx
@@ -105,6 +105,7 @@ beforeEach(() => {
mocks.forkSession.mockResolvedValue(session({ id: 'ses_forked' }));
mocks.setSessionPinned.mockResolvedValue(undefined);
mocks.archiveSession.mockResolvedValue(undefined);
+ mocks.setSessionVisibility.mockResolvedValue(undefined);
mocks.authorizeRouteAction.mockImplementation(grantedAuthorization);
});
@@ -237,6 +238,28 @@ describe('fork under the unsaved-changes guard', () => {
});
});
+// A background session is opened by id (Agents → Runs, a link) and read in the chat
+// header, whose menu used to offer "Hide to background" for it again.
+describe('the visibility row', () => {
+ it.each([
+ ['foreground', 'workbench.sessionHideToBackground', 'background', 'workbench.sessionHiddenToast'],
+ ['background', 'workbench.sessionShowInForeground', 'foreground', 'workbench.sessionShownToast'],
+ ] as const)('on a %s session offers %s and moves it to the %s', async (visibility, label, next, toast) => {
+ const onSessionPatched = vi.fn();
+ const h = mount(options({ session: session({ visibility }), onSessionPatched }));
+
+ expect(h.actions.find((action) => action.id === 'visibility')?.label).toBe(label);
+ select(h, 'visibility');
+ await flush();
+
+ expect(mocks.setSessionVisibility).toHaveBeenCalledWith('ses_standalone', next);
+ expect(mocks.showToast).toHaveBeenCalledWith(toast, 'success', expect.objectContaining({ label: 'common.undo' }));
+ // The chat header holds its own copy of the row; the label flips only if the
+ // committed visibility reaches it.
+ expect(onSessionPatched).toHaveBeenCalledWith({ visibility: next }, 'ses_standalone');
+ });
+});
+
describe('a read-only session', () => {
it('offers nothing to click, no dialog, and an inert shortcut', () => {
for (const readOnly of [session({ status: 'archived' }), session({ visibility: 'system' }), null]) {
@@ -263,12 +286,12 @@ describe('a metadata-only session', () => {
it('keeps organization actions but removes local lifecycle actions', () => {
const h = mount(options({ writable: true, lifecycleWritable: false }));
- expect(h.actions.map((action) => action.id)).toEqual(['pin', 'rename', 'hide']);
+ expect(h.actions.map((action) => action.id)).toEqual(['pin', 'rename', 'visibility']);
expect(h.canArchive).toBe(false);
expect(h.archiveDialog).toBeNull();
});
});
it('never offers session binding to the main-only pet', () => {
- expect(mount(options()).actions.map((action) => action.id)).toEqual(['pin', 'rename', 'fork', 'hide', 'archive']);
+ expect(mount(options()).actions.map((action) => action.id)).toEqual(['pin', 'rename', 'fork', 'visibility', 'archive']);
});
diff --git a/ui/src/components/workbench/useSessionActions.tsx b/ui/src/components/workbench/useSessionActions.tsx
index 6e613e6d7..5cd19432d 100644
--- a/ui/src/components/workbench/useSessionActions.tsx
+++ b/ui/src/components/workbench/useSessionActions.tsx
@@ -1,7 +1,7 @@
import type * as React from 'react';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
-import { Archive, EyeOff, GitFork, Hash, Pencil, Pin, PinOff } from 'lucide-react';
+import { Archive, Eye, EyeOff, GitFork, Hash, Pencil, Pin, PinOff } from 'lucide-react';
import { useApi } from '../../context/ApiContext';
import type { WorkbenchSession } from '../../context/ApiContext';
@@ -9,7 +9,7 @@ import { useComposerInsertTarget } from '../../context/ComposerBridgeContext';
import { useWorkbenchProjectsActions } from '../../context/WorkbenchProjectsContext';
import { useToast } from '../../context/ToastContext';
import { useUnsavedChangesActionGuard } from '../../context/useUnsavedChangesActionGuard';
-import { hideSessionToBackground } from '../../lib/sessionVisibilityActions';
+import { changeSessionVisibility } from '../../lib/sessionVisibilityActions';
import { archiveRequestIsLive, isSessionReadOnly } from './sessionArchived';
import { ArchiveSessionDialog } from './ArchiveSessionDialog';
import type { SessionActionDescriptor } from './sessionActions';
@@ -92,10 +92,12 @@ export const useSessionActions = ({
const [archiveRequestId, setArchiveRequestId] = useState<string | null>(null);
const [pinning, setPinning] = useState(false);
const [forking, setForking] = useState(false);
+ const [movingVisibility, setMovingVisibility] = useState(false);
// Refs, not the state above: a second click can land before React re-renders
// with the disabled row (a double fork spawns two sessions).
const pinningRef = useRef(false);
const forkingRef = useRef(false);
+ const movingVisibilityRef = useRef(false);
// A read-only session (archived, or a runtime-owned ``system`` row) refuses every
// one of these server-side — 409 archived / 403 reserved_session — so the whole
@@ -160,16 +162,31 @@ export const useSessionActions = ({
}
}, [target, ownerProjectId, forkSession, onOpenSession, authorizeNavigation]);
- const hide = useCallback(() => {
- if (!target) return;
- void hideSessionToBackground({
- sessionId: target.id,
- setSessionVisibility: api.setSessionVisibility,
- showToast,
- hiddenMessage: t('workbench.sessionHiddenToast'),
- undoLabel: t('common.undo'),
- });
- }, [target, api.setSessionVisibility, showToast, t]);
+ // A background session is reachable only by id (Agents → Runs, a link), and the
+ // chat header is where it is then read — so the row offers the way back instead
+ // of a second hide.
+ const inBackground = target?.visibility === 'background';
+ const toggleVisibility = useCallback(async () => {
+ if (!target || movingVisibilityRef.current) return;
+ movingVisibilityRef.current = true;
+ setMovingVisibility(true);
+ const next = target.visibility === 'background' ? 'foreground' : 'background';
+ const movedId = target.id;
+ try {
+ await changeSessionVisibility({
+ sessionId: movedId,
+ visibility: next,
+ setSessionVisibility: api.setSessionVisibility,
+ showToast,
+ message: t(next === 'background' ? 'workbench.sessionHiddenToast' : 'workbench.sessionShownToast'),
+ undoLabel: t('common.undo'),
+ onCommitted: (visibility) => onSessionPatched?.({ visibility }, movedId),
+ });
+ } finally {
+ movingVisibilityRef.current = false;
+ setMovingVisibility(false);
+ }
+ }, [target, api.setSessionVisibility, showToast, t, onSessionPatched]);
const actions = useMemo<SessionActionDescriptor[]>(() => {
if (!target) return [];
@@ -223,11 +240,13 @@ export const useSessionActions = ({
});
}
rows.push({
- id: 'hide',
+ id: 'visibility',
group: 'continue',
- icon: EyeOff,
- label: t('workbench.sessionHideToBackground'),
- onSelect: hide,
+ icon: inBackground ? Eye : EyeOff,
+ label: t(inBackground ? 'workbench.sessionShowInForeground' : 'workbench.sessionHideToBackground'),
+ pending: movingVisibility,
+ disabled: movingVisibility,
+ onSelect: () => void toggleVisibility(),
});
if (lifecycleWritable) {
rows.push({
@@ -250,7 +269,9 @@ export const useSessionActions = ({
togglePinned,
onRenameStart,
fork,
- hide,
+ inBackground,
+ movingVisibility,
+ toggleVisibility,
requestArchive,
archiveHint,
lifecycleWritable,
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index 619acbeb5..b862eea7e 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -3326,6 +3326,8 @@
"sessionForkUnavailable": "This session has no native agent session to fork yet.",
"sessionHideToBackground": "Hide to background",
"sessionHiddenToast": "Hidden to background · Find it in Agents → Runs",
+ "sessionShowInForeground": "Show in foreground",
+ "sessionShownToast": "Shown in foreground",
"sessionArchive": "Archive session",
"archiveSession": {
"title": "Archive this session permanently?",
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index 94d06ba20..f2ebd5c6d 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -3326,6 +3326,8 @@
"sessionForkUnavailable": "此会话还没有可复刻的原生 Agent 会话。",
"sessionHideToBackground": "隐藏到后台",
"sessionHiddenToast": "已隐藏到后台 · 可在 Agents→Runs 找回",
+ "sessionShowInForeground": "显示到前台",
+ "sessionShownToast": "已显示到前台",
"sessionArchive": "归档会话",
"archiveSession": {
"title": "永久归档此会话?",
diff --git a/ui/src/lib/sessionVisibilityActions.test.ts b/ui/src/lib/sessionVisibilityActions.test.ts
index d73257b03..52b418862 100644
--- a/ui/src/lib/sessionVisibilityActions.test.ts
+++ b/ui/src/lib/sessionVisibilityActions.test.ts
@@ -1,45 +1,55 @@
import { describe, expect, it, vi } from 'vitest';
-import { hideSessionToBackground } from './sessionVisibilityActions';
+import { changeSessionVisibility } from './sessionVisibilityActions';
-describe('hideSessionToBackground', () => {
- it('moves the session to the background and exposes an undo action', async () => {
+const flush = () => new Promise((resolve) => setTimeout(resolve, 0));
+
+describe('changeSessionVisibility', () => {
+ it.each([
+ ['background', 'foreground'],
+ ['foreground', 'background'],
+ ] as const)('moves the session to the %s, reports it, and undoes back to the %s', async (visibility, previous) => {
const setSessionVisibility = vi.fn().mockResolvedValue(undefined);
const showToast = vi.fn();
+ const onCommitted = vi.fn();
- await hideSessionToBackground({
+ await changeSessionVisibility({
sessionId: 'sess-1',
+ visibility,
setSessionVisibility,
showToast,
- hiddenMessage: 'Session hidden',
+ message: 'Moved',
undoLabel: 'Undo',
+ onCommitted,
});
- expect(setSessionVisibility).toHaveBeenCalledWith('sess-1', 'background');
- expect(showToast).toHaveBeenCalledWith(
- 'Session hidden',
- 'success',
- expect.objectContaining({ label: 'Undo' }),
- );
+ expect(setSessionVisibility).toHaveBeenCalledWith('sess-1', visibility);
+ expect(onCommitted).toHaveBeenLastCalledWith(visibility);
+ expect(showToast).toHaveBeenCalledWith('Moved', 'success', expect.objectContaining({ label: 'Undo' }));
- const action = showToast.mock.calls[0][2];
- action.onClick();
- expect(setSessionVisibility).toHaveBeenLastCalledWith('sess-1', 'foreground');
+ showToast.mock.calls[0][2].onClick();
+ await flush();
+ expect(setSessionVisibility).toHaveBeenLastCalledWith('sess-1', previous);
+ expect(onCommitted).toHaveBeenLastCalledWith(previous);
});
- it('surfaces visibility failures without offering undo', async () => {
+ it('surfaces visibility failures without reporting a change or offering undo', async () => {
const setSessionVisibility = vi.fn().mockRejectedValue(new Error('Visibility update failed'));
const showToast = vi.fn();
+ const onCommitted = vi.fn();
- await hideSessionToBackground({
+ await changeSessionVisibility({
sessionId: 'sess-1',
+ visibility: 'background',
setSessionVisibility,
showToast,
- hiddenMessage: 'Session hidden',
+ message: 'Moved',
undoLabel: 'Undo',
+ onCommitted,
});
expect(showToast).toHaveBeenCalledOnce();
expect(showToast).toHaveBeenCalledWith('Visibility update failed', 'error');
+ expect(onCommitted).not.toHaveBeenCalled();
});
});
diff --git a/ui/src/lib/sessionVisibilityActions.ts b/ui/src/lib/sessionVisibilityActions.ts
index 88141de45..ae917b00d 100644
--- a/ui/src/lib/sessionVisibilityActions.ts
+++ b/ui/src/lib/sessionVisibilityActions.ts
@@ -1,6 +1,6 @@
import type { ToastAction } from '../context/toastCoalesce';
-type SessionVisibility = 'foreground' | 'background';
+export type SessionVisibility = 'foreground' | 'background';
type SetSessionVisibility = (sessionId: string, visibility: SessionVisibility) => Promise<unknown>;
type ShowToast = (
message: string,
@@ -8,24 +8,40 @@ type ShowToast = (
action?: ToastAction,
) => void;
-export async function hideSessionToBackground(args: {
+const opposite = (visibility: SessionVisibility): SessionVisibility =>
+ visibility === 'background' ? 'foreground' : 'background';
+
+/** Move a session to ``visibility`` and offer an Undo that moves it back.
+ * ``onCommitted`` reports every visibility the server accepted — the move and a
+ * later Undo alike — so a surface holding its own copy of the session row (the
+ * chat header) can keep its menu label in step with both. */
+export async function changeSessionVisibility(args: {
sessionId: string;
+ visibility: SessionVisibility;
setSessionVisibility: SetSessionVisibility;
showToast: ShowToast;
- hiddenMessage: string;
+ message: string;
undoLabel: string;
+ onCommitted?: (visibility: SessionVisibility) => void;
}): Promise<void> {
- const { sessionId, setSessionVisibility, showToast, hiddenMessage, undoLabel } = args;
+ const { sessionId, visibility, setSessionVisibility, showToast, message, undoLabel, onCommitted } = args;
try {
- await setSessionVisibility(sessionId, 'background');
- showToast(hiddenMessage, 'success', {
- label: undoLabel,
- onClick: () => {
- void setSessionVisibility(sessionId, 'foreground');
- },
- });
+ await setSessionVisibility(sessionId, visibility);
} catch (err) {
showToast(err instanceof Error ? err.message : String(err), 'error');
+ return;
}
+ onCommitted?.(visibility);
+ showToast(message, 'success', {
+ label: undoLabel,
+ onClick: () => {
+ const previous = opposite(visibility);
+ void setSessionVisibility(sessionId, previous).then(
+ () => onCommitted?.(previous),
+ // The request layer already toasted an HTTP refusal.
+ () => undefined,
+ );
+ },
+ });
}