Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 统一工作组工具行与思考行的右侧三角槽 (#3107)
Dashdb7102684a5b
diff --git a/apps/desktop/src/renderer/__tests__/systemCardAutoResumeRow.test.tsx b/apps/desktop/src/renderer/__tests__/systemCardAutoResumeRow.test.tsxindex f5debc2c46..f89f4d566b 100644--- a/apps/desktop/src/renderer/__tests__/systemCardAutoResumeRow.test.tsx+++ b/apps/desktop/src/renderer/__tests__/systemCardAutoResumeRow.test.tsx@@ -163,9 +163,22 @@ describe('SystemCard auto-resume 行', () => {/>,);const button = screen.getByRole('button');+ expect(button.className.split(/\s+/)).toContain('group');expect(button.getAttribute('aria-label')).toBeNull();// 可见文本 = 结论 + 摘要,读屏据此拼出无障碍名。expect(button.textContent).toContain('chat.systemCard.autoResume.label');expect(button.textContent).toContain('502 upstream unreachable');});++ it('仅有 outcome 时仍保留 18px 三角槽,不画三角,也不挂 group', () => {+ render(<SystemCard cardType="auto-resume" data={{ outcome: 'succeeded' }} />);+ const button = screen.getByRole('button');+ expect((button as HTMLButtonElement).disabled).toBe(true);+ expect(button.className.split(/\s+/)).not.toContain('group');+ const slot = button.lastElementChild;+ expect(slot?.className).toContain('w-[18px]');+ expect(slot?.className).toContain('h-[18px]');+ expect(slot?.className).toContain('ml-auto');+ expect(slot?.querySelector('svg')).toBeNull();+ });});diff --git a/apps/desktop/src/renderer/__tests__/workGroupBlockInteraction.test.ts b/apps/desktop/src/renderer/__tests__/workGroupBlockInteraction.test.tsindex 75dab0eabd..d9aadebb6a 100644--- a/apps/desktop/src/renderer/__tests__/workGroupBlockInteraction.test.ts+++ b/apps/desktop/src/renderer/__tests__/workGroupBlockInteraction.test.ts@@ -21,6 +21,18 @@ describe('WorkGroupBlock — 嵌套工作组接线静态扫描', () => {resolve(__dirname, '..', 'components', 'chat', 'WorkGroupBlock.tsx'),'utf8',);+ const chrome = readFileSync(+ resolve(__dirname, '..', 'components', 'chat', 'activityRowChrome.ts'),+ 'utf8',+ );+ const actionRow = readFileSync(+ resolve(__dirname, '..', 'components', 'chat', 'AgentActionRow.tsx'),+ 'utf8',+ );+ const systemCard = readFileSync(+ resolve(__dirname, '..', 'components', 'chat', 'SystemCard.tsx'),+ 'utf8',+ );it('onToggle 不再批量 seed 后代工作组展开态', () => {// 外层 click 只能翻外层自身;内层「已工作」仍由用户单独展开。@@ -47,6 +59,38 @@ describe('WorkGroupBlock — 嵌套工作组接线静态扫描', () => {);});+ it('thinking 行右侧三角与工具行共用同一套槽和 hover 浮起', () => {+ expect(chrome).toMatch(/group-hover:bg-\[var\(--cmd-palette-item-hover\)\]/);+ expect(chrome).toMatch(/hover:bg-\[var\(--msg-code-inline-bg\)\]/);+ expect(chrome).toMatch(/h-\[18px\] w-\[18px\]/);+ expect(chrome).toMatch(/ACTIVITY_ROW_RADIUS_CLASS = 'rounded-\[8px\]'/);+ expect(chrome).toMatch(/rounded-\[8px\]/);+ expect(chrome).toMatch(/duration-\[var\(--motion-fast,150ms\)\]/);+ expect(chrome).toMatch(/ease-\[var\(--motion-ease-out\)\]/);+ expect(chrome).not.toMatch(/rounded-lg/);+ expect(chrome).not.toMatch(/var\(--radius\)/);+ expect(chrome).not.toMatch(/rounded-\[4px\]/);+ expect(source).toMatch(/from '\.\/activityRowChrome'/);+ expect(source).toMatch(/ACTIVITY_ROW_CHEVRON_SLOT_CLASS/);+ expect(source).toMatch(/ACTIVITY_ROW_HOVER_SURFACE_CLASS/);+ expect(source).toMatch(/ACTIVITY_ROW_RADIUS_CLASS/);+ expect(source).toMatch(/ACTIVITY_ROW_COLOR_TRANSITION_CLASS/);+ expect(source).not.toMatch(/function ThinkingActivityRow[\s\S]*rounded-\[6px\]/);+ expect(actionRow).toMatch(/from '\.\/activityRowChrome'/);+ expect(actionRow).toMatch(/ACTIVITY_ROW_CHEVRON_SLOT_CLASS/);+ expect(actionRow).toMatch(/ACTIVITY_ROW_RADIUS_CLASS/);+ expect(actionRow).toMatch(/ACTIVITY_ROW_COLOR_TRANSITION_CLASS/);+ expect(systemCard).toMatch(/ACTIVITY_ROW_CHEVRON_SLOT_CLASS/);+ // 槽位始终占位;只有可展开时才画三角。旧写法把整个 span 按 canExpand 卸掉,+ // 短思考行 / 仅有 outcome 的中断行会比工具行更靠右。+ expect(source).not.toMatch(+ /\{canExpand && \(\s*<span aria-hidden="true" className="inline-flex h-\[18px\]/,+ );+ expect(systemCard).not.toMatch(+ /\{canExpand && \(\s*<span aria-hidden="true" className=\{ACTIVITY_ROW_CHEVRON_SLOT_CLASS\}/,+ );+ });+it('完成态内层工作组递归复用 WorkGroupBlock', () => {expect(source).toMatch(/child\.kind === 'group'[\s\S]*?<WorkGroupBlock/);});diff --git a/apps/desktop/src/renderer/__tests__/workGroupBlockLivePreview.test.tsx b/apps/desktop/src/renderer/__tests__/workGroupBlockLivePreview.test.tsxindex ad922fd133..902a9be255 100644--- a/apps/desktop/src/renderer/__tests__/workGroupBlockLivePreview.test.tsx+++ b/apps/desktop/src/renderer/__tests__/workGroupBlockLivePreview.test.tsx@@ -510,6 +510,35 @@ describe('WorkGroupBlock — running latest-five preview', () => {expect(thinkingButton.textContent).toContain('first line\nsecond line');});+ it('always reserves the 18px trailing chevron slot on thinking rows', () => {+ render(+ createElement(WorkGroupBlock, {+ blockId: 'work:t1',+ isStreaming: true,+ childItems: [+ thinking(mkThinking('short', 'brief')),+ thinking(mkThinking('long', 'first line\nsecond line')),+ ],+ }),+ );++ const rows = document.querySelectorAll<HTMLButtonElement>(+ '[data-live-work-activity="thinking"]',+ );+ expect(rows).toHaveLength(2);+ for (const row of rows) {+ expect(row.className).toContain('rounded-[8px]');+ const slot = row.lastElementChild;+ expect(slot?.className).toContain('w-[18px]');+ expect(slot?.className).toContain('h-[18px]');+ expect(slot?.className).toContain('ml-auto');+ expect(slot?.className).toContain('rounded-[8px]');+ expect(slot?.className).toContain('group-hover:bg-[var(--cmd-palette-item-hover)]');+ }+ expect(rows[0]?.querySelector('svg.lucide-chevron-right')).toBeNull();+ expect(rows[1]?.querySelector('svg.lucide-chevron-right')).toBeTruthy();+ });+it('drops empty thinking and renders redacted thinking directly', () => {const redacted = { ...mkThinking('hidden', ''), thinkingRedacted: true };render(diff --git a/apps/desktop/src/renderer/components/chat/AgentActionRow.tsx b/apps/desktop/src/renderer/components/chat/AgentActionRow.tsxindex 628831939a..4728e40e62 100644--- a/apps/desktop/src/renderer/components/chat/AgentActionRow.tsx+++ b/apps/desktop/src/renderer/components/chat/AgentActionRow.tsx@@ -65,6 +65,12 @@ import { toRemoteMediaOrigin } from '@/lib/sessionFileOrigin';import { rewriteToRemoteMediaOrigin } from '../../../shared/remoteMediaUrl';import { useInstalledGhosts } from '@/cindy-brain/useInstalledGhosts';import { useChatSessionFile } from './ChatSessionFileContext';+import {+ ACTIVITY_ROW_CHEVRON_SLOT_CLASS,+ ACTIVITY_ROW_COLOR_TRANSITION_CLASS,+ ACTIVITY_ROW_HOVER_SURFACE_CLASS,+ ACTIVITY_ROW_RADIUS_CLASS,+} from './activityRowChrome';import { ImageLightbox } from './ImageLightbox';import { TextLightbox } from './TextLightbox';import { ToolPayloadLightbox, type ToolPayloadMode } from './ToolPayloadLightbox';@@ -894,8 +900,10 @@ export function AgentActionRow({}className={cn('group flex w-full items-center gap-[6px]',- 'rounded-[6px] px-2 py-[3px]',- 'hover:bg-[var(--msg-code-inline-bg)] transition-colors',+ ACTIVITY_ROW_RADIUS_CLASS,+ 'px-2 py-[3px]',+ ACTIVITY_ROW_HOVER_SURFACE_CLASS,+ ACTIVITY_ROW_COLOR_TRANSITION_CLASS,'cursor-pointer select-none outline-none','focus-visible:ring-2 focus-visible:ring-[var(--info-700)]/40','text-left',@@ -934,14 +942,7 @@ export function AgentActionRow({)}{/* v9: 移除 chevron 上的"查看详情" Tooltip。整行 button 已经是统一激活目标,末尾 chevron 只保留视觉提示。 */}- <span- aria-hidden="true"- className={cn(- 'flex h-[18px] w-[18px] items-center justify-center rounded-[4px] shrink-0',- 'text-[var(--msg-tool-card-chevron)]',- 'group-hover:bg-[var(--cmd-palette-item-hover)] transition-colors',- )}- >+ <span aria-hidden="true" className={ACTIVITY_ROW_CHEVRON_SLOT_CLASS}>{isInlineExpand && expanded ? (<ChevronDown size={13} />) : (diff --git a/apps/desktop/src/renderer/components/chat/SystemCard.tsx b/apps/desktop/src/renderer/components/chat/SystemCard.tsxindex 8ec86969f5..905695ffbe 100644--- a/apps/desktop/src/renderer/components/chat/SystemCard.tsx+++ b/apps/desktop/src/renderer/components/chat/SystemCard.tsx@@ -29,6 +29,12 @@ import {reviewFailureCodeFromLegacyError,type ReviewFailureCode,} from '../../../shared/reviewRun';+import {+ ACTIVITY_ROW_CHEVRON_SLOT_CLASS,+ ACTIVITY_ROW_COLOR_TRANSITION_CLASS,+ ACTIVITY_ROW_HOVER_SURFACE_CLASS,+ ACTIVITY_ROW_RADIUS_CLASS,+} from './activityRowChrome';import { MarkdownRenderer } from './MarkdownRenderer';interface SystemCardProps {@@ -867,8 +873,8 @@ function AutoResumeSeparator() {/*** 中断自愈活动行(进行中 / 已完成共用)。*- * **形态刻意对齐 AgentActionRow(工具活动行)**:radius 6 / `px-2 py-[3px]` / 16px 状态- * 图标槽位 / 14px `--msg-tool-card-chevron` 文字 / param 位 / 尾部 chevron / hover 抬到+ * **形态刻意对齐 AgentActionRow(工具活动行)**:inner-control 8px / `px-2 py-[3px]` / 16px 状态+ * 图标槽位 / 14px `--msg-tool-card-chevron` 文字 / param 位 / 尾部 18×18 槽始终占位 / hover 抬到* `--msg-code-inline-bg`。产品语义就是「这是 agent 干活流程里的一步,只不过这一步在* 重连」,而不是一条系统公告——所以它读起来必须像正常工作行,不是横幅、不是警告。*@@ -937,11 +943,16 @@ function AutoResumeActionRow({// 图标与 chevron 都是 aria-hidden,可见文本(动词 + 摘要)本身就是正确的无障碍名。disabled={!canExpand}className={cn(- 'group flex w-full items-center gap-[6px]',- 'rounded-[6px] px-2 py-[3px]',- 'text-left outline-none transition-colors',+ 'flex w-full items-center gap-[6px]',+ ACTIVITY_ROW_RADIUS_CLASS,+ 'px-2 py-[3px]',+ 'text-left outline-none',canExpand- ? 'cursor-pointer select-none hover:bg-[var(--msg-code-inline-bg)] focus-visible:ring-2 focus-visible:ring-[var(--info-700)]/40'+ ? cn(+ 'group cursor-pointer select-none focus-visible:ring-2 focus-visible:ring-[var(--info-700)]/40',+ ACTIVITY_ROW_COLOR_TRANSITION_CLASS,+ ACTIVITY_ROW_HOVER_SURFACE_CLASS,+ ): 'cursor-default select-none',)}>@@ -974,18 +985,9 @@ function AutoResumeActionRow({</span>)}<span className="flex-1" />- {canExpand && (- <span- aria-hidden="true"- className={cn(- 'flex h-[18px] w-[18px] items-center justify-center rounded-[4px] shrink-0',- 'text-[var(--msg-tool-card-chevron)]',- 'transition-colors group-hover:bg-[var(--cmd-palette-item-hover)]',- )}- >- {expanded ? <ChevronDown size={13} /> : <ChevronRight size={13} />}- </span>- )}+ <span aria-hidden="true" className={ACTIVITY_ROW_CHEVRON_SLOT_CLASS}>+ {canExpand ? (expanded ? <ChevronDown size={13} /> : <ChevronRight size={13} />) : null}+ </span></button>{canExpand && expanded && (<divdiff --git a/apps/desktop/src/renderer/components/chat/WorkGroupBlock.tsx b/apps/desktop/src/renderer/components/chat/WorkGroupBlock.tsxindex cdf967522c..f2a3a0db23 100644--- a/apps/desktop/src/renderer/components/chat/WorkGroupBlock.tsx+++ b/apps/desktop/src/renderer/components/chat/WorkGroupBlock.tsx@@ -38,6 +38,12 @@ import { useExpandedBlockMemory } from '@/hooks/useExpandedBlockMemory';import { Collapse } from '@/components/ui/collapse';import { Spinner } from '@/components/ui/spinner';+import {+ ACTIVITY_ROW_CHEVRON_SLOT_CLASS,+ ACTIVITY_ROW_COLOR_TRANSITION_CLASS,+ ACTIVITY_ROW_HOVER_SURFACE_CLASS,+ ACTIVITY_ROW_RADIUS_CLASS,+} from './activityRowChrome';import { AgentActionRow } from './AgentActionRow';import { ThinkingCard, formatDuration } from './ThinkingCard';import { ThinkingText } from './ThinkingText';@@ -112,7 +118,7 @@ export interface WorkGroupBlockProps {function ToolActivityRow({ activity }: { activity: ProjectedToolActivity }) {return (- <div data-live-work-activity="tool" className="min-w-0">+ <div data-live-work-activity="tool" className="w-full min-w-0"><AgentActionRowmessage={activity.message}toolResult={activity.toolResult}@@ -164,8 +170,16 @@ function ThinkingActivityRow({aria-expanded={canExpand ? expanded : undefined}onClick={() => setExpanded((value) => !value)}className={cn(- 'flex w-full min-w-0 items-start gap-[6px] px-2 py-[3px] text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]',- canExpand && 'cursor-pointer hover:opacity-80 transition-opacity',+ 'flex w-full min-w-0 gap-[6px] px-2 py-[3px] text-left outline-none',+ ACTIVITY_ROW_RADIUS_CLASS,+ expanded ? 'items-start' : 'items-center',+ canExpand+ ? [+ 'group cursor-pointer select-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]',+ ACTIVITY_ROW_COLOR_TRANSITION_CLASS,+ ACTIVITY_ROW_HOVER_SURFACE_CLASS,+ ]+ : 'cursor-default',)}><span@@ -184,8 +198,8 @@ function ThinkingActivityRow({><ThinkingText content={expanded ? rawContent : activity.content} /></span>- {canExpand && (- <span aria-hidden="true" className="inline-flex h-[18px] shrink-0 items-center text-[var(--msg-tool-card-chevron)]">+ <span aria-hidden="true" className={ACTIVITY_ROW_CHEVRON_SLOT_CLASS}>+ {canExpand ? (<ChevronRightsize={13}className={cn(@@ -193,46 +207,16 @@ function ThinkingActivityRow({expanded && 'rotate-90',)}/>- </span>- )}+ ) : null}+ </span></button>);}-/** 展开动作段里的 thinking:默认直接露出一行;原文多行或视觉溢出时,- * 允许再点该行查看完整原文。live preview 继续复用上面的固定单行版本。 */+/** 展开动作段里的 thinking:与 live preview 共用 ThinkingActivityRow,+ * 保证右侧三角槽同一套布局;redacted 仍走 ThinkingCard。 */function ExpandedThinkingRow({ message }: { message: ChatMessage }) {const activity = thinkingActivityForMessage(message);- const rawContent = message.content.trim();- const hasExplicitLineBreak = /[\r\n]/.test(rawContent);- const textRef = useRef<HTMLSpanElement>(null);- const [canExpand, setCanExpand] = useState(hasExplicitLineBreak);- const { expanded, setExpanded } = useExpandedBlockMemory(`thinking:${message.clientId}`);-- useLayoutEffect(() => {- if (!activity) return;- if (expanded) {- setCanExpand(true);- return;- }- const textElement = textRef.current;- if (!textElement) return;- const updateOverflow = () => {- setCanExpand(- hasExplicitLineBreak || textElement.scrollWidth > textElement.clientWidth + 1,- );- };- updateOverflow();- if (typeof ResizeObserver === 'undefined') return;- const observer = new ResizeObserver(updateOverflow);- observer.observe(textElement);- return () => observer.disconnect();- }, [activity?.content, expanded, hasExplicitLineBreak]);-- const onToggle = useCallback(() => {- if (canExpand) setExpanded((value) => !value);- }, [canExpand, setExpanded]);-if (!activity) {if (!message.thinkingRedacted) return null;return (@@ -246,49 +230,7 @@ function ExpandedThinkingRow({ message }: { message: ChatMessage }) {);}- return (- <button- type="button"- data-live-work-activity="thinking"- data-message-client-id={message.clientId}- data-work-thinking-expandable={canExpand ? 'true' : 'false'}- onClick={onToggle}- disabled={!canExpand}- aria-expanded={canExpand ? expanded : undefined}- className={cn(- 'flex w-full min-w-0 items-start gap-[6px] px-2 py-[3px] text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring)]',- canExpand && 'cursor-pointer hover:opacity-80 transition-opacity',- )}- >- <span- aria-hidden="true"- className="inline-flex h-[18px] w-4 shrink-0 items-center justify-center text-[var(--msg-tool-card-chevron)]"- >- <Sparkles size={13} />- </span>- <span- ref={textRef}- className={cn(- 'min-w-0 flex-1 text-14 italic text-[var(--thinking-body-text)]',- expanded ? 'whitespace-pre-wrap break-words' : 'truncate',- )}- title={expanded ? undefined : activity.content}- >- <ThinkingText content={expanded ? rawContent : activity.content} />- </span>- {canExpand && (- <span aria-hidden="true" className="inline-flex h-[18px] shrink-0 items-center text-[var(--msg-tool-card-chevron)]">- <ChevronRight- size={13}- className={cn(- 'transition-transform duration-[var(--motion-fast,150ms)]',- expanded && 'rotate-90',- )}- />- </span>- )}- </button>- );+ return <ThinkingActivityRow activity={activity} />;}/** 同一个子项渲染器递归服务运行态动作组、完成态内层动作组和外层文字时间线。 */@@ -423,8 +365,8 @@ export function WorkGroupBlock({: baseSummaryText;return (- <div className="flex w-full justify-start">- <div className="w-full">+ <div className="flex w-full min-w-0 justify-start">+ <div className="w-full min-w-0"><buttontype="button"onClick={canToggle ? onToggle : undefined}@@ -472,7 +414,7 @@ export function WorkGroupBlock({<divdata-live-work-preview="true"className={cn(- 'mt-1 border-l-2 border-[var(--agent-actions-rail)] py-[2px] pl-3',+ 'mt-1 min-w-0 border-l-2 border-[var(--agent-actions-rail)] py-[2px] pl-3','flex flex-col',)}>@@ -489,7 +431,7 @@ export function WorkGroupBlock({<Collapse open={effectiveExpanded}><divclassName={cn(- 'mt-1 pl-3 py-[2px]',+ 'mt-1 min-w-0 pl-3 py-[2px]','border-l-2 border-[var(--agent-actions-rail)]','flex flex-col gap-2',)}diff --git a/apps/desktop/src/renderer/components/chat/activityRowChrome.ts b/apps/desktop/src/renderer/components/chat/activityRowChrome.tsnew file mode 100644index 0000000000..8dc2dd654d--- /dev/null+++ b/apps/desktop/src/renderer/components/chat/activityRowChrome.ts@@ -0,0 +1,23 @@+/**+ * Compact activity-row chrome shared by tool rows, work-group thinking rows,+ * and system interruption rows. Mixed lists must share one trailing-triangle+ * slot, one hover lift, and one radius — two languages in the same column+ * read as drift. Radius is DESIGN.md §5 inner-control 8px. Do not use the+ * lg radius utility: it compiles to an undefined theme variable and is dropped.+ */++/** Compact row surface radius. Pair with padding on the clickable row. */+export const ACTIVITY_ROW_RADIUS_CLASS = 'rounded-[8px]';++/** Row surface that lifts on hover. Pair with `group` on the clickable row. */+export const ACTIVITY_ROW_HOVER_SURFACE_CLASS = 'hover:bg-[var(--msg-code-inline-bg)]';++/** Color hover. DESIGN.md §14.4: new transitions must cite motion tokens;+ * `transition-colors` alone uses Tailwind's hardcoded duration/easing. */+export const ACTIVITY_ROW_COLOR_TRANSITION_CLASS =+ 'transition-colors duration-[var(--motion-fast,150ms)] ease-[var(--motion-ease-out)]';++/** Fixed 18×18 trailing chevron slot. Always reserve the column; hover paints+ * the small rounded well behind the glyph (`group-hover` on the row). */+export const ACTIVITY_ROW_CHEVRON_SLOT_CLASS =+ `ml-auto flex h-[18px] w-[18px] shrink-0 items-center justify-center ${ACTIVITY_ROW_RADIUS_CLASS} ${ACTIVITY_ROW_COLOR_TRANSITION_CLASS} text-[var(--msg-tool-card-chevron)] group-hover:bg-[var(--cmd-palette-item-hover)]`;