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(sidebar): PR open 绿读实际表面明度,角点描边跟 hover

Dash22b42609a62b
diff --git a/apps/desktop/src/renderer/__tests__/prStatusIconColor.test.ts b/apps/desktop/src/renderer/__tests__/prStatusIconColor.test.ts
index 42b80fe881..d7834a6fea 100644
--- a/apps/desktop/src/renderer/__tests__/prStatusIconColor.test.ts
+++ b/apps/desktop/src/renderer/__tests__/prStatusIconColor.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it } from 'vitest';
import {
+ hslTripletLightness,
prIconSurface,
prStatusIconColor,
shouldShowPrUnresolvedDot,
@@ -12,10 +13,32 @@ describe('prIconSurface', () => {
expect(prIconSurface({ themeIsDark: true, isActive: false })).toBe('dark');
});
- it('选中胶囊反相:夜间选中是浅表面,白天选中是深表面', () => {
+ it('读不到实际明度时,选中按 Cindy 反相假设兜底', () => {
expect(prIconSurface({ themeIsDark: true, isActive: true })).toBe('light');
expect(prIconSurface({ themeIsDark: false, isActive: true })).toBe('dark');
});
+
+ it('有实际背景明度时不再假设选中反相(社区/导入主题)', () => {
+ expect(
+ prIconSurface({ themeIsDark: false, isActive: true, backgroundLightness: 92 }),
+ ).toBe('light');
+ expect(
+ prIconSurface({ themeIsDark: true, isActive: true, backgroundLightness: 18 }),
+ ).toBe('dark');
+ });
+});
+
+describe('hslTripletLightness', () => {
+ it('解析 HSL 三元组与带 alpha 的写法', () => {
+ expect(hslTripletLightness('0.0 0.0% 93.3%')).toBe(93.3);
+ expect(hslTripletLightness('0.0 0.0% 100.0% / 0.09')).toBe(100);
+ expect(hslTripletLightness('214.3 5.5% 24.9%')).toBe(24.9);
+ });
+
+ it('解析不了返回 null', () => {
+ expect(hslTripletLightness('')).toBeNull();
+ expect(hslTripletLightness('#eeeeee')).toBeNull();
+ });
});
describe('prStatusIconColor', () => {
diff --git a/apps/desktop/src/renderer/features/cc-agent/gitContextPrVisuals.ts b/apps/desktop/src/renderer/features/cc-agent/gitContextPrVisuals.ts
index 9777698f59..ee3f855961 100644
--- a/apps/desktop/src/renderer/features/cc-agent/gitContextPrVisuals.ts
+++ b/apps/desktop/src/renderer/features/cc-agent/gitContextPrVisuals.ts
@@ -50,16 +50,34 @@ export const PR_STATUS_COLOR: Record<PrStatusKind, string> = {
closed: 'var(--error-fg)',
};
-/** 侧栏任务行 PR icon 所在表面:选中胶囊是反相底,跟主题名不是一回事。 */
+/** 侧栏任务行 PR icon 所在表面:跟实际底色走,不跟主题名走。 */
export type PrIconSurface = 'light' | 'dark';
+/** 从 `H S% L%` / `H S% L% / A` 取 L(0–100)。解析不了返回 null。 */
+export function hslTripletLightness(raw: string): number | null {
+ const parsed = raw.trim().match(/(-?[\d.]+)\s+(-?[\d.]+)%\s+(-?[\d.]+)%/);
+ if (!parsed) return null;
+ const lightness = Number(parsed[3]);
+ return Number.isFinite(lightness) ? lightness : null;
+}
+
/**
* 侧栏 open 绿按表面取,不跟当前主题名走(2026-08-17 用户选 B):
- * 浅表面(白天未选中 / 夜间选中白胶囊)→ `--pr-open-on-light` `#2EA043`
- * 深表面(夜间未选中 / 白天选中深胶囊)→ `--pr-open-on-dark` `#3FB950`
+ * 浅表面 → `--pr-open-on-light` `#2EA043`
+ * 深表面 → `--pr-open-on-dark` `#3FB950`
+ * 选中胶囊是否反相因主题而异(Cindy 反相,社区/导入主题多半不反相),
+ * 所以优先用实际背景的 HSL L%;读不到时才退回 Cindy 反相假设。
* 顶栏 GitContextBadge / hover tooltip 仍用 PR_STATUS_COLOR(主题 `--diff-add-fg`)。
*/
-export function prIconSurface(opts: { themeIsDark: boolean; isActive: boolean }): PrIconSurface {
+export function prIconSurface(opts: {
+ themeIsDark: boolean;
+ isActive: boolean;
+ /** 实际行底 `--sidebar` / `--sidebar-item-active` 的 L%。 */
+ backgroundLightness?: number | null;
+}): PrIconSurface {
+ if (opts.backgroundLightness != null && Number.isFinite(opts.backgroundLightness)) {
+ return opts.backgroundLightness >= 50 ? 'light' : 'dark';
+ }
if (opts.isActive) return opts.themeIsDark ? 'light' : 'dark';
return opts.themeIsDark ? 'dark' : 'light';
}
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 eb34a11e92..5e1a3ef26e 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionInfoMeta.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/SessionInfoMeta.tsx
@@ -32,7 +32,7 @@
* 等价于"只查可见行"(列表有 collapse 上限,数量有界)。
*/
-import { useEffect } from 'react';
+import { useEffect, useState } from 'react';
import { GitPullRequest } from 'lucide-react';
import { formatCompactTokens } from '@cindy/maker-shared/usage-format';
import { useTranslation } from 'react-i18next';
@@ -46,6 +46,7 @@ import { formatMoney, formatUsd } from '@/lib/usageFormat';
import { prStatusKey } from '@/lib/prStatus';
import {
PR_STATUS_ICON,
+ hslTripletLightness,
prIconSurface,
prStatusIconColor,
shouldShowPrUnresolvedDot,
@@ -134,9 +135,28 @@ export function buildSessionInfoPieces(
* 在 icon 上(open 按所在表面取,见 prStatusIconColor)。状态未加载时 icon
* 灰色 GitPullRequest 占位;文字状态与未解决条数进 title。
*/
+function readSidebarSurfaceLightness(isActive: boolean): number | null {
+ if (typeof document === 'undefined') return null;
+ const token = isActive ? '--sidebar-item-active' : '--sidebar';
+ return hslTripletLightness(getComputedStyle(document.documentElement).getPropertyValue(token));
+}
+
function PrNumberPiece({ prRef, isActive }: { prRef: SessionPrRef; isActive?: boolean }) {
const { t } = useTranslation();
const themeIsDark = useIsDarkMode();
+ const [backgroundLightness, setBackgroundLightness] = useState(() =>
+ readSidebarSurfaceLightness(Boolean(isActive)),
+ );
+ useEffect(() => {
+ const read = () => setBackgroundLightness(readSidebarSurfaceLightness(Boolean(isActive)));
+ read();
+ const observer = new MutationObserver(read);
+ observer.observe(document.documentElement, {
+ attributes: true,
+ attributeFilter: ['class', 'style'],
+ });
+ return () => observer.disconnect();
+ }, [isActive, themeIsDark]);
// fetch 从恒定的 actions context 拿——经 usePrStatuses 拿会连带订阅整表快照,
// 徽标就退化回"任一状态变化全体重渲染"。
const { fetchStatusesForSession } = usePrActions();
@@ -150,7 +170,14 @@ function PrNumberPiece({ prRef, isActive }: { prRef: SessionPrRef; isActive?: bo
const unresolvedCount = status?.ok ? status.unresolvedCount : null;
const showDot = shouldShowPrUnresolvedDot(kind, unresolvedCount);
const Icon = kind ? PR_STATUS_ICON[kind] : GitPullRequest;
- const color = prStatusIconColor(kind, prIconSurface({ themeIsDark, isActive: Boolean(isActive) }));
+ const color = prStatusIconColor(
+ kind,
+ prIconSurface({
+ themeIsDark,
+ isActive: Boolean(isActive),
+ backgroundLightness,
+ }),
+ );
const baseTitle = kind
? `${prRef.owner}/${prRef.repo}#${prRef.prNumber} · ${t(`ccAgent.gitContext.pr.status.${kind}`)}`
: `${prRef.owner}/${prRef.repo}#${prRef.prNumber}`;
@@ -165,14 +192,17 @@ function PrNumberPiece({ prRef, isActive }: { prRef: SessionPrRef; isActive?: bo
{showDot ? (
<span
aria-hidden
- className="absolute rounded-full bg-[var(--status-bar-accent)]"
- style={{
- width: 5,
- height: 5,
- top: -1.5,
- right: -1.5,
- boxShadow: `0 0 0 1.25px ${isActive ? 'hsl(var(--sidebar-item-active))' : 'hsl(var(--sidebar))'}`,
- }}
+ className={cn(
+ 'absolute rounded-full bg-[var(--status-bar-accent)]',
+ isActive
+ ? 'shadow-[0_0_0_1.25px_hsl(var(--sidebar-item-active))]'
+ : [
+ 'shadow-[0_0_0_1.25px_hsl(var(--sidebar))]',
+ 'group-hover:shadow-[0_0_0_1.25px_hsl(var(--sidebar-item-hover))]',
+ 'group-hover/card:shadow-[0_0_0_1.25px_hsl(var(--sidebar-item-hover))]',
+ ],
+ )}
+ style={{ width: 5, height: 5, top: -1.5, right: -1.5 }}
/>
) : null}
</span>
diff --git a/docs/design-rules/DESIGN.md b/docs/design-rules/DESIGN.md
index ddd9acd7b3..f40882ce88 100644
--- a/docs/design-rules/DESIGN.md
+++ b/docs/design-rules/DESIGN.md
@@ -82,7 +82,7 @@ The grayscale rule is near-absolute. The following are the **only** sanctioned n
> - **ConfirmDialog Danger** — `#EF4444` used ONLY on the confirm button background in the Danger variant. The cancel button and rest of the dialog remain grayscale.
> - **Permission Selector Mode Highlights** — selected risky permission modes may color only the option text/icon/checkmark and the collapsed trigger text/icon. The selected row background remains grayscale. Auto Approval uses `#417CDD` in both modes (finalized 2026-07-17, same value light/dark; replaces light #000050 / dark #00D9C5). Full Access uses Heart Orange `#EA6B17` in both modes (auto-follows warning-accent, finalized 2026-07-17). These hex values are the **default-theme palette only** — other themes may override `--perm-auto-selected-text` and `--perm-bypass-selected-text` with their own accent colors, provided both modes remain color-coded, distinguishable from each other, and visually distinct from neutral text. Tokens: `--perm-auto-selected-text` and `--perm-bypass-selected-text` in `apps/desktop/src/renderer/styles/globals.css`.
> - **Diff Add Green / Diff Del Red** — GitHub-standard diff syntax colors, used on the `+` / `-` symbol glyph, the changed-line text foreground, **and the full row background** inside code-diff renderings. Applied in three places: (1) the Edit-tool DiffView card (F-MSG-6), (2) markdown ````diff` fenced code blocks in the message stream, and (3) `.diff` / `.patch` files opened in TextLightbox (the document previewer) — there hljs `.hljs-addition` / `.hljs-deletion` are forced `display: block` so the background fills to the right edge instead of stopping at the last glyph. Line-number gutter and ctx (unchanged) lines remain strictly grayscale per the layer system. **Foreground** — Add: `#22863a` Light / `#7ee787` Dark; Del: `#b31d28` Light / `#ff7b72` Dark. **Background** — Add: `#f0fff4` Light / `#033a16` Dark; Del: `#ffeef0` Light / `#67060c` Dark. Tokens: `--diff-add-fg/-bg` and `--diff-del-fg/-bg` in `apps/desktop/src/renderer/styles/globals.css`. Updated 2026-04-21: backgrounds switched from grayscale → GitHub red/green for full-row fill so additions / deletions are unambiguous at a glance.
-> - **PR Status Colors (session-git-pr-context / sidebar task-info)** — closed = `--error-fg`, merged = `--focus-ring`, draft = `--text-tertiary` (single source: `PR_STATUS_COLOR` in `apps/desktop/src/renderer/features/cc-agent/gitContextPrVisuals.ts`). **Open green is split:** the session-header GitContextBadge and sidebar hover tooltip keep `--diff-add-fg` (theme-following GitHub greens). The sidebar task-info icon (registered 2026-08-17) follows the **surface**, not the theme name, because the selected pill is inverse: light surfaces (Light rest / Dark selected `#EEEEEE`) use `--pr-open-on-light` `#2EA043`; dark surfaces (Dark rest / Light selected `#3C3F43`) use `--pr-open-on-dark` `#3FB950`. Both values are theme-invariant. The `#number` stays on the info-slot foreground. Open/draft PRs with `unresolvedCount > 0` add a 5px static `--status-bar-accent` corner dot on the status icon (not an AttentionDot tone). Unknown/unloaded status degrades to `--text-tertiary`. Scope is strictly PR-state surfaces; do not generalize these colors to other status systems.
+> - **PR Status Colors (session-git-pr-context / sidebar task-info)** — closed = `--error-fg`, merged = `--focus-ring`, draft = `--text-tertiary` (single source: `PR_STATUS_COLOR` in `apps/desktop/src/renderer/features/cc-agent/gitContextPrVisuals.ts`). **Open green is split:** the session-header GitContextBadge and sidebar hover tooltip keep `--diff-add-fg` (theme-following GitHub greens). The sidebar task-info icon (registered 2026-08-17) follows the **surface**, not the theme name: it reads HSL lightness of `--sidebar` / `--sidebar-item-active` (Cindy's selected pill is inverse; many community/imported themes are not). Light surfaces use `--pr-open-on-light` `#2EA043`; dark surfaces use `--pr-open-on-dark` `#3FB950`. Both values are theme-invariant. The `#number` stays on the info-slot foreground. Open/draft PRs with `unresolvedCount > 0` add a 5px static `--status-bar-accent` corner dot on the status icon (not an AttentionDot tone). Unknown/unloaded status degrades to `--text-tertiary`. Scope is strictly PR-state surfaces; do not generalize these colors to other status systems.
*Dark Mode text uses softened neutrals to reduce eye strain: **Soft Gray** (`#d4d4d4`) for primary text, **Silver** (`#a3a3a3`) for secondary, **Stone** (`#737373`) for tertiary (per `--text-secondary` / `--text-tertiary` in `colors.ts` — the two swap between modes). Pure White (`#ffffff`) is reserved for button labels and high-contrast UI elements on dark backgrounds.*