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(desktop): 隐藏独立任务的重复来源标签 (#4342)

Dash14ad93a18f2f
diff --git a/apps/desktop/src/renderer/__tests__/sessionSourceLabel.test.ts b/apps/desktop/src/renderer/__tests__/sessionSourceLabel.test.ts
index 86e8940a9b..3a7635603d 100644
--- a/apps/desktop/src/renderer/__tests__/sessionSourceLabel.test.ts
+++ b/apps/desktop/src/renderer/__tests__/sessionSourceLabel.test.ts
@@ -1,7 +1,7 @@
/**
* sessionSourceLabel — vitest unit tests
*
- * 覆盖 buildSessionSourceLabelMap 的四条分支:dialogue label / ProjectNode 命中 /
+ * 覆盖 buildSessionSourceLabelMap 的分支:独立对话不标 / ProjectNode 命中 /
* workingDir basename 回退(POSIX + Windows 分隔符)/ 拿不到来源时不注入。
* 该 helper 由 DateGroupedSessionsSection 与 PinnedSection 共用,提取自两处
* 原本逐字节重复的 useMemo(PR #533 follow-up)。
@@ -69,55 +69,53 @@ function projectNodeFor(session: Session, displayName: string): ProjectNode {
};
}
-const DIALOGUE = '对话';
-
/* ============================== tests ============================== */
describe('buildSessionSourceLabelMap', () => {
- it('maps dialogue sessions to the provided dialogue label', () => {
+ it('does not label standalone dialogue sessions', () => {
const d = s({ id: 'd1', workspaceKind: 'dialogue' });
- const map = buildSessionSourceLabelMap([d], [], DIALOGUE);
- expect(map.get('d1')).toBe(DIALOGUE);
+ const map = buildSessionSourceLabelMap([d], []);
+ expect(map.has('d1')).toBe(false);
});
it('uses the matching ProjectNode displayName for a project session', () => {
const p = s({ id: 'p1', workspaceKind: 'project', workingDir: '/home/me/repo-a' });
const node = projectNodeFor(p, 'parent/repo-a');
- const map = buildSessionSourceLabelMap([p], [node], DIALOGUE);
+ const map = buildSessionSourceLabelMap([p], [node]);
expect(map.get('p1')).toBe('parent/repo-a');
});
it('falls back to POSIX workingDir basename when no ProjectNode matches', () => {
const p = s({ id: 'p2', workspaceKind: 'project', workingDir: '/home/me/my-proj' });
- const map = buildSessionSourceLabelMap([p], [], DIALOGUE);
+ const map = buildSessionSourceLabelMap([p], []);
expect(map.get('p2')).toBe('my-proj');
});
it('falls back to Windows workingDir basename (backslash separator)', () => {
const p = s({ id: 'p3', workspaceKind: 'project', workingDir: 'D:\\code\\win-proj' });
- const map = buildSessionSourceLabelMap([p], [], DIALOGUE);
+ const map = buildSessionSourceLabelMap([p], []);
expect(map.get('p3')).toBe('win-proj');
});
it('does not inject a label when a project session has no workingDir', () => {
const p = s({ id: 'p4', workspaceKind: 'project', workingDir: null });
- const map = buildSessionSourceLabelMap([p], [], DIALOGUE);
+ const map = buildSessionSourceLabelMap([p], []);
expect(map.has('p4')).toBe(false);
});
- it('handles a mixed batch, only injecting resolvable sources', () => {
+ it('handles a mixed batch, only injecting resolvable project sources', () => {
const d = s({ id: 'm-d', workspaceKind: 'dialogue' });
const named = s({ id: 'm-named', workspaceKind: 'project', workingDir: '/x/named-proj' });
const node = projectNodeFor(named, 'named-proj');
const fallback = s({ id: 'm-fb', workspaceKind: 'project', workingDir: '/x/fallback-proj' });
const empty = s({ id: 'm-empty', workspaceKind: 'project', workingDir: null });
- const map = buildSessionSourceLabelMap([d, named, fallback, empty], [node], DIALOGUE);
+ const map = buildSessionSourceLabelMap([d, named, fallback, empty], [node]);
- expect(map.get('m-d')).toBe(DIALOGUE);
+ expect(map.has('m-d')).toBe(false);
expect(map.get('m-named')).toBe('named-proj');
expect(map.get('m-fb')).toBe('fallback-proj');
expect(map.has('m-empty')).toBe(false);
- expect(map.size).toBe(3);
+ expect(map.size).toBe(2);
});
});
diff --git a/apps/desktop/src/renderer/features/cc-agent/lib/sessionSourceLabel.ts b/apps/desktop/src/renderer/features/cc-agent/lib/sessionSourceLabel.ts
index 49daa65944..948e5dc9a8 100644
--- a/apps/desktop/src/renderer/features/cc-agent/lib/sessionSourceLabel.ts
+++ b/apps/desktop/src/renderer/features/cc-agent/lib/sessionSourceLabel.ts
@@ -3,29 +3,25 @@ import type { Session } from '@/lib/ccAgent.types';
import { normalizeWorkingDir, projectIdentityKeyForSession, type ProjectNode } from './projectGrouping';
/**
- * 构建 session → "项目来源"标签映射,供文字模式 SessionItem hover 时右侧浮层展示。
+ * 构建 session → "项目来源"标签映射,供平铺时标题旁展示。
*
- * 口径(时间排序视图与置顶视图共用,保持一致):
- * - dialogue → 传入的 `dialogueLabel`(已 i18n 解析,保持本函数 i18n-agnostic / 纯函数);
+ * 口径(主列表与置顶视图共用,保持一致):
+ * - dialogue → 不注入(独立对话本身不需要再标「对话」);
* - project → 命中 ProjectNode 就用其 displayName(消歧后可能带父目录段);
* - orca-lead / 罕见来源找不到 ProjectNode 时 → 回退 workingDir basename;
- * - 都拿不到 → 不注入(map 里无该 session key),SessionTooltip 直接透传行。
+ * - 都拿不到 → 不注入(map 里无该 session key),标题旁不画来源。
*
* 纯函数、无 React 依赖:调用方各自用 useMemo 包裹并传入自己的 session 数组
- * (时间视图传全量 sessions,置顶视图传 slicedSessions),memo 依赖各自维护。
+ * (主列表传散排会话,置顶视图传 visibleSessions),memo 依赖各自维护。
*/
export function buildSessionSourceLabelMap(
sessions: readonly Session[],
allKnownProjects: readonly ProjectNode[],
- dialogueLabel: string,
): Map<string, string> {
const nameByKey = new Map(allKnownProjects.map((p) => [p.projectKey, p.displayName]));
const map = new Map<string, string>();
for (const s of sessions) {
- if (s.workspaceKind === 'dialogue') {
- map.set(s.id, dialogueLabel);
- continue;
- }
+ if (s.workspaceKind === 'dialogue') continue;
const key = projectIdentityKeyForSession(s);
const name = key ? nameByKey.get(key) : undefined;
if (name) {
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/PinnedSection.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/PinnedSection.tsx
index 7d5ca136be..3cfaf7f53b 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/PinnedSection.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/PinnedSection.tsx
@@ -210,9 +210,8 @@ export function PinnedSection({
// 平铺时标题旁的"项目来源"标签(口径见 buildSessionSourceLabelMap)。
// 置顶视图传 visibleSessions;文字 / 列表都画,card 变体不画这个标签。
const sourceLabelMap = useMemo(
- () =>
- buildSessionSourceLabelMap(visibleSessions, allKnownProjects, t('ccAgent.sidebar.dialogues')),
- [visibleSessions, allKnownProjects, t],
+ () => buildSessionSourceLabelMap(visibleSessions, allKnownProjects),
+ [visibleSessions, allKnownProjects],
);
const getEntryId = useCallback((entry: PinnedSidebarEntry) => entry.id, []);
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/ProjectsSection.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/ProjectsSection.tsx
index d93605639a..6a2775b594 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/ProjectsSection.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/sections/ProjectsSection.tsx
@@ -795,13 +795,8 @@ export function ProjectsSection({
return [...projects.flatMap((project) => project.sessions), ...dialogues];
}, [filter.groupBy, projects, dialogues]);
const dialogueSourceLabelMap = useMemo(
- () =>
- buildSessionSourceLabelMap(
- flattenedSessionsForSourceLabels,
- allKnownProjects,
- t('ccAgent.sidebar.dialogues'),
- ),
- [flattenedSessionsForSourceLabels, allKnownProjects, t],
+ () => buildSessionSourceLabelMap(flattenedSessionsForSourceLabels, allKnownProjects),
+ [flattenedSessionsForSourceLabels, allKnownProjects],
);
// F-PJ-10:即使 projects 因 filter 收窄到空,也要保留段头供用户切回 Filter。
diff --git a/docs/product-rules/sidebar-redesign-plan.md b/docs/product-rules/sidebar-redesign-plan.md
index 101cb48301..06707bb245 100644
--- a/docs/product-rules/sidebar-redesign-plan.md
+++ b/docs/product-rules/sidebar-redesign-plan.md
@@ -251,7 +251,7 @@ More/Archive,复用 `TimeActionsSlot`),行 2 = 固定 1 行预览;整行恒两
列表标题与文字模式同档:`text-sm` / 14px / medium;预览、来源标签与右侧信息槽
用 `text-xs` / 12px。列表右侧时间 / 远程小标与文字模式同一套 token 和尺寸
(`sidebar-action-icon`,远程标 12px)。平铺时两种模式都在标题旁显示项目来源标签;
-按项目分组时不重复写。置顶卡片版仍用 12px 标题,不跟这次对齐。
+独立对话不标「对话」。按项目分组时不重复写。置顶卡片版仍用 12px 标题,不跟这次对齐。
## 6. 「展开/收起所有分组」按钮