Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

Merge upstream/main and preserve group lifecycle alongside archive recovery

zqchrisf8c775467e73
diff --cc apps/desktop/src/renderer/features/bots/BotsSidebar.tsx
index a564c5a77b,b9f8504937..6043039477
--- a/apps/desktop/src/renderer/features/bots/BotsSidebar.tsx
+++ b/apps/desktop/src/renderer/features/bots/BotsSidebar.tsx
@@@ -125,7 -145,42 +145,42 @@@ function BotsSidebarContent()
menuOriginRef.current = origin;
menuPointerDownRef.current = false;
menuRestoreFocusRef.current = true;
- setContextMenu({ botId, x, y });
+ setContextMenu({ kind, id, x, y });
+ };
+
+ const changeGroupArchive = async (group: BotGroupSummary) => {
- if (archiveBusyRef.current) return;
++ if (archiveBusyRef.current || group.dissolvedAt) return;
+ archiveBusyRef.current = true;
+ setArchiveBusy(true);
+ setArchiveError('');
+ const owner = getDataOwnerGeneration();
+ const origin = menuOriginRef.current;
+ let focusArchived = !!group.archived;
+ const actionKey = 'bots.groupChat.server.settings.' + (group.archived ? 'unarchive' : 'archive');
+ try {
+ const accepted = await confirm({ presentation: 'standard', title: t(actionKey),
+ description: t(actionKey + 'Hint'), confirmText: t(actionKey),
+ cancelText: t('bots.cancel'), confirmVariant: 'destructive' });
+ if (!accepted || !isDataOwnerGenerationCurrent(owner)) return;
+ const result = await window.electronAPI.maker.chatServer.manage({ groupId: group.id,
+ action: { type: 'archive', archived: !group.archived, expectedRevision: group.revision! } });
+ if (!isDataOwnerGenerationCurrent(owner)) return;
+ if (!result.ok) setArchiveError(t(chatErrorKey(result.errorCode)));
+ else {
+ focusArchived = !group.archived;
+ refreshBotGroups();
+ }
+ } catch {
+ if (isDataOwnerGenerationCurrent(owner)) setArchiveError(t(chatErrorKey('REQUEST_FAILED')));
+ } finally {
+ // Cancelled and failed confirmations also lose their menu-item opener.
+ // Recover to the unchanged row after the dialog releases focus.
+ if (isDataOwnerGenerationCurrent(owner)) {
+ pendingArchiveFocusRef.current = { groupId: group.id, archived: focusArchived, origin };
+ }
+ archiveBusyRef.current = false;
+ setArchiveBusy(false);
+ }
};
/*
@@@ -351,8 -487,35 +487,35 @@@
<Trash2 size={14} className="mr-2" />
{t('bots.lifecycle.delete')}
</DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
+ </>);
+
+ const renderGroupRow = (group: BotGroupSummary) => (
+ <BotGroupSidebarRow key={'group:' + group.id} group={group} bots={bots}
+ islandActivity={islandActivity} now={now} selected={group.id === groupId}
+ onOpenGroup={id => navigate('/bots/groups/' + encodeURIComponent(id))}
+ onContextMenu={event => {
+ event.preventDefault(); event.stopPropagation();
+ openContextMenu('group', group.id, event.currentTarget, event.clientX, event.clientY);
+ }}
+ onKeyDown={event => {
+ if (event.key !== 'ContextMenu' && !(event.key === 'F10' && event.shiftKey)) return;
+ event.preventDefault();
+ const rect = event.currentTarget.getBoundingClientRect();
+ openContextMenu('group', group.id, event.currentTarget, rect.left + 10, rect.bottom);
+ }}>
+ {renderContextMenu('group', group.id, <>
+ <DropdownMenuItem onSelect={() => navigate('/bots/groups/' + encodeURIComponent(group.id) + '?' + BOT_GROUP_SETTINGS_PARAM + '=1')}>
+ <Settings size={14} className="mr-2" />{t('bots.groupChat.settings.title')}
+ </DropdownMenuItem>
- {group.serverBacked && group.members.some(member => member.isOwned && (member.role === 'owner' || member.role === 'admin')) && <>
++ {group.serverBacked && !group.dissolvedAt && group.members.some(member => member.isOwned && (member.role === 'owner' || member.role === 'admin')) && <>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem disabled={archiveBusy} onSelect={() => void changeGroupArchive(group)}>
+ {group.archived ? <ArchiveRestore size={14} className="mr-2" /> : <Archive size={14} className="mr-2" />}
+ {t('bots.groupChat.server.settings.' + (group.archived ? 'unarchive' : 'archive'))}
+ </DropdownMenuItem>
+ </>}
+ </>)}
+ </BotGroupSidebarRow>
);
if (collapsed) {
diff --cc apps/desktop/src/renderer/features/bots/ChatGroupSettings.tsx
index 743acccc61,6ee4bd7229..b13f9fe17b
--- a/apps/desktop/src/renderer/features/bots/ChatGroupSettings.tsx
+++ b/apps/desktop/src/renderer/features/bots/ChatGroupSettings.tsx
@@@ -27,13 -26,10 +27,14 @@@ export function ChatGroupSettings({ gro
const { confirm } = useConfirmDialog();
const profiles = useBotProfiles();
const companions = group.members.filter(member => member.actorKind === 'bot');
- const me = group.members.find(m => m.isSelf);
- const owner = group.members.some(m => m.isOwned && m.role === 'owner');
- const manager = owner || group.members.some(m => m.isOwned && m.role === 'admin');
+ const membership = chatGroupMembership(group);
+ const { self: me } = membership;
+ const owner = membership.owner && !group.dissolvedAt;
+ const manager = membership.manager && !group.dissolvedAt;
+ const canLeave = membership.canLeave && !group.dissolvedAt;
+ const mounted = useRef(true);
+ useEffect(() => { mounted.current = true; return () => { mounted.current = false; }; }, []);
+ const soleOwner = me?.role === 'owner' && group.members.length === 1;
const [name, setName] = useState(group.name);
const [topic, setTopic] = useState(group.topic ?? '');
const [description, setDescription] = useState(group.description ?? '');
@@@ -70,13 -66,13 +71,13 @@@
refreshBotGroups();
if (exit) navigate('/bots');
return true;
- } catch { if (isDataOwnerGenerationCurrent(owner)) setError(t(chatErrorKey('REQUEST_FAILED'))); return false; }
- finally { busyRef.current = false; setBusy(false); }
+ } catch { if (mounted.current && isDataOwnerGenerationCurrent(owner)) setError(t(chatErrorKey('REQUEST_FAILED'))); return false; }
+ finally { busyRef.current = false; if (mounted.current) setBusy(false); }
}
- async function confirmed(action: ChatGroupAction, title: string, note: string, exit = false) {
+ async function confirmed(action: ChatGroupAction, title: string, note: string, exit = false, confirmText = t(key('confirm'))) {
const owner = getDataOwnerGeneration();
- if (await confirm({ presentation: 'standard', title, description: note, confirmText: t(key('confirm')),
+ if (await confirm({ presentation: 'standard', title, description: note, confirmText,
- cancelText: t('bots.cancel'), confirmVariant: 'destructive' }) && isDataOwnerGenerationCurrent(owner)) await mutate(action, exit);
+ cancelText: t('bots.cancel'), confirmVariant: 'destructive' }) && mounted.current && isDataOwnerGenerationCurrent(owner)) await mutate(action, exit);
}
const profileOpenChange = useCallback((open: boolean) => {
setEditingProfile(open);
@@@ -207,15 -203,12 +208,18 @@@
options={addable.map(bot => ({ value: bot.actorId, label: bot.name }))}
onValueChange={actorId => void mutate({ type: 'member', actorId, action: 'invite' })} />}
</section>
+ {group.dissolvedAt && <p className="text-13 text-[var(--text-secondary)]">{t('bots.groupChat.lifecycle.dissolved')}</p>}
- <div className="flex flex-wrap gap-2 border-t border-[var(--border-default)] pt-5">
- {canLeave && <Button variant="secondary" size="sm" disabled={busy} onClick={() => void confirmed({ type: 'member', actorId: me!.actorId!, action: 'leave' }, t(key('leave')), t(key('leaveHint')), true)}>{t(key('leave'))}</Button>}
- {manager && <Button variant="secondary" size="sm" disabled={busy} onClick={() => void confirmed({ type: 'archive', archived: !group.archived, expectedRevision: group.revision! }, t(key(group.archived ? 'unarchive' : 'archive')), t(key(group.archived ? 'unarchiveHint' : 'archiveHint')))}>{t(key(group.archived ? 'unarchive' : 'archive'))}</Button>}
- {owner && <Button variant="secondary" size="sm" disabled={busy || group.supportsDissolve !== true}
- onClick={() => void confirmed({ type: 'dissolve', expectedRevision: group.revision! }, t('bots.groupChat.lifecycle.dissolve'), t('bots.groupChat.lifecycle.dissolveNote'))}>{t('bots.groupChat.lifecycle.dissolve')}</Button>}
- <Button variant="secondary" size="sm" disabled={busy || group.supportsListRemoval !== true}
- onClick={() => void confirmed({ type: 'hide' }, t('bots.groupChat.lifecycle.hide'), t('bots.groupChat.lifecycle.hideNote'), true)}>{t('bots.groupChat.lifecycle.hide')}</Button>
- {((owner && !group.supportsDissolve) || !group.supportsListRemoval) && <p className="w-full text-12 text-[var(--text-secondary)]">{t('bots.groupChat.lifecycle.unavailable')}</p>}
+ <div className="space-y-3 border-t border-[var(--border-default)] pt-5">
- {soleOwner && !group.archived && <p className="text-13 text-[var(--text-secondary)]">{t(key('soleOwnerHint'))}</p>}
++ {soleOwner && !group.archived && !group.dissolvedAt && <p className="text-13 text-[var(--text-secondary)]">{t(key('soleOwnerHint'))}</p>}
+ <div className="flex flex-wrap gap-2">
- {!soleOwner && <Button variant="secondary" size="sm" disabled={busy || !me} onClick={() => void confirmed({ type: 'member', actorId: me!.actorId!, action: 'leave' }, t(key('leave')), t(key('leaveHint')), true)}>{t(key('leave'))}</Button>}
++ {canLeave && <Button variant="secondary" size="sm" disabled={busy} onClick={() => void confirmed({ type: 'member', actorId: me!.actorId!, action: 'leave' }, t(key('leave')), t(key('leaveHint')), true)}>{t(key('leave'))}</Button>}
+ {manager && <Button variant="secondary" size="sm" disabled={busy} onClick={() => void confirmed({ type: 'archive', archived: !group.archived, expectedRevision: group.revision! }, t(key(group.archived ? 'unarchive' : 'archive')), t(key(group.archived ? 'unarchiveHint' : 'archiveHint')), false, t(key(group.archived ? 'unarchive' : 'archive')))}>{t(key(group.archived ? 'unarchive' : 'archive'))}</Button>}
++ {owner && <Button variant="secondary" size="sm" disabled={busy || group.supportsDissolve !== true}
++ onClick={() => void confirmed({ type: 'dissolve', expectedRevision: group.revision! }, t('bots.groupChat.lifecycle.dissolve'), t('bots.groupChat.lifecycle.dissolveNote'))}>{t('bots.groupChat.lifecycle.dissolve')}</Button>}
++ <Button variant="secondary" size="sm" disabled={busy || group.supportsListRemoval !== true}
++ onClick={() => void confirmed({ type: 'hide' }, t('bots.groupChat.lifecycle.hide'), t('bots.groupChat.lifecycle.hideNote'), true)}>{t('bots.groupChat.lifecycle.hide')}</Button>
++ {((owner && !group.supportsDissolve) || !group.supportsListRemoval) && <p className="w-full text-12 text-[var(--text-secondary)]">{t('bots.groupChat.lifecycle.unavailable')}</p>}
+ </div>
</div>
</div>
<ProfileEditDialog open={editingProfile} onOpenChange={profileOpenChange} />
diff --cc apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
index 76c7a6203b,7cd8105437..b486d0df0e
--- a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
@@@ -327,14 -327,22 +327,30 @@@ beforeEach(() =>
afterEach(() => { cleanup(); vi.unstubAllGlobals(); });
describe('BotGroupChatView', () => {
+ it('clears the selected route when an authoritative personal hide unmounts settings', async () => {
+ renderView();
+ await screen.findByRole('textbox');
+ act(() => mocks.pushes.forEach(push => push({ groupId: 'g1', change: 'list', listState: { hidden: true, revision: 1 } })));
+ expect(mocks.navigate).toHaveBeenCalledWith('/bots');
+ expect(screen.queryByRole('textbox')).toBeNull();
+ });
+
+ it('keeps archived history readable and restores the composer only after the group is unarchived', async () => {
+ const archived = detail({ serverBacked: true, archived: true,
+ messages: [msg({ content: 'Preserved group history' })],
+ });
+ mocks.getBotGroup.mockResolvedValue({ ok: true, group: archived });
+ renderView();
+ await screen.findByText('Preserved group history');
+ expect(screen.getByText('bots.groupChat.server.settings.archived')).toBeTruthy();
+ expect(screen.queryByRole('textbox')).toBeNull();
+ mocks.getBotGroup.mockResolvedValue({ ok: true, group: { ...archived, archived: false } });
+ act(() => { mocks.pushes.forEach(push => push({ groupId: 'g1', change: 'updated' })); });
+ await screen.findByRole('textbox');
+ expect(screen.getByText('Preserved group history')).toBeTruthy();
+ expect(screen.queryByText('bots.groupChat.server.settings.archived')).toBeNull();
+ });
+
function mockThreadMotion(duration: string) {
const style = document.createElement('style');
style.textContent = `aside { --motion-base: ${duration}; --motion-ease-move: linear; }`;
diff --cc apps/desktop/src/renderer/features/bots/__tests__/botGroupSidebar.test.tsx
index 5ac012815b,c659828f08..7dfdcadf6e
--- a/apps/desktop/src/renderer/features/bots/__tests__/botGroupSidebar.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/botGroupSidebar.test.tsx
@@@ -175,9 -199,314 +199,324 @@@ beforeEach(() =>
});
});
- afterEach(cleanup);
+ afterEach(() => {
+ cleanup();
+ vi.restoreAllMocks();
+ });
describe('BotsSidebar group chats', () => {
+ it('hides archived groups without an archive entry and finds their history through search', async () => {
+ mocks.groups = [group(), group({ id: 'saved', name: '已完成的旅行', archived: true })];
+ const view = await renderSidebar();
+ expect(screen.getByText('周末出游')).toBeTruthy();
+ expect(screen.queryByText('已完成的旅行')).toBeNull();
+ expect(screen.queryByTestId('bot-archived-groups-toggle')).toBeNull();
+ const input = screen.getByRole('textbox', { name: 'bots.list.search' });
+ fireEvent.change(input, { target: { value: '已完成的旅行' } });
+ expect(screen.getByText('bots.archived')).toBeTruthy();
+ fireEvent.click(screen.getByText('已完成的旅行'));
+ expect(mocks.navigate).toHaveBeenCalledWith('/bots/groups/saved');
+ fireEvent.change(input, { target: { value: '' } });
+ expect(screen.queryByText('已完成的旅行')).toBeNull();
+ mocks.groups = mocks.groups.map(item => ({ ...item, archived: false }));
+ view.rerender(cloneElement(mocks.registered.node as ReactElement));
+ expect(screen.getByText('已完成的旅行')).toBeTruthy();
+ });
+
+ it('searches archived group names and members without showing them in the default list', async () => {
+ mocks.profiles = [];
+ mocks.groups = Array.from({ length: 8 }, (_, i) => group({ id: 'saved-' + i,
+ name: '历史群 ' + i, archived: true, members: i === 0 ? group().members : [],
+ }));
+ await renderSidebar();
+ const input = screen.getByRole('textbox', { name: 'bots.list.search' });
+ fireEvent.change(input, { target: { value: '历史群 0' } });
+ expect(screen.getByText('历史群 0')).toBeTruthy();
+ expect(screen.queryByText('历史群 1')).toBeNull();
+ fireEvent.change(input, { target: { value: '小满' } });
+ expect(screen.getByText('历史群 0')).toBeTruthy();
+ fireEvent.change(input, { target: { value: 'missing' } });
+ expect(screen.queryByText('历史群 0')).toBeNull();
+ expect(screen.getByText('bots.list.noResults')).toBeTruthy();
+ });
+
+ it('keeps an empty default list searchable when only one archived group remains and no bots exist', async () => {
+ mocks.profiles = [];
+ mocks.groups = [group({ archived: true, members: [{ ...group().members[0]!, name: 'Research Lead' }] })];
+ await renderSidebar();
+ expect(screen.queryByText('周末出游')).toBeNull();
+ expect(document.querySelector('[data-bot-group-id]')).toBeNull();
+ expect(screen.queryByTestId('bot-archived-groups-toggle')).toBeNull();
+ const input = screen.getByRole('textbox', { name: 'bots.list.search' });
+ fireEvent.change(input, { target: { value: ' RESEARCH ' } });
+ expect(screen.getByText('周末出游')).toBeTruthy();
+ expect(screen.getByText('bots.archived')).toBeTruthy();
+ fireEvent.change(input, { target: { value: ' ' } });
+ expect(screen.queryByText('周末出游')).toBeNull();
+ });
+
+ const managedGroup = (archived = false) => group({ serverBacked: true, archived, revision: 7,
+ members: [{ ...group().members[0]!, isOwned: true, role: 'owner' }],
+ });
+ const archiveKey = (archived = false) => 'bots.groupChat.server.settings.' + (archived ? 'unarchive' : 'archive');
+ async function selectArchive(archived = false) {
+ fireEvent.contextMenu(screen.getByText('周末出游').closest('button')!, { clientX: 20, clientY: 30 });
+ fireEvent.click(await screen.findByRole('menuitem', { name: archiveKey(archived) }));
+ }
+
+ it.each([false, true])('confirms archive change (%s) with the current revision and waits for refresh', async archived => {
+ mocks.groups = [managedGroup(archived)];
+ const view = await renderSidebar();
+ if (archived) fireEvent.change(screen.getByRole('textbox', { name: 'bots.list.search' }), { target: { value: '周末' } });
+ await selectArchive(archived);
+ await waitFor(() => expect(mocks.manage).toHaveBeenCalledWith({ groupId: 'g1', action: {
+ type: 'archive', archived: !archived, expectedRevision: 7,
+ } }));
+ expect(mocks.confirm).toHaveBeenCalledWith(expect.objectContaining({ title: archiveKey(archived),
+ confirmText: archiveKey(archived),
+ description: 'bots.groupChat.server.settings.' + (archived ? 'unarchiveHint' : 'archiveHint'),
+ }));
+ expect(mocks.refreshGroups).toHaveBeenCalledOnce();
+ expect(screen.getByText('周末出游')).toBeTruthy();
+ mocks.groups = [managedGroup(!archived)];
+ view.rerender(cloneElement(mocks.registered.node as ReactElement));
+ if (!archived) expect(screen.queryByText('周末出游')).toBeNull();
+ else expect(screen.getByText('周末出游')).toBeTruthy();
+ });
+
+ it('restores visible search focus after keyboard archive removes a default row', async () => {
+ const focus = vi.spyOn(HTMLElement.prototype, 'focus');
+ mocks.groups = [managedGroup()];
+ const view = await renderSidebar();
+ const row = screen.getByText('周末出游').closest('button')!;
+ fireEvent.keyDown(row, { key: 'F10', shiftKey: true });
+ fireEvent.click(await screen.findByRole('menuitem', { name: archiveKey() }));
+ await waitFor(() => expect(mocks.manage).toHaveBeenCalledOnce());
+
+ mocks.groups = [managedGroup(true)];
+ view.rerender(cloneElement(mocks.registered.node as ReactElement));
+ await waitFor(() => expect(document.activeElement).toBe(screen.getByRole('textbox', { name: 'bots.list.search' })));
+ // Let the browser reveal the search field if needed.
+ expect(focus).toHaveBeenLastCalledWith();
+ });
+
+ it.each([false, true])('recovers focus when settings archives the selected group (route already cleared: %s)', async cleared => {
+ mocks.params = { groupId: 'g1' };
+ mocks.pathname = '/bots/groups/g1';
+ mocks.groups = [managedGroup()];
+ const view = await renderSidebar();
+ mocks.groups = [managedGroup(true)];
+ if (cleared) { mocks.params = {}; mocks.pathname = '/bots/list'; }
+ view.rerender(cloneElement(mocks.registered.node as ReactElement));
+ await waitFor(() => expect(document.activeElement).toBe(screen.getByRole('textbox', { name: 'bots.list.search' })));
+ });
+
+ it('keeps a new sidebar selection when settings archive finishes', async () => {
+ mocks.params = { groupId: 'g1' };
+ mocks.pathname = '/bots/groups/g1';
+ mocks.groups = [managedGroup()];
+ const view = await renderSidebar();
+ const next = screen.getByText('咪咪').closest('button')!;
+ act(() => next.focus());
+ mocks.groups = [managedGroup(true)];
+ mocks.params = {};
+ mocks.pathname = '/bots/list';
+ view.rerender(cloneElement(mocks.registered.node as ReactElement));
+ await act(async () => { await new Promise(resolve => setTimeout(resolve, 60)); });
+ expect(document.activeElement).toBe(next);
+ });
+
+ it('recovers to an existing sidebar button when settings archive finishes with a collapsed sidebar', async () => {
+ mocks.params = { groupId: 'g1' };
+ mocks.pathname = '/bots/groups/g1';
+ mocks.groups = [managedGroup()];
+ mocks.collapsed = true;
+ const view = await renderSidebar();
+ mocks.groups = [managedGroup(true)];
+ mocks.params = {};
+ mocks.pathname = '/bots/list';
+ view.rerender(cloneElement(mocks.registered.node as ReactElement));
+ await waitFor(() => expect(document.activeElement).toBe(view.container.querySelector('button')));
+ });
+
+ it('restores focus to the moved group row after keyboard unarchive', async () => {
+ const focus = vi.spyOn(HTMLElement.prototype, 'focus');
+ mocks.groups = [managedGroup(true)];
+ const view = await renderSidebar();
+ fireEvent.change(screen.getByRole('textbox', { name: 'bots.list.search' }), { target: { value: '周末' } });
+ const row = screen.getByText('周末出游').closest('button')!;
+ fireEvent.keyDown(row, { key: 'F10', shiftKey: true });
+ fireEvent.click(await screen.findByRole('menuitem', { name: archiveKey(true) }));
+ await waitFor(() => expect(mocks.manage).toHaveBeenCalledOnce());
+
+ mocks.groups = [managedGroup(false)];
+ view.rerender(cloneElement(mocks.registered.node as ReactElement));
+ await waitFor(() => expect(document.activeElement).toBe(screen.getByText('周末出游').closest('button')));
+ expect(focus).toHaveBeenLastCalledWith();
+ });
+
+ it('keeps the search input focused when its last archived result is restored and the query is cleared', async () => {
+ mocks.profiles = [];
+ mocks.groups = [managedGroup(true)];
+ const view = await renderSidebar();
+ const input = screen.getByRole('textbox', { name: 'bots.list.search' });
+ fireEvent.change(input, { target: { value: '周末' } });
+ await selectArchive(true);
+ await waitFor(() => expect(mocks.manage).toHaveBeenCalledOnce());
+ act(() => input.focus());
+ mocks.groups = [managedGroup(false)];
+ view.rerender(cloneElement(mocks.registered.node as ReactElement));
+ fireEvent.change(input, { target: { value: '' } });
+ expect(screen.getByRole('textbox', { name: 'bots.list.search' })).toBe(input);
+ expect(document.activeElement).toBe(input);
+
+ const row = screen.getByText('周末出游').closest('button')!;
+ act(() => row.focus());
+ expect(screen.queryByRole('textbox', { name: 'bots.list.search' })).toBeNull();
+ expect(document.activeElement).toBe(row);
+ });
+
+ it('does not steal search focus when unarchive moves a filtered-out group', async () => {
+ mocks.groups = [managedGroup(true)];
+ const view = await renderSidebar();
+ fireEvent.change(screen.getByRole('textbox', { name: 'bots.list.search' }), { target: { value: '周末' } });
+ const input = screen.getByRole('textbox', { name: 'bots.list.search' });
+ await selectArchive(true);
+ await waitFor(() => expect(mocks.manage).toHaveBeenCalledOnce());
+
+ fireEvent.change(input, { target: { value: 'missing' } });
+ input.focus();
+ mocks.groups = [managedGroup(false)];
+ view.rerender(cloneElement(mocks.registered.node as ReactElement));
+ await waitFor(() => expect(document.activeElement).toBe(input));
+ });
+
+ it.each([false, true])('restores the original row after archive confirmation is cancelled (%s)', async archived => {
+ let settle!: (accepted: boolean) => void;
+ mocks.confirm.mockImplementationOnce(() => new Promise<boolean>(resolve => { settle = resolve; }));
+ mocks.groups = [managedGroup(archived)];
+ await renderSidebar();
+ if (archived) fireEvent.change(screen.getByRole('textbox', { name: 'bots.list.search' }), { target: { value: '周末' } });
+ const row = screen.getByText('周末出游').closest('button')!;
+ row.focus();
+ await selectArchive(archived);
+ await waitFor(() => expect(document.activeElement).toBe(row));
+
+ // Closing the real confirmation leaves body focused because its menu item
+ // opener has already unmounted. The group row itself still exists.
+ row.blur();
+ await act(async () => { settle(false); });
+ await waitFor(() => expect(document.activeElement).toBe(row));
+ expect(mocks.manage).not.toHaveBeenCalled();
+ expect(mocks.refreshGroups).not.toHaveBeenCalled();
+ });
+
+ it.each([false, true])('restores the original row after archive request failure (%s)', async archived => {
+ let settle!: (result: { ok: false; errorCode: string }) => void;
+ mocks.manage.mockImplementationOnce(() => new Promise(resolve => { settle = resolve; }));
+ mocks.groups = [managedGroup(archived)];
+ await renderSidebar();
+ if (archived) fireEvent.change(screen.getByRole('textbox', { name: 'bots.list.search' }), { target: { value: '周末' } });
+ const row = screen.getByText('周末出游').closest('button')!;
+ row.focus();
+ await selectArchive(archived);
+ await waitFor(() => expect(mocks.manage).toHaveBeenCalledOnce());
+ await waitFor(() => expect(document.activeElement).toBe(row));
+
+ row.blur();
+ await act(async () => { settle({ ok: false, errorCode: 'REVISION_CONFLICT' }); });
+ await waitFor(() => expect(document.activeElement).toBe(row));
+ expect(screen.getByRole('alert').textContent).toBe('bots.groupChat.server.settings.conflict');
+ expect(mocks.refreshGroups).not.toHaveBeenCalled();
+ });
+
+ it('does not steal search focus when unarchive keeps the group visible', async () => {
+ mocks.groups = [managedGroup(true)];
+ const view = await renderSidebar();
+ fireEvent.change(screen.getByRole('textbox', { name: 'bots.list.search' }), { target: { value: '周末' } });
+ const input = screen.getByRole('textbox', { name: 'bots.list.search' });
+ await selectArchive(true);
+ await waitFor(() => expect(mocks.manage).toHaveBeenCalledOnce());
+
+ fireEvent.change(input, { target: { value: '周末' } });
+ input.focus();
+ mocks.groups = [managedGroup(false)];
+ view.rerender(cloneElement(mocks.registered.node as ReactElement));
+ await waitFor(() => expect(document.activeElement).toBe(input));
+ });
+
+ it('keeps cancelled archives untouched and blocks old-account confirmations', async () => {
+ mocks.groups = [managedGroup()];
+ mocks.confirm.mockResolvedValueOnce(false);
+ await renderSidebar();
+ await selectArchive();
+ await waitFor(() => expect(mocks.confirm).toHaveBeenCalledOnce());
+ expect(mocks.manage).not.toHaveBeenCalled();
+ expect(screen.getByText('周末出游')).toBeTruthy();
+ mocks.confirm.mockImplementationOnce(async () => { mocks.ownerGeneration += 1; return true; });
+ await selectArchive();
+ await waitFor(() => expect(mocks.confirm).toHaveBeenCalledTimes(2));
+ expect(mocks.manage).not.toHaveBeenCalled();
+ expect(mocks.refreshGroups).not.toHaveBeenCalled();
+ });
+
+ it('blocks duplicate archive triggers while a confirmation is pending', async () => {
+ mocks.groups = [managedGroup()];
+ let accept!: (value: boolean) => void;
+ mocks.confirm.mockImplementationOnce(() => new Promise(resolve => { accept = resolve; }));
+ await renderSidebar();
+ await selectArchive();
+ fireEvent.contextMenu(screen.getByText('周末出游').closest('button')!);
+ const action = await screen.findByRole('menuitem', { name: archiveKey() });
+ expect(action.getAttribute('aria-disabled')).toBe('true');
+ fireEvent.click(action);
+ expect(mocks.confirm).toHaveBeenCalledOnce();
+ await act(async () => { accept(true); });
+ await waitFor(() => expect(mocks.manage).toHaveBeenCalledOnce());
+ });
+
+ it('shows archived history rather than stale speaking or plan prompts', async () => {
+ mocks.groups = [group({ archived: true, speakingBotIds: ['mimi'], openPlan: openPlan() })];
+ await renderSidebar();
+ fireEvent.change(screen.getByRole('textbox', { name: 'bots.list.search' }), { target: { value: '周末' } });
+ expect(screen.queryByTestId('bot-group-running')).toBeNull();
+ expect(screen.queryByText(/sidebar.planStepDone/)).toBeNull();
+ expect(screen.getByText('bots.groupChat.sidebar.preview:{"name":"阿布","text":"下午 有小概率阵雨"}')).toBeTruthy();
+ });
+
+ it('keeps failed archives visible and ignores old-account responses', async () => {
+ mocks.groups = [managedGroup()];
+ mocks.manage.mockResolvedValueOnce({ ok: false, errorCode: 'REVISION_CONFLICT' });
+ await renderSidebar();
+ await selectArchive();
+ await waitFor(() => expect(screen.getByRole('alert').textContent).toBe('bots.groupChat.server.settings.conflict'));
+ expect(screen.getByText('周末出游')).toBeTruthy();
+ expect(mocks.refreshGroups).not.toHaveBeenCalled();
+ mocks.manage.mockImplementationOnce(async () => { mocks.ownerGeneration += 1; return { ok: true }; });
+ await selectArchive();
+ await waitFor(() => expect(mocks.manage).toHaveBeenCalledTimes(2));
+ expect(mocks.refreshGroups).not.toHaveBeenCalled();
+ });
+
+ it('offers settings but no archive for ordinary members, with keyboard access', async () => {
+ mocks.groups = [group({ serverBacked: true, revision: 1 })];
+ await renderSidebar();
+ fireEvent.keyDown(screen.getByText('周末出游').closest('button')!, { key: 'F10', shiftKey: true });
+ expect(screen.queryByRole('menuitem', { name: archiveKey() })).toBeNull();
+ fireEvent.click(await screen.findByRole('menuitem', { name: 'bots.groupChat.settings.title' }));
+ expect(mocks.navigate).toHaveBeenCalledWith('/bots/groups/g1?groupSettings=1');
+ });
+
++ it('keeps dissolved history searchable without offering unarchive to its owner', async () => {
++ mocks.groups = [{ ...managedGroup(true), dissolvedAt: '2026-10-15T12:00:00Z' }];
++ await renderSidebar();
++ fireEvent.change(screen.getByRole('textbox', { name: 'bots.list.search' }), { target: { value: '周末' } });
++ fireEvent.keyDown(screen.getByText('周末出游').closest('button')!, { key: 'F10', shiftKey: true });
++ expect(screen.queryByRole('menuitem', { name: archiveKey(true) })).toBeNull();
++ expect(await screen.findByRole('menuitem', { name: 'bots.groupChat.settings.title' })).toBeTruthy();
++ expect(mocks.manage).not.toHaveBeenCalled();
++ });
++
it('lists groups alongside teammates with an author preview and opens them', async () => {
mocks.groups = [group(), group({ id: 'g2', name: '读书会', lastMessage: null, updatedAt: 1 })];
mocks.params = { groupId: 'g1' };
diff --cc apps/desktop/src/renderer/i18n/locales/en/common.json
index 7a20887b86,1aa63e3594..f2530ded4b
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@@ -9242,9 -9241,10 +9244,10 @@@
"removeHint": "They will lose access to messages. Their companions will also leave.",
"addCompanion": "Invite my companion",
"leave": "Leave group",
- "leaveHint": "You and your companions will leave. Transfer ownership first if you own the group.",
+ "leaveHint": "You and your companions will leave this group. You will no longer receive new messages or have access to its history.",
- "archive": "Archive group",
- "archiveHint": "Keep history, stop new messages and companion activity.",
+ "soleOwnerHint": "You’re the only member left. Archive this group to keep its history and restore it later.",
+ "archive": "Archive Group",
+ "archiveHint": "Archiving disables this group for all members, stopping new messages and teammate runs. History is kept. Search for the group to view its history or unarchive it.",
"confirm": "Confirm",
"lastOwner": "Transfer ownership to another member before leaving or removing the current owner.",
"conflict": "Someone updated this group. Refresh and try again.",
diff --cc apps/desktop/src/renderer/i18n/locales/ja/common.json
index e07f8366af,a5e42bfb1a..1267ecf1d6
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@@ -9205,9 -9204,10 +9207,10 @@@
"removeHint": "メッセージの閲覧と送信ができなくなります。そのメンバーのパートナーも退出します。",
"addCompanion": "自分のパートナーを招待",
"leave": "グループを退出",
- "leaveHint": "あなたとあなたのパートナーが退出します。オーナーは先に所有権を譲渡してください。",
+ "leaveHint": "あなたとあなたの仲間がグループから退出します。新しいメッセージは届かなくなり、グループの履歴を閲覧できなくなります。",
+ "soleOwnerHint": "メンバーはあなただけです。グループをアーカイブすると履歴が残り、後で再開できます。",
"archive": "グループをアーカイブ",
- "archiveHint": "履歴を残し、新しいメッセージとパートナーの実行を停止します。",
+ "archiveHint": "アーカイブすると、すべてのメンバーに対して新しいメッセージとパートナーの実行が停止します。履歴は保持されます。グループを検索して履歴を閲覧したり、アーカイブを解除したりできます。",
"confirm": "確認",
"lastOwner": "退出またはオーナーを削除する前に、別のメンバーに所有権を譲渡してください。",
"conflict": "設定が更新されました。再読み込みしてお試しください。",
diff --cc apps/desktop/src/renderer/i18n/locales/ko/common.json
index 5d81996d8b,4523238f17..8bca3f2243
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@@ -9205,9 -9204,10 +9207,10 @@@
"removeHint": "메시지를 읽거나 보낼 수 없게 됩니다. 해당 멤버의 파트너도 나갑니다.",
"addCompanion": "내 파트너 초대",
"leave": "그룹 나가기",
- "leaveHint": "본인과 자신의 파트너가 그룹을 나갑니다. 소유자는 먼저 소유권을 이전해야 합니다.",
+ "leaveHint": "나와 내 동료가 이 그룹에서 나갑니다. 새 메시지를 받지 못하며 그룹 기록을 볼 수 없게 됩니다.",
+ "soleOwnerHint": "그룹에 나만 남았어요. 그룹을 보관하면 기록을 유지하고 나중에 다시 사용할 수 있어요.",
"archive": "그룹 보관",
- "archiveHint": "기록을 보존하고 새 메시지와 파트너 실행을 중단합니다.",
+ "archiveHint": "그룹을 보관하면 모든 멤버의 새 메시지와 파트너 실행이 중지돼요. 기록은 유지돼요. 그룹을 검색해 기록을 보거나 보관을 해제할 수 있어요.",
"confirm": "확인",
"lastOwner": "나가거나 소유자를 내보내기 전에 다른 멤버에게 소유권을 이전하세요.",
"conflict": "다른 멤버가 설정을 변경했습니다. 새로 고침 후 다시 시도하세요.",
diff --cc apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index d35f19ae37,7938047253..48a57811f7
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@@ -9205,9 -9204,10 +9207,10 @@@
"removeHint": "该成员将无法继续查看或发消息;如果是伙伴的主人,其伙伴也会退出。",
"addCompanion": "邀请我的伙伴",
"leave": "退出群",
- "leaveHint": "你和你带来的伙伴将退出群。群主需要先转让身份。",
+ "leaveHint": "你和你的伙伴将退出此群聊,不再接收新消息,也无法查看群历史。",
+ "soleOwnerHint": "群里只剩你。可以归档群,保留历史记录,以后再恢复使用。",
"archive": "归档群",
- "archiveHint": "归档后保留群聊记录,停止新消息和伙伴执行。",
+ "archiveHint": "归档会对所有成员停用本群,停止新消息和伙伴执行。历史记录保留,之后可通过搜索找到本群、查看历史并取消归档。",
"confirm": "确认",
"lastOwner": "请先将群主转让给其他成员,再退出或移除当前群主。",
"conflict": "群设置已被其他成员更新,请刷新后重试。",
diff --cc apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index f0b57db24f,ef76f7d9f6..c3653ab163
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@@ -9205,9 -9204,10 +9207,10 @@@
"removeHint": "該成員將無法繼續查看或傳送訊息;其夥伴也會退出。",
"addCompanion": "邀請我的夥伴",
"leave": "退出群組",
- "leaveHint": "你和你帶來的夥伴將退出群組。群主需要先轉讓身分。",
+ "leaveHint": "你和你的伙伴將退出此群聊,不再接收新訊息,也無法查看群歷史。",
+ "soleOwnerHint": "群組裡只剩你。可以封存群組,保留歷史記錄,以後再恢復使用。",
"archive": "封存群組",
- "archiveHint": "封存後保留群聊記錄,停止新訊息和夥伴執行。",
+ "archiveHint": "封存會對所有成員停用本群組,停止新訊息與夥伴執行。歷史記錄保留,之後可透過搜尋找到本群組、查看歷史並取消封存。",
"confirm": "確認",
"lastOwner": "請先將群主轉讓給其他成員,再退出或移除目前的群主。",
"conflict": "群組設定已更新,請重新整理後再試。",
diff --cc docs/product-rules/bot-group-chat.md
index ed20256ca5,789cb1ec2e..1b8f97d6f2
--- a/docs/product-rules/bot-group-chat.md
+++ b/docs/product-rules/bot-group-chat.md
@@@ -374,6 -361,17 +374,17 @@@ Chris 已明确扩展到多人各带伙
当前本地验收与正式切源边界见 [Chat Server 本地联调](../dev-rules/chat-server-local-test.md)。
+ ### 群归档与找回(2026-10-14,Issue #6039)
+
+ - 群主或管理员可从 Desktop 群行右键菜单或群设置归档群;确认框明确归档会对全群停止新消息与伙伴执行,保留群历史。
+ - 默认侧栏只显示未归档群,不放常驻归档入口。输入群名或成员搜索时,结果包含已归档群并标明归档状态,可直接打开历史;即使没有任何伙伴、只剩归档群,也保留搜索能力。有管理权限的成员可从搜索结果的群行菜单或群设置取消归档,恢复默认列表中的群行与群内使用。
+ - 当前选中的群归档成功后,右侧回到未选中聊天的空态,居中显示「选择伙伴或群聊,开始对话」,群设置同时关闭;归档其他群不切换当前页面。取消、失败或等待期间已切到其他聊天时保留当前选择。通过搜索主动打开已归档群可继续查看历史,取消归档也不退出历史页。
+ - 只剩当前群主一个成员时,群设置提供归档引导,不再提供要求转让给不存在成员的退出操作。已有多人群的退出与群主转让规则不变。
+ - 归档沿用服务器已有的全群停用语义,不删除群消息或任何群专线 Session。群列表镜像仍保留归档群,隐藏只发生在默认侧栏的展示层。
-- 此次不提供永久删除、个人收起,也不增加「新消息自动取消归档」行为。归档期间服务器拒绝新消息;取消归档后才恢复。
++- 归档不提供永久删除,也不增加「新消息自动取消归档」行为;个人列表移除使用上述独立生命周期操作。归档期间服务器拒绝新消息;取消归档后才恢复。已解散群不可取消归档,侧栏菜单与群设置均不提供恢复入口。
+
+ 实现见 Desktop 的 BotsSidebar、ChatGroupSettings、BotsFeatureLayout;回归见对应群侧栏、群设置与 `botsFeatureLayout.archive.test.tsx` 测试。
+
### Thread 内唤醒伙伴的上下文
伙伴要回答的是服务端执行指定的那条源消息,不是「群里最新的一条」。执行端按源消息 ID 定位当前请求;