Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 保留推荐取消逻辑并同步主干 (#3687)
qsoyq3d18b8a4511e
diff --cc apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsxindex 62253d04f5,590dd82a7d..6342de2134--- a/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx+++ b/apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx@@@ -3,7 -3,7 +3,7 @@@** Inputs: installed Ghost snapshots and user actions. `embedded` mounts the same* catalog inside Settings; `onSelectCatalogTab` keeps Plugins / Skills in-panel.-- * Outputs: the Plugin list/detail UI, focus-stable installed queue, and Plugin action flows.++ * Outputs: the Plugin list/detail UI, recommendation-aware return navigation, and Plugin action flows.* [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md*/@@@ -1265,13 -1323,8 +1335,14 @@@ export function GhostPluginPage(releaseMarketBusy(marketBusyLease);}},- [acquireMarketBusy, isMarketBusyLeaseActive, releaseMarketBusy, t],+ [acquireMarketBusy, capturePluginCatalogScroll, isMarketBusyLeaseActive, releaseMarketBusy, t],);+ const handleMarketBack = useCallback(() => {++ cancelPendingPluginSuggestion(recommendationNonce ?? undefined);+ requestPluginCatalogScrollRestore();+ marketDetailRequestRef.current += 1;+ setMarketDetail(null);- }, [requestPluginCatalogScrollRestore]);++ }, [recommendationNonce, requestPluginCatalogScrollRestore]);const refreshVisibleMarketDetail = useCallback(async (pluginId: string) => {// A background icon renewal may observe navigation, but must never invalidate a@@@ -1440,18 -1504,25 +1522,21 @@@if (marketDetail) {return (<div className="flex h-full min-h-0 w-full">- <div className="min-w-0 flex-1">- <MarketPluginDetailView- detail={marketDetail}- busy={marketBusyId === marketDetail.pluginId}- onBack={handleMarketBack}- onInstall={- canOfferMarketInstall(mode, marketDetail.ghostId)- ? () => void handleInstallFromMarket()- : undefined- }- onIconLoadError={handleMarketIconLoadError}- />+ <div className="flex min-w-0 flex-1 flex-col">+ {recommendationNotice}+ <div className="min-h-0 flex-1">+ <MarketPluginDetailView+ detail={marketDetail}+ busy={marketBusyId === marketDetail.pluginId}- onBack={() => {- cancelPendingPluginSuggestion(recommendationNonce ?? undefined);- marketDetailRequestRef.current += 1;- setMarketDetail(null);- }}++ onBack={handleMarketBack}+ onInstall={+ canOfferMarketInstall(mode, marketDetail.ghostId)+ ? () => void handleInstallFromMarket()+ : undefined+ }+ onIconLoadError={handleMarketIconLoadError}+ />+ </div></div>{panelAside}</div>@@@ -1524,9 -1600,9 +1615,10 @@@'min-h-0 w-full min-w-0 flex-1 overflow-y-auto [scrollbar-gutter:stable_both-edges]',embedded ? 'bg-transparent' : 'bg-[var(--surface)]',)}+ onScroll={onPluginCatalogScroll}><PluginManagementPage>+ {recommendationNotice}<header className="plugin-motion-page-header pb-2"><div className="min-w-0"><div className="flex flex-wrap items-center justify-between gap-3">diff --cc apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginPage.navigation.test.tsxindex 0000000000,0000000000..2352e15ea8new file mode 100644--- /dev/null+++ b/apps/desktop/src/renderer/features/plugin/__tests__/GhostPluginPage.navigation.test.tsx@@@ -1,0 -1,0 +1,195 @@@++/** @vitest-environment jsdom */++++import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';++import { MemoryRouter } from 'react-router-dom';++import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';++++import type { PluginMarketDetail } from '../../../../shared/pluginMarket';++import { __resetInstalledGhostsStoreForTest } from '@/cindy-brain/useInstalledGhosts';++import {++ cancelPendingPluginSuggestion,++ getPendingPluginSuggestion,++ readyPendingPluginSuggestion,++ startPendingPluginSuggestion,++ type PluginSuggestionRequest,++} from '@/features/cc-agent/pendingPluginSuggestion';++import { GhostPluginPage } from '../GhostPluginPage';++++const { auth, translation } = vi.hoisted(() => ({++ auth: { user: { membershipKind: 'personal' }, mode: 'local', dataOwnerId: 'navigation-owner' },++ translation: {++ t: (key: string) => key,++ i18n: { language: 'en', resolvedLanguage: 'en' },++ },++}));++++vi.mock('@/contexts/AuthContext', () => ({ useAuth: () => auth }));++vi.mock('react-i18next', async (importOriginal) => ({++ ...(await importOriginal<typeof import('react-i18next')>()),++ useTranslation: () => translation,++}));++vi.mock('@/components/ui/confirm-dialog-provider', () => ({++ useConfirmDialog: () => ({ confirm: vi.fn() }),++}));++++const detail: PluginMarketDetail = {++ pluginId: 'navigation-market-plugin',++ ghostId: 'navigation-plugin',++ name: 'Navigation Plugin',++ description: 'Navigation regression fixture',++ author: 'Cindy',++ scope: 'public',++ organizationId: null,++ defaultInstall: false,++ releaseId: 'navigation-release',++ version: '1.0.0',++ publishedAt: '2026-09-07T00:00:00.000Z',++ icon: null,++ installState: 'not-installed',++ enabled: null,++ sourceType: 'server',++ sourceMarketName: null,++ manifest: {++ schemaVersion: 2,++ id: 'navigation-plugin',++ name: 'Navigation Plugin',++ version: '1.0.0',++ kind: 'chip',++ entry: 'main.js',++ },++};++++const suggestion: PluginSuggestionRequest = {++ ownerId: 'navigation-owner',++ targetKey: 'local',++ workingDir: null,++ model: 'test',++ effort: 'medium',++ permissionMode: 'default',++ files: [],++ suggestion: {++ id: 'plugin:navigation',++ category: 'email',++ label: 'Navigation suggestion',++ prompt: 'Do not continue after returning from plugin details',++ pluginId: detail.ghostId,++ },++};++++const loadDetail = vi.fn<() => Promise<PluginMarketDetail>>();++++beforeEach(() => {++ translation.i18n.language = 'en';++ translation.i18n.resolvedLanguage = 'en';++ cancelPendingPluginSuggestion();++ __resetInstalledGhostsStoreForTest();++ loadDetail.mockReset().mockResolvedValue(detail);++ vi.stubGlobal('electronAPI', {++ platform: 'win32',++ sidebarSettings: {++ loadSnapshot: () => ({ hiddenMainViewGhostIds: [], dataOwnerId: null, ownerGeneration: 0 }),++ onHiddenMainViewGhostIdsChanged: () => () => {},++ },++ ghosts: {++ listSync: () => ({ ghosts: [] }),++ recentUsageSync: () => ({ ids: [] }),++ onChanged: () => () => {},++ onRecentUsageChanged: () => () => {},++ },++ pluginMarket: {++ snapshot: async () => ({++ items: [detail],++ unavailableReason: null,++ customSourceNames: [],++ unavailableCustomSourceNames: [],++ }),++ detail: loadDetail,++ },++ setApplicationMenuLocale: async () => {},++ });++});++++afterEach(() => {++ cleanup();++ cancelPendingPluginSuggestion();++ __resetInstalledGhostsStoreForTest();++ vi.unstubAllGlobals();++});++++function page(entry: string) {++ return (++ <MemoryRouter initialEntries={[entry]}>++ <GhostPluginPage />++ </MemoryRouter>++ );++}++++async function openFromCatalog() {++ const plugin = await screen.findByText(detail.name);++ const catalog = screen.getByRole('main');++ fireEvent.scroll(catalog, { target: { scrollTop: 640 } });++ fireEvent.click(plugin);++ await screen.findByRole('button', { name: 'settings.ghosts.detail.backToList' });++ expect(catalog.isConnected).toBe(false);++}++++describe('plugin page return navigation', () => {++ it.each(['button', 'Escape'] as const)(++ '%s cancels the recommendation and restores the catalog scroll position',++ async (method) => {++ const nonce = startPendingPluginSuggestion(suggestion);++ render(page(`/plugins?recommendation=${nonce}`));++ await openFromCatalog();++ expect(screen.getByRole('status')).toBeTruthy();++ expect(getPendingPluginSuggestion()?.nonce).toBe(nonce);++++ if (method === 'button') {++ fireEvent.click(screen.getByRole('button', { name: 'settings.ghosts.detail.backToList' }));++ } else {++ fireEvent.keyDown(window, { key: 'Escape' });++ }++++ expect(screen.getByRole('main').scrollTop).toBe(640);++ expect(++ screen.queryByRole('button', { name: 'settings.ghosts.detail.backToList' }),++ ).toBeNull();++ expect(screen.queryByRole('status')).toBeNull();++ expect(getPendingPluginSuggestion()).toBeNull();++ expect(readyPendingPluginSuggestion(nonce, suggestion.ownerId, detail.ghostId)).toBeNull();++ },++ );++++ it('restores ordinary catalog navigation without a pending recommendation', async () => {++ render(page('/plugins'));++ await openFromCatalog();++ fireEvent.keyDown(window, { key: 'Escape' });++ expect(screen.getByRole('main').scrollTop).toBe(640);++ expect(getPendingPluginSuggestion()).toBeNull();++ });++++ it('does not reopen details when a locale refresh completes after returning', async () => {++ const nonce = startPendingPluginSuggestion(suggestion);++ const mounted = render(page(`/plugins?recommendation=${nonce}`));++ await openFromCatalog();++ let finishRefresh!: (value: PluginMarketDetail) => void;++ loadDetail.mockImplementationOnce(++ () =>++ new Promise((resolve) => {++ finishRefresh = resolve;++ }),++ );++ translation.i18n.language = 'ja';++ translation.i18n.resolvedLanguage = 'ja';++ mounted.rerender(page(`/plugins?recommendation=${nonce}`));++ await waitFor(() => expect(loadDetail).toHaveBeenCalledTimes(2));++++ fireEvent.keyDown(window, { key: 'Escape' });++ await act(async () => {++ finishRefresh({ ...detail, name: 'Refreshed Plugin' });++ });++++ expect(screen.getByRole('main').scrollTop).toBe(640);++ expect(screen.queryByRole('button', { name: 'settings.ghosts.detail.backToList' })).toBeNull();++ expect(getPendingPluginSuggestion()).toBeNull();++ });++});diff --cc apps/desktop/src/renderer/features/plugin/__tests__/PluginDetailTopBar.test.tsxindex b69a9a94e7,b77c957613..42d22cd60a--- a/apps/desktop/src/renderer/features/plugin/__tests__/PluginDetailTopBar.test.tsx+++ b/apps/desktop/src/renderer/features/plugin/__tests__/PluginDetailTopBar.test.tsx@@@ -42,38 -42,6 +42,64 @@@ function Harness({ onBack = () => {} }}describe('PluginDetailTopBar', () => {+ it('returns to the owning list when Escape is pressed', () => {+ stubPlatform('darwin');+ const onBack = vi.fn();++ render(<Harness onBack={onBack} />);++ const event = new KeyboardEvent('keydown', { key: 'Escape', cancelable: true });+ window.dispatchEvent(event);++ expect(onBack).toHaveBeenCalledTimes(1);+ expect(event.defaultPrevented).toBe(true);+ });++ it('leaves Escape to editable controls, modifiers, and consumed events', () => {+ stubPlatform('darwin');+ const onBack = vi.fn();+ render(<Harness onBack={onBack} />);++ fireEvent.keyDown(window, { key: 'Escape', metaKey: true });++ const input = document.createElement('input');+ document.body.appendChild(input);+ fireEvent.keyDown(input, { key: 'Escape' });+ input.remove();++ const consumed = new KeyboardEvent('keydown', { key: 'Escape', cancelable: true });+ consumed.preventDefault();+ window.dispatchEvent(consumed);++ expect(onBack).not.toHaveBeenCalled();+ });+++ it.each(['altKey', 'ctrlKey', 'metaKey', 'shiftKey', 'isComposing'])(++ 'does not navigate back when Escape carries %s',++ (flag) => {++ const onBack = vi.fn();++ render(<Harness onBack={onBack} />);++++ fireEvent.keyDown(window, { key: 'Escape', [flag]: true });++++ expect(onBack).not.toHaveBeenCalled();++ },++ );++++ it('lets a nested surface stop Escape before it reaches the detail listener', () => {++ const onBack = vi.fn();++ render(++ <div onKeyDown={(event) => event.stopPropagation()}>++ <Harness onBack={onBack} />++ <button>Nested surface</button>++ </div>,++ );++++ fireEvent.keyDown(screen.getByRole('button', { name: 'Nested surface' }), { key: 'Escape' });++++ expect(onBack).not.toHaveBeenCalled();++ });++it('carries the window drag region on macOS and keeps the back button clickable', () => {stubPlatform('darwin');const onBack = vi.fn();