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。

feat(desktop): 任务信息按用户勾选顺序显示

Dash49a15c6d3fcc
diff --git a/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts b/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts
index cec4a6925a..a126e94eb2 100644
--- a/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts
+++ b/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts
@@ -203,14 +203,35 @@ describe('远程机器切换入口并入 SidebarTopNav(置顶段上方,固定不
);
});
+ // 2026-08-12 用户裁决:任务信息按用户勾选顺序显示(先勾时间再勾费用 → 时间在前)。
+ it('任务信息渲染顺序 = 勾选顺序,不再是固定的 pr → tokens → cost → time', () => {
+ const infoMetaSource = read('features', 'cc-agent', 'sidebar', 'SessionInfoMeta.tsx');
+ const filterCoreSource = read(
+ 'features',
+ 'cc-agent',
+ 'hooks',
+ 'helpers',
+ 'sidebarFilterCore.ts',
+ );
+
+ // 勾选状态本身按先后追加(存储即顺序),这是整条链路的源头。
+ expect(filterCoreSource).toContain('return prev.concat(field);');
+ // 拼装遍历 fields 数组,而不是走固定的 if 序列。
+ expect(infoMetaSource).toContain('for (const field of fields)');
+ // PR 也参与排序:以 'pr' 占位进入 pieces,渲染时换成徽标。
+ expect(infoMetaSource).toContain("if (field === 'pr' && hasPrRef)");
+ expect(infoMetaSource).toContain("pieces.push({ key: 'pr', text: '' })");
+ expect(infoMetaSource).toContain("piece.key === 'pr' ?");
+ // 菜单摘要的图标串同样按勾选顺序(遍历 taskInfoFields,不是遍历选项表)。
+ const filterSource = read('features', 'cc-agent', 'sidebar', 'SidebarFilterPopover.tsx');
+ expect(filterSource).toContain('{taskInfoFields.map((field) => {');
+ });
+
// 2026-08-12 用户裁决:任务信息行的当前选中项用图标表示,不再罗列短词。
it('任务信息摘要用图标串,筛选各维度行也有图标', () => {
const filterSource = read('features', 'cc-agent', 'sidebar', 'SidebarFilterPopover.tsx');
- // 摘要节点按 TASK_INFO_OPTIONS 顺序过滤已选项渲染图标;文字版留给 aria-label。
+ // 摘要节点渲染已选项的图标(顺序见上一条:按勾选顺序);文字版留给 aria-label。
expect(filterSource).toContain('valueNode={');
- expect(filterSource).toContain(
- 'TASK_INFO_OPTIONS.filter((option) => taskInfoFields.includes(option.value))',
- );
expect(filterSource).toContain('aria-label={valueNode ? value : undefined}');
// 具体维度行配图标(状态 / 项目 / Agent / 最近活跃 / 筛选 / 任务信息)。
expect(filterSource).toContain('Icon={Filter}');
diff --git a/apps/desktop/src/renderer/__tests__/sidebarSessionTime.test.ts b/apps/desktop/src/renderer/__tests__/sidebarSessionTime.test.ts
index f28663eb91..7f5c250ec9 100644
--- a/apps/desktop/src/renderer/__tests__/sidebarSessionTime.test.ts
+++ b/apps/desktop/src/renderer/__tests__/sidebarSessionTime.test.ts
@@ -92,8 +92,10 @@ describe('SessionItem activity time', () => {
expect(sessionItemSource).toContain('session.updatedAt');
// C 期起时间渲染并入 SessionInfoMeta(任务信息复选,同一 activityIso 时间轴);
// 时间文本与 text-sidebar-action-icon 色由该组件承担。
- expect(sessionItemSource).toContain(
- 'buildSessionInfoPieces(session, taskInfoFields, activityIso, t)',
+ // 2026-08-12 起多传 hasPrRef(让 PR 参与「按勾选顺序」排列),调用被 prettier
+ // 折成多行——断言收窄到函数与前四个入参。
+ expect(sessionItemSource).toMatch(
+ /buildSessionInfoPieces\(\s*session,\s*taskInfoFields,\s*activityIso,\s*t,/,
);
expect(sessionItemSource).toContain('<SessionInfoMeta pieces={infoPieces}');
expect(sessionInfoMetaSource).toContain('formatSidebarTime(activityIso, t)');
diff --git a/apps/desktop/src/renderer/features/cc-agent/hooks/helpers/sidebarFilterCore.ts b/apps/desktop/src/renderer/features/cc-agent/hooks/helpers/sidebarFilterCore.ts
index ab1baa5905..27a40728f4 100644
--- a/apps/desktop/src/renderer/features/cc-agent/hooks/helpers/sidebarFilterCore.ts
+++ b/apps/desktop/src/renderer/features/cc-agent/hooks/helpers/sidebarFilterCore.ts
@@ -61,7 +61,10 @@ export type FilterLastActivity = 'all' | '1d' | '3d' | '7d' | '30d';
* (侧边栏重设计裁决:alphabetic 与 time(旧「最早优先」)已删除,存量值回退到
* recency——时间排序只保留最近优先一档。) */
export type FilterSortBy = 'recency' | 'manual' | 'priority';
-/** 任务行右侧信息项(复选)。顺序固定 pr → tokens → cost → time 渲染。 */
+/**
+ * 任务行右侧信息项(复选)。存储数组的顺序 = 用户勾选先后(nextTaskInfoAfterToggle
+ * 按序追加),列表行据此渲染(2026-08-12 用户裁决);菜单里四个选项的排列另有固定顺序。
+ */
export type TaskInfoField = 'time' | 'pr' | 'tokens' | 'cost';
export type ManualProjectDropPosition = 'before' | 'after';
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionCard.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionCard.tsx
index d4977d15ba..acf43a7dcc 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionCard.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionCard.tsx
@@ -235,9 +235,16 @@ export function SessionCard({
const cardPreviewLineClamp = session.summary ? 3 : isRunning ? 2 : isAutomationGenerated ? 1 : 2;
// 任务信息复选(C / C' 期):卡片右下角信息槽内容,与整理菜单同源共享状态。
const { fields: taskInfoFields } = useTaskInfoFields();
- const cardInfoPieces = buildSessionInfoPieces(session, taskInfoFields, activityIso, t);
const cardPrRefs = usePrRefsForSession(session.id);
const cardInfoPrRef = taskInfoFields.includes('pr') ? cardPrRefs[0] : undefined;
+ // 传 hasPrRef 让 PR 参与「按勾选顺序」排列(否则它恒在最前)。
+ const cardInfoPieces = buildSessionInfoPieces(
+ session,
+ taskInfoFields,
+ activityIso,
+ t,
+ cardInfoPrRef != null,
+ );
// 勾选 pr 且行渲染时注册为 PR 消费者:注册即拉取(远程会话含引用补拉),
// 此后 Provider 周期/聚焦统一刷新,失败自愈(与 SessionItem 同一条路径)。
const { registerPrConsumer } = usePrActions();
@@ -1188,9 +1195,16 @@ function TimeActionsSlot({
const { t } = useTranslation();
// 任务信息复选(C / C' 期):与 SessionItem 的时间槽同源;默认仅 time 与旧渲染等价。
const { fields: taskInfoFields } = useTaskInfoFields();
- const infoPieces = buildSessionInfoPieces(session, taskInfoFields, activityIso, t);
const prRefs = usePrRefsForSession(session.id);
const infoPrRef = taskInfoFields.includes('pr') ? prRefs[0] : undefined;
+ // 传 hasPrRef 让 PR 参与「按勾选顺序」排列(否则它恒在最前)。
+ const infoPieces = buildSessionInfoPieces(
+ session,
+ taskInfoFields,
+ activityIso,
+ t,
+ infoPrRef != null,
+ );
return (
<div className="group/slot relative ml-auto flex h-5 shrink-0 items-center justify-end">
{/* 默认内容:worktree + 信息槽;hover / 菜单打开 / archivePending 时淡出让位给操作钮。 */}
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionInfoMeta.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionInfoMeta.tsx
index 945640d93e..f0c21ce43c 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionInfoMeta.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionInfoMeta.tsx
@@ -1,8 +1,10 @@
/**
* SessionInfoMeta — 任务行右侧信息槽的内容(sidebar-redesign C / C' 期)。
* ---------------------------------------------------------------------------
- * 按「任务信息」复选(useTaskInfoFields)拼装,渲染顺序固定 pr → tokens → cost →
- * time。以「·」分隔;全不选渲染 null(行右侧留空)。
+ * 按「任务信息」复选(useTaskInfoFields)拼装,**渲染顺序 = 用户勾选顺序**
+ * (2026-08-12 用户裁决,此前是固定的 pr → tokens → cost → time):勾选状态本身
+ * 就按先后追加(nextTaskInfoAfterToggle),这里遍历该数组即可。以「·」分隔;
+ * 全不选渲染 null(行右侧留空)。
*
* 数据口径:
* - pr:session_pr_refs 的最新一条(lastSeenAt 降序首位),显示「状态 icon +
@@ -54,44 +56,64 @@ export interface SessionInfoPiece {
dateTime?: string;
}
-/** 按复选拼装该会话应显示的信息片段(pr 由 SessionInfoMeta 单独渲染,不在此列)。 */
+/**
+ * 按复选拼装该会话应显示的信息片段(pr 由 SessionInfoMeta 单独渲染,不在此列)。
+ * **顺序 = 用户勾选顺序**(2026-08-12 用户裁决):fields 数组本身就按勾选先后
+ * 追加(见 nextTaskInfoAfterToggle),这里遍历它而不是走固定的 if 序列 ——
+ * 先勾时间再勾费用就显示「时间 · 费用」,反过来勾就是「费用 · 时间」。
+ * 无数据的项(token 为 0 / 无费用 / 无活动时间)照旧跳过,不占位。
+ */
export function buildSessionInfoPieces(
session: Session,
fields: readonly TaskInfoField[],
activityIso: string | undefined,
t: TFunc,
+ /** 该会话是否有 PR 引用;有才为 'pr' 排一个占位(无 PR 的行不占位)。 */
+ hasPrRef = false,
): SessionInfoPiece[] {
const pieces: SessionInfoPiece[] = [];
- if (fields.includes('tokens') && session.totalTokenUsage > 0) {
- pieces.push({
- key: 'tokens',
- text: formatCompactTokens(session.totalTokenUsage),
- title: t('ccAgent.sidebar.taskInfoTip.tokens'),
- });
- }
- if (fields.includes('cost')) {
- const money = session.totalMoney;
- if (money && money.amount > 0) {
- pieces.push({
- key: 'cost',
- text: formatMoney(money),
- title: t('ccAgent.sidebar.taskInfoTip.cost'),
- });
- } else if (session.totalCostUsd > 0) {
+ for (const field of fields) {
+ if (field === 'tokens') {
+ if (session.totalTokenUsage > 0) {
+ pieces.push({
+ key: 'tokens',
+ text: formatCompactTokens(session.totalTokenUsage),
+ title: t('ccAgent.sidebar.taskInfoTip.tokens'),
+ });
+ }
+ continue;
+ }
+ if (field === 'cost') {
+ const money = session.totalMoney;
+ if (money && money.amount > 0) {
+ pieces.push({
+ key: 'cost',
+ text: formatMoney(money),
+ title: t('ccAgent.sidebar.taskInfoTip.cost'),
+ });
+ } else if (session.totalCostUsd > 0) {
+ pieces.push({
+ key: 'cost',
+ text: formatUsd(session.totalCostUsd),
+ title: t('ccAgent.sidebar.taskInfoTip.cost'),
+ });
+ }
+ continue;
+ }
+ if (field === 'time' && activityIso) {
pieces.push({
- key: 'cost',
- text: formatUsd(session.totalCostUsd),
- title: t('ccAgent.sidebar.taskInfoTip.cost'),
+ key: 'time',
+ text: formatSidebarTime(activityIso, t),
+ title: formatSidebarTimeAbsolute(activityIso),
+ dateTime: activityIso,
});
+ continue;
+ }
+ if (field === 'pr' && hasPrRef) {
+ // 占位:PR 徽标要单独订阅状态缓存(见 PrNumberPiece),内容由 SessionInfoMeta
+ // 渲染时替换。放进 pieces 只为让它参与「按勾选顺序」排列。
+ pieces.push({ key: 'pr', text: '' });
}
- }
- if (fields.includes('time') && activityIso) {
- pieces.push({
- key: 'time',
- text: formatSidebarTime(activityIso, t),
- title: formatSidebarTimeAbsolute(activityIso),
- dateTime: activityIso,
- });
}
return pieces;
}
@@ -131,7 +153,8 @@ function PrNumberPiece({ prRef }: { prRef: SessionPrRef }) {
/**
* 信息槽内容。tabular-nums 保持数字纵向对齐;分隔点用低对比度,不与正文抢焦点。
* 调用方负责外层布局(让位动画 / 对齐),本组件只渲染内容。
- * prRef 非空时在最前渲染 PR `#号`(渲染顺序定稿:pr → tokens → cost → time)。
+ * prRef 的位置由 pieces 里的 'pr' 占位决定(= 用户勾选顺序);兼容未传
+ * hasPrRef 的旧调用:那时 pieces 里没有占位,PR 仍前置渲染。
*/
export function SessionInfoMeta({
pieces,
@@ -154,15 +177,25 @@ export function SessionInfoMeta({
className,
)}
>
- {prRef && <PrNumberPiece prRef={prRef} />}
+ {/* 顺序完全由 pieces 决定(= 用户勾选顺序);'pr' 是占位,这里换成徽标。
+ 兼容旧调用:未把 pr 排进 pieces 时(hasPrRef 未传),仍按老样子前置。 */}
+ {prRef && !pieces.some((piece) => piece.key === 'pr') && <PrNumberPiece prRef={prRef} />}
{pieces.map((piece, index) => (
<span key={piece.key} className="flex shrink-0 items-center gap-1" title={piece.title}>
- {(index > 0 || prRef) && (
+ {(index > 0 || (prRef && !pieces.some((p) => p.key === 'pr'))) && (
<span aria-hidden className="opacity-50">
·
</span>
)}
- {piece.dateTime ? <time dateTime={piece.dateTime}>{piece.text}</time> : piece.text}
+ {piece.key === 'pr' ? (
+ prRef ? (
+ <PrNumberPiece prRef={prRef} />
+ ) : null
+ ) : piece.dateTime ? (
+ <time dateTime={piece.dateTime}>{piece.text}</time>
+ ) : (
+ piece.text
+ )}
</span>
))}
</span>
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionItem.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionItem.tsx
index 36206e6fdf..83d31f57fa 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionItem.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionItem.tsx
@@ -332,9 +332,16 @@ export const SessionItem = memo(function SessionItem({
session.userSendAt && session.userSendAt > session.updatedAt
? session.userSendAt
: session.updatedAt;
- const infoPieces = buildSessionInfoPieces(session, taskInfoFields, activityIso, t);
// PR 信息(C' 期):勾选且有引用时取最新一条(prRefs 已按 lastSeenAt 降序)。
const infoPrRef = taskInfoFields.includes('pr') ? prRefs[0] : undefined;
+ // 传 hasPrRef 让 PR 参与「按勾选顺序」排列(否则它恒在最前)。
+ const infoPieces = buildSessionInfoPieces(
+ session,
+ taskInfoFields,
+ activityIso,
+ t,
+ infoPrRef != null,
+ );
// 右侧状态指示器五档优先级(高→低),色表全端统一(侧栏 / 卡片 / 灵动岛同一张表):
// 1. error(出错终止 / 定时任务失败未读)→ 红点 —— 红专职表示"坏了"
// 2. awaiting(等待回复/权限/计划审阅)→ TapTap 蓝点 —— "在等你",邀请而非告警
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/SidebarFilterPopover.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/SidebarFilterPopover.tsx
index 248aea8475..5cded4268d 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/SidebarFilterPopover.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/SidebarFilterPopover.tsx
@@ -117,7 +117,8 @@ const PROJECT_SORT_BY_OPTIONS: ReadonlyArray<Option<FilterSortBy>> = [
];
/**
- * 复选顺序即菜单显示顺序;渲染顺序固定 pr → tokens → cost → time。
+ * 本表的顺序 = 菜单里四个复选项的排列顺序(固定)。列表行的**渲染顺序**另算:
+ * 按用户勾选先后(2026-08-12 用户裁决),见 SessionInfoMeta。
* 图标对应各自的数据类型:时间=Clock(Timer 已被自动任务独占,不复用避免撞义)、
* PR=GitPullRequest(与顶栏 / 侧栏徽标未知态同一个字形)、token=Coins、费用=Wallet。
*/
@@ -634,21 +635,21 @@ export function SidebarFilterPopover({
Icon={Info}
valueNode={
taskInfoFields.length > 0 ? (
- // 已选项用图标串表示(顺序固定为 TASK_INFO_OPTIONS 的展示顺序,
- // 与列表行的渲染顺序一致),不再罗列短词。
+ // 已选项用图标串表示,不再罗列短词。顺序 = 用户勾选顺序(遍历
+ // taskInfoFields 而非选项表),与列表行的渲染顺序一致。
<span className="flex items-center justify-end gap-1">
- {TASK_INFO_OPTIONS.filter((option) => taskInfoFields.includes(option.value)).map(
- (option) =>
- option.Icon ? (
- <option.Icon
- key={option.value}
- size={13}
- strokeWidth={1.8}
- className="shrink-0"
- aria-hidden
- />
- ) : null,
- )}
+ {taskInfoFields.map((field) => {
+ const Icon = TASK_INFO_OPTIONS.find((option) => option.value === field)?.Icon;
+ return Icon ? (
+ <Icon
+ key={field}
+ size={13}
+ strokeWidth={1.8}
+ className="shrink-0"
+ aria-hidden
+ />
+ ) : null;
+ })}
</span>
) : undefined
}
diff --git a/docs/product-rules/sidebar-redesign-plan.md b/docs/product-rules/sidebar-redesign-plan.md
index 863e4b8e2e..38c1a1f3fc 100644
--- a/docs/product-rules/sidebar-redesign-plan.md
+++ b/docs/product-rules/sidebar-redesign-plan.md
@@ -131,7 +131,10 @@
- **文字版 / 列表版** 二选一,默认**列表版**(定稿)。卡片版仅置顶区支持。
- **任务信息**(一行入口,二级复选菜单):决定任务行标题右侧显示哪些信息,
- 顺序固定 PR · token · 费用 · 时间,以「·」分隔:
+ **顺序 = 用户勾选先后**(2026-08-12 用户裁决,推翻原「固定 PR · token · 费用 ·
+ 时间」),以「·」分隔——先勾时间再勾费用就显示「时间 · 费用」,反过来即相反。
+ 勾选状态本身按顺序存储,PR 也参与排列;菜单里四个复选项自身的排列顺序不变。
+ 一行入口右侧用**已选项的图标串**表示当前选择(不罗列短词):
| 项 | 默认 | 形态 |
|---|---|---|