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): 提高草稿铅笔标记可见度 (#2896)

Dash6275560776fb
diff --git a/apps/desktop/src/renderer/__tests__/sidebarAttentionBadge.test.ts b/apps/desktop/src/renderer/__tests__/sidebarAttentionBadge.test.ts
index fbf8b10278..81d9b32f96 100644
--- a/apps/desktop/src/renderer/__tests__/sidebarAttentionBadge.test.ts
+++ b/apps/desktop/src/renderer/__tests__/sidebarAttentionBadge.test.ts
@@ -18,6 +18,11 @@ import type { Session } from '@/lib/ccAgent.types';
import { resolveSidebarRightStatus } from '../features/cc-agent/sidebar/sidebarRightStatus';
import { SessionStatusIcon } from '../features/cc-agent/sidebar/SessionStatusIcon';
+const sidebarState = vi.hoisted(() => ({
+ hasDraft: false,
+ hasPausedQueue: false,
+}));
+
vi.mock('react-i18next', () => ({
initReactI18next: {
type: '3rdParty',
@@ -27,11 +32,11 @@ vi.mock('react-i18next', () => ({
}));
vi.mock('@/hooks/useComposerDraftPresence', () => ({
- useComposerDraftPresence: () => false,
+ useComposerDraftPresence: () => sidebarState.hasDraft,
}));
vi.mock('@/hooks/useSessionPausedQueue', () => ({
- useSessionPausedQueue: () => false,
+ useSessionPausedQueue: () => sidebarState.hasPausedQueue,
}));
vi.mock('@/components/sidebar/VendorIcon', () => ({
@@ -42,6 +47,8 @@ vi.mock('@/components/sidebar/VendorIcon', () => ({
afterEach(() => {
cleanup();
+ sidebarState.hasDraft = false;
+ sidebarState.hasPausedQueue = false;
});
const session = {
@@ -147,3 +154,23 @@ describe('sidebar attention badge', () => {
expect(attentionDot(container)).toBeUndefined();
});
});
+
+describe('sidebar draft indicator', () => {
+ it('uses the dedicated high-contrast color for unsent content', () => {
+ sidebarState.hasDraft = true;
+
+ const { getByTitle } = render(
+ createElement(SessionStatusIcon, {
+ session,
+ isRunning: false,
+ isAttached: false,
+ hasAttentionNotification: false,
+ isActive: false,
+ }),
+ );
+
+ expect(getByTitle('ccAgent.sidebar.hasDraft').className).toContain(
+ 'text-[var(--sidebar-draft-indicator)]',
+ );
+ });
+});
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/RailNav.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/RailNav.tsx
index bc6b6f1843..047db79a58 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/RailNav.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/RailNav.tsx
@@ -354,7 +354,7 @@ export function RailNav({
// 反相胶囊主题下混用功能钮 chip-bg 会得到白字浮浅灰的断层)。
isActive
? 'bg-sidebar-item-active border border-[var(--sidebar-item-active-border)]'
- : 'text-[hsl(var(--titlebar-icon))] group-hover/pin:bg-[var(--update-btn-hover)]',
+ : 'text-[hsl(var(--titlebar-icon))] group-hover/pin:bg-sidebar-item-hover',
)}
>
<SessionStatusIcon
@@ -425,7 +425,7 @@ export function RailNav({
'relative flex h-9 w-9 shrink-0 items-center justify-center rounded-full transition-colors duration-150',
panelState.openSection === key
? 'bg-[var(--chat-input-chip-bg)] text-[var(--msg-assistant-text)]'
- : 'text-[hsl(var(--titlebar-icon))] hover:bg-[var(--update-btn-hover)]',
+ : 'text-[hsl(var(--titlebar-icon))] hover:bg-sidebar-item-hover',
)}
>
<span
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionStatusIcon.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionStatusIcon.tsx
index 966af012bb..04b408081b 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionStatusIcon.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionStatusIcon.tsx
@@ -151,7 +151,7 @@ export function SessionStatusIcon({
)}
{showDraftIndicator && (
<span
- className="absolute -bottom-0.5 -right-0.5 text-[var(--text-secondary)]"
+ className="absolute -bottom-0.5 -right-0.5 text-[var(--sidebar-draft-indicator)]"
aria-label={draftIndicatorLabel}
title={draftIndicatorLabel}
role="img"
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/sessionCardReviewRegressions.test.ts b/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/sessionCardReviewRegressions.test.ts
index dc6f543ef6..2bd1aec696 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/sessionCardReviewRegressions.test.ts
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/__tests__/sessionCardReviewRegressions.test.ts
@@ -7,6 +7,7 @@ const sidebarDir = resolve(__dirname, '..');
const sessionCardSource = readFileSync(resolve(sidebarDir, 'SessionCard.tsx'), 'utf8');
const sessionEntryListSource = readFileSync(resolve(sidebarDir, 'SessionEntryList.tsx'), 'utf8');
const sessionItemSource = readFileSync(resolve(sidebarDir, 'SessionItem.tsx'), 'utf8');
+const railNavSource = readFileSync(resolve(sidebarDir, 'RailNav.tsx'), 'utf8');
const sessionRenameInputSource = readFileSync(
resolve(sidebarDir, '..', 'SessionRenameInput.tsx'),
'utf8',
@@ -321,6 +322,12 @@ describe('SessionCard review regressions', () => {
);
});
+ it('keeps rail hover backgrounds in the sidebar token family', () => {
+ expect(railNavSource).toContain('group-hover/pin:bg-sidebar-item-hover');
+ expect(railNavSource).toContain('hover:bg-sidebar-item-hover');
+ expect(railNavSource).not.toContain('update-btn-hover');
+ });
+
it('keeps selected sidebar hover actions inside the active color system', () => {
expect(sessionItemSource).toContain('isActive={isActive}');
expect(sessionItemSource).toContain(
diff --git a/apps/desktop/src/renderer/themes/__tests__/cindyThemes.test.ts b/apps/desktop/src/renderer/themes/__tests__/cindyThemes.test.ts
index 96a1776bcb..1f63cd462a 100644
--- a/apps/desktop/src/renderer/themes/__tests__/cindyThemes.test.ts
+++ b/apps/desktop/src/renderer/themes/__tests__/cindyThemes.test.ts
@@ -70,6 +70,30 @@ function parseRgb(v: string): RGB {
return [parts[0], parts[1], parts[2]];
}
+function parseCssColor(v: string | undefined): { rgb: RGB; alpha: number } {
+ if (!v) throw new Error('empty color literal');
+ const t = v.trim();
+ const hsl = t.match(
+ /^([\d.]+)\s+([\d.]+)%\s+([\d.]+)%(?:\s*\/\s*(0|1|0?\.\d+))?$/,
+ );
+ if (hsl) {
+ return {
+ rgb: hslToRgb(parseFloat(hsl[1]), parseFloat(hsl[2]), parseFloat(hsl[3])),
+ alpha: hsl[4] === undefined ? 1 : parseFloat(hsl[4]),
+ };
+ }
+ const rgb = t.match(/^rgba?\(([^)]+)\)$/);
+ if (rgb) {
+ const parts = rgb[1].split(',').map((x) => parseFloat(x));
+ return {
+ rgb: [parts[0], parts[1], parts[2]],
+ alpha: parts[3] === undefined ? 1 : parts[3],
+ };
+ }
+ if (t === 'transparent') return { rgb: [0, 0, 0], alpha: 0 };
+ return { rgb: toRgb(t), alpha: 1 };
+}
+
/** 把任意 CSS 色值归一成 RGB(hex / HSL 三元组 / rgb() / rgba())。 */
function toRgb(v: string | undefined): RGB {
if (!v) throw new Error("empty color literal");
@@ -95,13 +119,22 @@ function luminance(rgb: RGB): number {
return 0.2126 * f[0] + 0.7152 * f[1] + 0.0722 * f[2];
}
-function contrast(c1: string | undefined, c2: string | undefined): number {
- const l1 = luminance(toRgb(c1));
- const l2 = luminance(toRgb(c2));
+function compositeOver(foreground: string | undefined, background: RGB): RGB {
+ const { rgb, alpha } = parseCssColor(foreground);
+ return rgb.map((channel, index) => channel * alpha + background[index] * (1 - alpha)) as RGB;
+}
+
+function rgbContrast(c1: RGB, c2: RGB): number {
+ const l1 = luminance(c1);
+ const l2 = luminance(c2);
const [hi, lo] = l1 > l2 ? [l1, l2] : [l2, l1];
return (hi + 0.05) / (lo + 0.05);
}
+function contrast(c1: string | undefined, c2: string | undefined): number {
+ return rgbContrast(toRgb(c1), toRgb(c2));
+}
+
const BRAND_RED_HEX = '#DF0C27';
type CindyTheme = { colors: Record<string, string> };
const THEMES: ReadonlyArray<readonly [string, CindyTheme]> = [
@@ -436,6 +469,35 @@ describe('CINDY · ⑦ WCAG 复算 + U2 例外 allowlist + text-secondary 反向
expect(contrast(cindyLight.colors['sidebar-item-active-foreground']!, cindyLight.colors['sidebar-item-active']!), 'light 选中胶囊 前景×中性底').toBeGreaterThanOrEqual(4.5);
expect(contrast(cindyDark.colors['sidebar-item-active-foreground']!, cindyDark.colors['sidebar-item-active']!), 'dark 选中胶囊 前景×中性底').toBeGreaterThanOrEqual(4.5);
});
+
+ it('CINDY 侧栏草稿铅笔×普通/悬停行底色对比度 ≥3:1', () => {
+ const draftLight = colorRegistry.resolveDefault('sidebar-draft-indicator', 'light') ?? '';
+ const draftDarkAlias = colorRegistry.resolveDefault('sidebar-draft-indicator', 'dark') ?? '';
+ const awaitingDark = colorRegistry.resolveDefault('card-status-awaiting', 'dark') ?? '';
+
+ expect(draftLight).toBe('#0B726B');
+ expect(draftDarkAlias).toBe('var(--card-status-awaiting)');
+ for (const [name, colors, draft] of [
+ ['light', light, draftLight],
+ ['dark', dark, awaitingDark],
+ ] as const) {
+ for (const [wallpaperName, wallpaper] of [
+ ['black wallpaper', '#000000'],
+ ['white wallpaper', '#FFFFFF'],
+ ] as const) {
+ const sidebar = compositeOver(colors['surface-translucent-sidebar'], toRgb(wallpaper));
+ const hover = compositeOver(colors['sidebar-item-hover'], sidebar);
+ expect(
+ rgbContrast(toRgb(draft), sidebar),
+ `${name} 草稿铅笔×侧栏(${wallpaperName})`,
+ ).toBeGreaterThanOrEqual(3);
+ expect(
+ rgbContrast(toRgb(draft), hover),
+ `${name} 草稿铅笔×悬停行(${wallpaperName})`,
+ ).toBeGreaterThanOrEqual(3);
+ }
+ }
+ });
});
// ===== ⑧ 可证伪自检 =====
diff --git a/apps/desktop/src/renderer/themes/colors.ts b/apps/desktop/src/renderer/themes/colors.ts
index 2383afe5fe..24c9be30c9 100644
--- a/apps/desktop/src/renderer/themes/colors.ts
+++ b/apps/desktop/src/renderer/themes/colors.ts
@@ -1720,6 +1720,10 @@ registerColor('card-status-awaiting', {
light: '#19D2C1',
dark: '#19D2C1',
}, '状态点 — 待用户回复/选择 (设计定稿 2026-07-17 #19D2C1,取代 #00D9C5 冻结红线;light/dark 同值)');
+registerColor('sidebar-draft-indicator', {
+ light: '#0B726B',
+ dark: 'var(--card-status-awaiting)',
+}, '侧边栏草稿/暂停队列铅笔 — light 深青保证透明侧栏上的小图形对比度,dark 复用 awaiting 青色');
registerColor('card-status-error', {
light: '#D91F37',
dark: '#D91F37',
diff --git a/docs/design-rules/DESIGN.md b/docs/design-rules/DESIGN.md
index 23375cd6fe..ca08204aae 100644
--- a/docs/design-rules/DESIGN.md
+++ b/docs/design-rules/DESIGN.md
@@ -1046,6 +1046,7 @@ See the skin decision table §2 (design-stage working file, not in repo). The Li
- Semantic colors: `warning-accent` `#EA6B17` (finalized 2026-07-17, replaces `#FF6600`) / `annotation-accent` `#FF3B30` (image-annotation burn-in ink — exempt, do not change) / `status-bar-accent` (alias of warning orange, auto-follows).
- The status four (finalized 2026-07-17; same values both modes, all 9 themes follow with no override): running `#EA6B17` / awaiting `#19D2C1` / error (status family) `#D91F37` / done `#2AAE5B`; warning foreground `warning-fg` `#F3A115` (decoupled from Toast amber `#F59E0B` — Toast keeps its group-B status quo).
+- `sidebar-draft-indicator` is a narrow semantic exception for the 8px pencil shown on non-selected sidebar rows with a composer draft or paused send queue. Light uses deep teal `#0B726B`; dark aliases `card-status-awaiting` (`#19D2C1`). Both must remain ≥3:1 against ordinary and hover CINDY sidebar surfaces after the translucent sidebar is composited over black and white wallpaper extremes (worst case at registration: `3.17:1` light / `5.65:1` dark). Rail tiles therefore use `--sidebar-item-hover`, never the inverse upgrade-button-only `--update-btn-hover`. Do not reuse the indicator token for generic awaiting states or add an active-row variant; the pencil is intentionally hidden while that task is selected.
- `focus-ring` `#417CDD` (blue — never red); diff red/green; modal scrim/shadows; `overlay-lightbox`; the four Toast colors.
- `destructive` / `search-match-bg` stay outside HSL_FORMAT_IDS coverage.
- **hljs syntax colors** (light = highlight.js `github.css`; dark = globals.css `.dark .hljs-*` mirroring github-dark) — dual-threshold ruling (2026-07-17): syntax colors ≥3:1, body text ≥4.5:1. The hljs palettes were designed for GitHub's default canvases; CINDY's code-block canvas (`surface-elevated`, since 2026-08 `#FDFDF8`/`#1F1F1F`; code block fill `perm-code-bg` `#FAFAF5`/`#191919`) sits close to default's, so marginal shortfalls are inherited, not CINDY-introduced (default is equally affected). Light: all syntax colors ≥3 — no remediation, itemized as exemptions. Dark: `[data-theme="cindy-dark"]` overrides `.hljs-section` to `#2573ec` (3.00:1 on the pre-2026-08 canvas; 3.72:1 after the darker revision — margins only improved, override retained) and sets `.hljs-punctuation` / `.hljs-tag` explicitly to `#c9d1d9` (defensive). Guarded by `cindyCodeBlockContrast.test.ts` (≥2 baseline + text ≥4.5). Full derivation: decision log.