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。

fix(projects): honor renamed projects in pickers

creed05c74e1b96c1
diff --git a/apps/desktop/scripts/fixtures/project-picker-aliases/picker-fixture.tsx b/apps/desktop/scripts/fixtures/project-picker-aliases/picker-fixture.tsx
new file mode 100644
index 0000000000..a181c03fe1
--- /dev/null
+++ b/apps/desktop/scripts/fixtures/project-picker-aliases/picker-fixture.tsx
@@ -0,0 +1,44 @@
+import { useState } from 'react';
+import { useTranslation } from 'react-i18next';
+import { mountPage, subscription, ctx } from '../../ui-page/harness';
+import { useProjectPickerOptions } from '../../../src/renderer/hooks/useProjectPickerOptions';
+import { FolderPickerPopover } from '../../../src/renderer/components/new-chat/FolderPickerPopover';
+import { SessionProjectMoveSubmenu } from '../../../src/renderer/features/cc-agent/sidebar/SessionProjectMoveSubmenu';
+import { Button } from '../../../src/renderer/components/ui/button';
+import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from '../../../src/renderer/components/ui/dropdown-menu';
+
+function PickerFixture() {
+ const options = useProjectPickerOptions();
+ const [open, setOpen] = useState(false);
+ const [selected, setSelected] = useState('');
+ const { t } = useTranslation();
+ return <div className="p-8">
+ {ctx.case === 'move' ? <DropdownMenu open={open} onOpenChange={setOpen}>
+ <DropdownMenuTrigger asChild><Button data-testid="open-picker">{t('ccAgent.sidebar.sessionMenu.moveToProjectHeading')}</Button></DropdownMenuTrigger>
+ <DropdownMenuContent align="start" className="w-80">
+ <SessionProjectMoveSubmenu projectOptions={options} isDialogue onSelectProject={setSelected} />
+ </DropdownMenuContent>
+ </DropdownMenu> : <FolderPickerPopover open={open} onOpenChange={setOpen} projectOptions={options}
+ onSelect={path => setSelected(path)}>
+ <Button data-testid="open-picker">{t('newChat.folderPicker.dialogueOrSelectProject')}</Button>
+ </FolderPickerPopover>}
+ <output data-testid="selected-path" className="mt-6 block text-sm">{selected}</output>
+ </div>;
+}
+
+mountPage({
+ host: () => ({
+ platform: 'win32',
+ localDb: {
+ recentWorkdirs: { list: async () => [
+ { path: 'D:/work/cindy', exists: true, lastUsedAt: '2026-10-29T00:00:00.000Z' },
+ { path: 'D:/archive/cindy', exists: true, lastUsedAt: '2026-10-28T00:00:00.000Z' },
+ ] },
+ projectAliases: {
+ list: async () => [{ projectKey: 'local:d:/WORK/Cindy', alias: '项目新名称 · Cindy', updatedAt: '2026-10-29T00:00:00.000Z' }],
+ onChanged: subscription('project-aliases-changed'),
+ },
+ },
+ }),
+ render: () => <PickerFixture />,
+});
diff --git a/apps/desktop/scripts/fixtures/project-picker-aliases/ui-page.mjs b/apps/desktop/scripts/fixtures/project-picker-aliases/ui-page.mjs
new file mode 100644
index 0000000000..5729737780
--- /dev/null
+++ b/apps/desktop/scripts/fixtures/project-picker-aliases/ui-page.mjs
@@ -0,0 +1,21 @@
+import assert from 'node:assert/strict';
+
+export default {
+ name: 'project-picker-aliases', entry: './picker-fixture.tsx', viewport: { width: 620, height: 440 },
+ real: 'useProjectPickerOptions, useProjectAliases, FolderPickerPopover and SessionProjectMoveSubmenu',
+ notCovered: 'Real database persistence, full new-task submission and task relocation; fixture host supplies saved aliases and paths.',
+ cases: {
+ default: { about: 'New-task project picker displays the saved alias and selects the original directory' },
+ move: { about: 'Move-task menu displays the same saved alias and selects the original directory' },
+ },
+ async ready(page) { await page.getByTestId('open-picker').waitFor(); },
+ async check(page, ui) {
+ await page.getByTestId('open-picker').click();
+ await page.getByText('D:/work/cindy', { exact: true }).waitFor();
+ await ui.capture('project-menu');
+ const renamed = page.getByText('项目新名称 · Cindy', { exact: true });
+ assert.equal(await renamed.count(), 1, 'Saved alias must appear in the actual project menu');
+ await renamed.click();
+ assert.equal(await page.getByTestId('selected-path').textContent(), 'D:/work/cindy');
+ },
+};
diff --git a/apps/desktop/src/renderer/features/cc-agent/hooks/__tests__/useProjectAliases.test.tsx b/apps/desktop/src/renderer/features/cc-agent/hooks/__tests__/useProjectAliases.test.tsx
index b525788001..26f5b5b38f 100644
--- a/apps/desktop/src/renderer/features/cc-agent/hooks/__tests__/useProjectAliases.test.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/hooks/__tests__/useProjectAliases.test.tsx
@@ -5,6 +5,11 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
import type { ProjectAlias } from '../../../../../shared/projectAliases';
import { useProjectAliases } from '../useProjectAliases';
+import { useProjectPickerOptions, getProjectPickerDisplayName } from '@/hooks/useProjectPickerOptions';
+import { extractDisplayName } from '../../lib/projectGrouping';
+
+const recent = vi.hoisted(() => ({ entries: [] as Array<{ path: string; exists: boolean }> }));
+vi.mock('@/hooks/useRecentWorkdirs', () => ({ useRecentWorkdirs: () => recent }));
const service = vi.hoisted(() => ({
list: vi.fn<() => Promise<ProjectAlias[]>>(),
@@ -34,7 +39,7 @@ const LEGACY_ROWS: ProjectAlias[] = [
beforeEach(() => {
service.list.mockReset().mockResolvedValue(LEGACY_ROWS);
service.set.mockReset().mockResolvedValue(null);
- service.subscribe.mockClear();
+ service.subscribe.mockReset().mockImplementation(() => () => {});
(window as unknown as { electronAPI: unknown }).electronAPI = { platform: 'win32' };
});
@@ -68,3 +73,64 @@ describe('useProjectAliases Windows comparison identity', () => {
]);
});
});
+
+
+describe('project picker aliases (#7831)', () => {
+ it('loads persisted Windows aliases with sidebar identity rules without changing paths', async () => {
+ recent.entries = [{ path: 'd:\\ÉCOLE\\project-a\\', exists: false }, { path: '\\\\SERVER\\Share\\App', exists: true }];
+ service.list.mockResolvedValue([...LEGACY_ROWS, {
+ projectKey: 'local://server/share/app', alias: ' Shared app ', updatedAt: '2026-08-13T01:00:00.000Z',
+ }]);
+ const view = renderHook(() => useProjectPickerOptions());
+ await waitFor(() => expect(view.result.current.map(p => p.name)).toEqual(['Newest alias', 'Shared app']));
+ expect(view.result.current.map(p => ({ path: p.path, missing: p.missing, description: p.description }))).toEqual([
+ { path: 'd:\\ÉCOLE\\project-a\\', missing: true, description: 'd:/ÉCOLE/project-a/' },
+ { path: '\\\\SERVER\\Share\\App', missing: false, description: '//SERVER/Share/App' },
+ ]);
+ expect(getProjectPickerDisplayName(recent.entries[0].path, view.result.current)).toBe('Newest alias');
+ view.unmount();
+ });
+
+ it('updates an already-open picker on rename and clear, and loads the saved name on remount', async () => {
+ recent.entries = [{ path: '/work/app', exists: true }];
+ service.list.mockResolvedValue([]);
+ let notify = () => {};
+ service.subscribe.mockImplementation(listener => { notify = listener; return () => {}; });
+ const view = renderHook(() => useProjectPickerOptions());
+ await act(async () => {});
+ expect(view.result.current[0].name).toBe('app');
+ const saved = [{ projectKey: 'local:/work/app', alias: 'Renamed project', updatedAt: '2026-08-13T01:00:00.000Z' }];
+ service.list.mockResolvedValue(saved);
+ await act(async () => notify());
+ expect(view.result.current[0]).toMatchObject({ name: 'Renamed project', path: '/work/app' });
+ view.unmount();
+ const reopened = renderHook(() => useProjectPickerOptions());
+ await waitFor(() => expect(reopened.result.current[0].name).toBe('Renamed project'));
+ service.list.mockResolvedValue([]);
+ await act(async () => notify());
+ expect(reopened.result.current[0]).toMatchObject({ name: 'app', path: '/work/app' });
+ reopened.unmount();
+ });
+
+ it('keeps unaliased names disambiguated and does not borrow a remote project alias', async () => {
+ recent.entries = [{ path: '/one/app', exists: true }, { path: '/two/app', exists: true }];
+ service.list.mockResolvedValue([
+ { projectKey: 'remote:host:/one/app', alias: 'Remote only', updatedAt: '' },
+ { projectKey: 'local:/two/app', alias: ' ', updatedAt: '' },
+ ]);
+ const view = renderHook(() => useProjectPickerOptions());
+ await act(async () => {});
+ const paths = recent.entries.map(p => p.path);
+ expect(view.result.current.map(p => p.name)).toEqual(paths.map(p => extractDisplayName(p, paths).name));
+ view.unmount();
+ });
+
+ it('keeps local POSIX paths case-sensitive', async () => {
+ (window as unknown as { electronAPI: unknown }).electronAPI = { platform: 'linux' };
+ recent.entries = [{ path: '/work/App', exists: true }, { path: '/work/app', exists: true }];
+ service.list.mockResolvedValue([{ projectKey: 'local:/work/App', alias: 'Uppercase project', updatedAt: '' }]);
+ const view = renderHook(() => useProjectPickerOptions());
+ await waitFor(() => expect(view.result.current.map(p => p.name)).toEqual(['Uppercase project', 'app']));
+ view.unmount();
+ });
+});
diff --git a/apps/desktop/src/renderer/features/cc-agent/lib/projectGrouping.ts b/apps/desktop/src/renderer/features/cc-agent/lib/projectGrouping.ts
index cd7fbf8eae..f6e1d15689 100644
--- a/apps/desktop/src/renderer/features/cc-agent/lib/projectGrouping.ts
+++ b/apps/desktop/src/renderer/features/cc-agent/lib/projectGrouping.ts
@@ -37,7 +37,7 @@ import { getSessionListActivityAt } from '@cindy/maker-shared/session-activity';
* 全部纯函数;输入为空 / 异常 → 静默返回合理默认。
*/
-import { extractDisplayName, splitPathSegments, tailJoin } from '../../../../shared/projectDisplayName';
+import { splitPathSegments, tailJoin } from '../../../../shared/projectDisplayName';
export { extractDisplayName } from '../../../../shared/projectDisplayName';
import type { DeviceLinkConnectionStatus, Session } from '@/lib/ccAgent.types';
@@ -358,7 +358,7 @@ function extractDisplayNameFromIndex(
return { name: fallback, segments: maxSegments };
}
-function normalizeProjectAliases(
+export function normalizeProjectAliases(
raw: GroupSessionsOptions['projectAliases'],
localPlatform: string,
): Map<string, string> {
diff --git a/apps/desktop/src/renderer/hooks/useProjectPickerOptions.ts b/apps/desktop/src/renderer/hooks/useProjectPickerOptions.ts
index 985d8ceb8f..db3c380c0d 100644
--- a/apps/desktop/src/renderer/hooks/useProjectPickerOptions.ts
+++ b/apps/desktop/src/renderer/hooks/useProjectPickerOptions.ts
@@ -1,7 +1,8 @@
import { useMemo } from 'react';
import type { FolderPickerOption } from '@/components/new-chat/FolderPickerPopover';
-import { extractDisplayName } from '@/features/cc-agent/lib/projectGrouping';
+import { extractDisplayName, normalizeProjectAliases, projectIdentityKey, projectKeyComparisonKey } from '@/features/cc-agent/lib/projectGrouping';
+import { useProjectAliases } from '@/features/cc-agent/hooks/useProjectAliases';
import { useRecentWorkdirs } from '@/hooks/useRecentWorkdirs';
export type ProjectPickerEmptyLabelMode = 'generic' | 'dialogue';
@@ -18,20 +19,25 @@ function toPosixPath(p: string): string {
*/
export function useProjectPickerOptions(): FolderPickerOption[] {
const { entries } = useRecentWorkdirs();
+ const { aliases } = useProjectAliases();
+ const localPlatform = window.electronAPI.platform;
return useMemo<FolderPickerOption[]>(() => {
+ const projectAliases = normalizeProjectAliases(aliases, localPlatform);
const posixAll = entries.map((entry) => toPosixPath(entry.path));
return entries.map((entry, idx) => {
const posix = posixAll[idx];
const { name } = extractDisplayName(posix, posixAll);
+ const projectKey = projectIdentityKey('local', entry.path, null);
+ const alias = projectAliases.get(projectKeyComparisonKey(projectKey, localPlatform) ?? projectKey);
return {
path: entry.path,
- name,
+ name: alias ?? name,
description: posix,
missing: entry.exists === false,
};
});
- }, [entries]);
+ }, [entries, aliases, localPlatform]);
}
export function getProjectPickerDisplayName(