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: keep project aliases stable across list filters

xuzini-xzn06dd3e38857f
diff --git a/apps/desktop/src/main/cindy-brain/__tests__/libraryVault.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/libraryVault.test.ts
index 0a421c9caf..917767da92 100644
--- a/apps/desktop/src/main/cindy-brain/__tests__/libraryVault.test.ts
+++ b/apps/desktop/src/main/cindy-brain/__tests__/libraryVault.test.ts
@@ -136,10 +136,25 @@ describe('LibraryVault', () => {
const parent = path.join(tmpRoot, 'picked-owner');
const custom = path.join(parent, 'test-ghost');
await fs.promises.mkdir(parent, { recursive: true });
- const previous = makeVault({ rootDir: () => custom, locationKind: 'custom', ghostId: 'other-plugin' });
+ // Seed the persisted tree without a native helper: this unit tests the
+ // vault's owner comparison, not cold PowerShell startup (15s under CI load).
+ // Real held-fd init/open coverage remains in the custom-tree tests below.
+ const previous = makeVault({ rootDir: () => custom, ghostId: 'other-plugin' });
expect(await previous.open()).toMatchObject({ ok: true, state: 'ready' });
- const current = makeVault({ rootDir: () => custom, locationKind: 'custom' });
+ const metaFile = path.join(custom, '.cindy-library', 'meta.json');
+ const persistedMeta = await fs.promises.readFile(metaFile, 'utf8');
+ const keepFile = path.join(custom, 'keep.txt');
+ await fs.promises.writeFile(keepFile, 'private');
+ const openExistingCustom = vi.fn(async () => ({
+ ok: true as const,
+ meta: JSON.parse(await fs.promises.readFile(metaFile, 'utf8')),
+ usage: null,
+ }));
+ const current = makeVault({ rootDir: () => custom, locationKind: 'custom', openExistingCustom });
expect(await current.open()).toMatchObject({ ok: true, state: 'unavailable', reason: 'binding-moved' });
+ expect(openExistingCustom).toHaveBeenCalledOnce();
+ expect(await fs.promises.readFile(metaFile, 'utf8')).toBe(persistedMeta);
+ expect(await fs.promises.readFile(keepFile, 'utf8')).toBe('private');
});
it('open 建骨架并写 meta;重复 open 幂等', async () => {
diff --git a/packages/maker-shared/src/__tests__/projectAliasPresentation.test.ts b/packages/maker-shared/src/__tests__/projectAliasPresentation.test.ts
index ee0b7a2739..db271161f7 100644
--- a/packages/maker-shared/src/__tests__/projectAliasPresentation.test.ts
+++ b/packages/maker-shared/src/__tests__/projectAliasPresentation.test.ts
@@ -74,6 +74,43 @@ describe('project aliases in controller presentations', () => {
})[0].title).toBe('Project');
});
+ it('keeps a single-identity alias when a deleted foreign member remains in the source', () => {
+ const projectAliases = new Map([['computer-a', snapshot('Local')]]);
+ const sessions = [session('one'), session('gone', { remoteHostId: 'ssh-a', status: 'deleted' })];
+ expect(buildMobileHomePresentation({ sessions, projectAliases, searchQuery: 'Task one' }).projects[0].title)
+ .toBe('Local');
+ expect(buildRemoteSessionSections(sessions, 0, { projectAliases, searchQuery: 'Task one' })[0].title)
+ .toBe('Local');
+ });
+
+ // A project's identity comes from every member, before search/status/pinning hide rows.
+ it.each(['search', 'status', 'pinned', 'worktree'] as const)(
+ 'keeps a mixed local/SSH project title stable when %s hides its other member',
+ (filter) => {
+ const projectAliases = new Map([['computer-a', {
+ platform: 'darwin', aliases: [
+ { projectKey: 'local:/repo/Slack对话', alias: 'Local' },
+ { projectKey: 'remote:ssh-a:/repo/Slack对话', alias: 'Remote' },
+ ],
+ }]]);
+ const sessions = [session('one'), session('two', {
+ remoteHostId: 'ssh-a',
+ ...(filter === 'status' ? { status: 'archived' } : {}),
+ ...(filter === 'pinned' ? { pinnedAt: '2026-10-23T00:00:00.000Z' } : {}),
+ ...(filter === 'worktree' ? { workingDir: '/repo/Slack对话/.cindy-worktrees/example' } : {}),
+ })];
+ const options = filter === 'status' ? { statusFilter: 'active' as const }
+ : filter === 'pinned' ? {} : { searchQuery: 'Task one' };
+ const home = buildMobileHomePresentation({ sessions, projectAliases, ...options });
+ const detail = buildRemoteSessionSections(sessions, 0, { projectAliases, ...options })
+ .find(section => section.key.startsWith('project:'))!;
+ expect(home.projects[0].title).toBe('Slack对话');
+ expect(detail.title).toBe('Slack对话');
+ expect(home.projects[0].sessions.map(item => item.session.id)).toEqual(['one']);
+ expect(detail.data.map(item => item.session.id)).toEqual(['one']);
+ },
+ );
+
it.each([false, true])('never assigns a local name to an existing mixed local/SSH group (reversed=%s)', (reverse) => {
const projectAliases = new Map([['computer-a', {
platform: 'darwin', aliases: [
diff --git a/packages/maker-shared/src/mobileHome.ts b/packages/maker-shared/src/mobileHome.ts
index 5e805e1ae0..35104d52ec 100644
--- a/packages/maker-shared/src/mobileHome.ts
+++ b/packages/maker-shared/src/mobileHome.ts
@@ -217,6 +217,7 @@ export function buildMobileHomePresentation({
localizer,
),
devices,
+ normalizedSessions,
projectAliases,
);
const overview = summarizeHomeOverview(normalizedSessions, projects, pendingInteractionIndex, normalizedSelectedDeviceId);
@@ -338,8 +339,21 @@ function pickPrimaryDevice(
function buildProjectGroups(
items: readonly RemoteSessionListItem[],
devices: readonly MobileHomeDeviceLike[],
+ allSessions: readonly MobileHomeSessionLike[],
projectAliases?: ProjectAliasesByDevice,
): MobileHomeProjectGroup[] {
+ // Hidden and pinned members still define the project's identity. Filtering only
+ // changes the displayed rows, never which host/local-or-SSH name belongs to it.
+ const projectMembers = new Map<string, MobileHomeSessionLike[]>();
+ if (projectAliases) {
+ for (const session of allSessions) {
+ if (session.status === 'deleted' || isDialogueSession(session)) continue;
+ const key = projectGroupKey(session);
+ const members = projectMembers.get(key) ?? [];
+ members.push(session);
+ projectMembers.set(key, members);
+ }
+ }
const deviceNames = new Map(devices.map((device) => [device.deviceId, device.name]));
const grouped = new Map<string, RemoteSessionListItem[]>();
for (const item of items) {
@@ -375,7 +389,7 @@ function buildProjectGroups(
sessions: group,
subtitle: [deviceName, workingDir].filter(Boolean).join(' · '),
title: cindyMake ? 'Cindy Make' : resolveProjectAliasForSessions(
- group.flatMap((item) => item.automationGroup?.items.map((member) => member.session) ?? [item.session]),
+ projectMembers.get(key) ?? [],
projectAliases,
) ?? projectTitle(workingDir),
workingDir,
diff --git a/packages/maker-shared/src/sessionList.ts b/packages/maker-shared/src/sessionList.ts
index 34281d314f..4fc97ae76a 100644
--- a/packages/maker-shared/src/sessionList.ts
+++ b/packages/maker-shared/src/sessionList.ts
@@ -234,7 +234,7 @@ export function buildRemoteSessionSections(
sections.push({ key: 'pinned', title: '置顶', data: pinned });
}
- sections.push(...buildProjectSections(rest, now, groupAutomations, options.localizer, options));
+ sections.push(...buildProjectSections(rest, now, groupAutomations, options.localizer, options, sessions));
return sections;
}
@@ -395,10 +395,23 @@ function remoteSessionListHint(statusFilter: RemoteSessionStatusFilter, searchQu
function buildProjectSections(
items: readonly RemoteSessionListItem[],
now: number,
- groupAutomations = true,
- localizer?: PresentationLocalizer,
- options: RemoteSessionListOptions = {},
+ groupAutomations: boolean,
+ localizer: PresentationLocalizer | undefined,
+ options: RemoteSessionListOptions,
+ allSessions: readonly RemoteSession[],
): RemoteSessionSection[] {
+ // Use the same group key as displayed rows, but retain membership before any
+ // search/status/pinning filter so a mixed local/SSH project cannot change names.
+ const projectMembers = new Map<string, RemoteSession[]>();
+ if (options.projectAliases) {
+ for (const session of allSessions) {
+ if (session.status === 'deleted' || isDialogueSession(session)) continue;
+ const key = session.workingDir ? collapseWorktreeDirForGrouping(session.workingDir) : 'unknown';
+ const members = projectMembers.get(key) ?? [];
+ members.push(session);
+ projectMembers.set(key, members);
+ }
+ }
const dialogue = groupAutomationListItems(items.filter((item) => isDialogueSession(item.session)), now, groupAutomations, undefined, localizer);
const sections: RemoteSessionSection[] = [];
if (dialogue.length > 0) {
@@ -418,7 +431,7 @@ function buildProjectSections(
for (const [workingDir, data] of [...projectGroups].sort(([a], [b]) => compareSessionListStrings(a, b))) {
sections.push({
key: `project:${workingDir}`,
- title: resolveProjectAliasForSessions(data.map((item) => item.session), options.projectAliases, options.projectAliasDeviceId)
+ title: resolveProjectAliasForSessions(projectMembers.get(workingDir) ?? [], options.projectAliases, options.projectAliasDeviceId)
?? projectTitle(workingDir),
data: groupAutomationListItems(data, now, groupAutomations, undefined, localizer),
});