🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
💄 style: refine single-file edit summary (#17632)
Arvin Xu9093ebb2d70a
diff --git a/.agents/acceptance/common-mistakes.md b/.agents/acceptance/common-mistakes.mdindex ceacd467141..7224c796522 100644--- a/.agents/acceptance/common-mistakes.md+++ b/.agents/acceptance/common-mistakes.md@@ -243,3 +243,13 @@ full incident narratives and old Case numbers for earlier cross-references.**What it breaks**: the closed record acquires post-decision evidence, the round history no longer matches the delivery that was accepted, and reviewers cannot independently accept or reject the new work.**Correct approach**: before every ingest, inspect `acceptance.status` and the latest run decision. If the Acceptance is terminally accepted and the current work is a new delivery, create a new production Task (or use the new work's existing subject) and ingest there. Reuse an accepted Acceptance only when the user explicitly requests reopening that exact delivery and the product supports that lifecycle.++## Single-file edit summaries need stable information hierarchy++**Wrong approach**: place line deltas at the far edge of the card and keep the secondary “View changes” action permanently visible beneath the file title.++**Why it's wrong**: the line delta describes the edited file and belongs with its identity, while an always-visible inspection action competes with the summary during normal conversation scanning.++**What it breaks**: the direct summary no longer matches the compact coding-agent pattern the user expects, and the action occupies persistent visual weight despite being needed only on inspection.++**Correct approach**: place additions/deletions directly below the single-file title, reveal “View changes” on row hover or keyboard focus, and keep it visible while the diff is open so the reverse action remains discoverable.diff --git a/locales/en-US/chat.json b/locales/en-US/chat.jsonindex 1f96657536b..aff52fd4e7c 100644--- a/locales/en-US/chat.json+++ b/locales/en-US/chat.json@@ -209,8 +209,11 @@"duplicateSession.success": "Copy successful","duplicateSession.title": "{{title}} Copy","duplicateTitle": "{{title}} Copy",+ "editedFiles.hideChanges": "Hide changes",+ "editedFiles.singleTitle": "Edited {{path}}","editedFiles.title_one": "Edited {{count}} file","editedFiles.title_other": "Edited {{count}} files",+ "editedFiles.viewChanges": "View changes","emptyAgent": "No Agents yet. Start with your first Agent—build your system over time.","emptyAgentAction": "Create Agent","extendParams.disableContextCaching.desc": "Reduce by up to 90% of the cost of generating a single conversation and bring a max of 4x speed. <1>Learn more</1>",diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.jsonindex a3c20782666..8f5a86c8807 100644--- a/locales/zh-CN/chat.json+++ b/locales/zh-CN/chat.json@@ -209,8 +209,11 @@"duplicateSession.success": "复制成功","duplicateSession.title": "{{title}} 副本","duplicateTitle": "{{title}} 副本",+ "editedFiles.hideChanges": "收起更改",+ "editedFiles.singleTitle": "已编辑 {{path}}","editedFiles.title_one": "已编辑 {{count}} 个文件","editedFiles.title_other": "已编辑 {{count}} 个文件",+ "editedFiles.viewChanges": "查看更改","emptyAgent": "还没有助理。从第一个助理开始,慢慢搭建你的助理体系","emptyAgentAction": "创建助理","extendParams.disableContextCaching.desc": "最多可减少90%的单次对话生成成本,并将速度提升至最多4倍。<1>了解更多</1>",diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.tsindex 900c637e777..6392fb2c0c0 100644--- a/packages/locales/src/default/chat.ts+++ b/packages/locales/src/default/chat.ts@@ -209,6 +209,9 @@ export default {'duplicateTitle': '{{title}} Copy','editedFiles.title_one': 'Edited {{count}} file','editedFiles.title_other': 'Edited {{count}} files',+ 'editedFiles.hideChanges': 'Hide changes',+ 'editedFiles.singleTitle': 'Edited {{path}}',+ 'editedFiles.viewChanges': 'View changes','emptyAgent': 'No Agents yet. Start with your first Agent—build your system over time.','emptyAgentAction': 'Create Agent','extendParams.disableContextCaching.desc':diff --git a/packages/shared-tool-ui/src/components/FilePathDisplay.tsx b/packages/shared-tool-ui/src/components/FilePathDisplay.tsxindex ab50c3dc5fc..fedf5b4dba1 100644--- a/packages/shared-tool-ui/src/components/FilePathDisplay.tsx+++ b/packages/shared-tool-ui/src/components/FilePathDisplay.tsx@@ -23,16 +23,20 @@ interface FilePathDisplayProps {isDirectory?: boolean;}+export const getFilePathDisplayInfo = (filePath: string) => {+ if (!filePath) return { displayPath: '', name: '' };++ const { base, dir } = path.parse(filePath);+ const parentDir = path.basename(dir);++ return {+ displayPath: parentDir ? `${parentDir}/${base}` : base,+ name: base,+ };+};+export const FilePathDisplay = memo<FilePathDisplayProps>(({ filePath, isDirectory }) => {- const { displayPath, name } = useMemo(() => {- if (!filePath) return { displayPath: '', name: '' };- const { base, dir } = path.parse(filePath);- const parentDir = path.basename(dir);- return {- displayPath: parentDir ? `${parentDir}/${base}` : base,- name: base,- };- }, [filePath]);+ const { displayPath, name } = useMemo(() => getFilePathDisplayInfo(filePath), [filePath]);if (!filePath) return null;diff --git a/packages/shared-tool-ui/src/components/index.ts b/packages/shared-tool-ui/src/components/index.tsindex 5cd3370b96a..11fc7a9618c 100644--- a/packages/shared-tool-ui/src/components/index.ts+++ b/packages/shared-tool-ui/src/components/index.ts@@ -6,5 +6,5 @@ export {KindDot,LineStats,} from './FileChangeStats';-export { FilePathDisplay } from './FilePathDisplay';+export { FilePathDisplay, getFilePathDisplayInfo } from './FilePathDisplay';export { OptionCard, type OptionCardProps } from './OptionCard';diff --git a/src/features/Conversation/Messages/EditedFilesCard/index.test.ts b/src/features/Conversation/Messages/EditedFilesCard/index.test.tsnew file mode 100644index 00000000000..beea24a902b--- /dev/null+++ b/src/features/Conversation/Messages/EditedFilesCard/index.test.ts@@ -0,0 +1,79 @@+import { getFilePathDisplayInfo } from '@lobechat/shared-tool-ui/components';+import { fireEvent, render, screen } from '@testing-library/react';+import { createElement } from 'react';+import { describe, expect, it, vi } from 'vitest';++import EditedFilesCard, {+ getEditedFileIconName,+ getEditedFilesCardMode,+ SINGLE_EDITED_FILE_ICON_SIZE,+} from './index';++vi.mock('react-i18next', () => ({+ useTranslation: () => ({+ t: (key: string, options?: { path?: string }) =>+ options?.path ? `${key}:${options.path}` : key,+ }),+}));++const singleEntry = {+ diffTexts: [+ 'diff --git a/Acceptance/index.tsx b/Acceptance/index.tsx\n--- a/Acceptance/index.tsx\n+++ b/Acceptance/index.tsx\n@@ -1 +1 @@\n-old\n+new',+ ],+ kind: 'modified' as const,+ linesAdded: 7,+ linesDeleted: 2,+ path: '/workspace/Acceptance/index.tsx',+ sourceToolCallIds: ['tool-1'],+};++describe('getEditedFilesCardMode', () => {+ it('uses the dedicated direct summary for a single edited file', () => {+ expect(getEditedFilesCardMode(1)).toBe('single');+ });++ it('uses the collapsible aggregate for multiple edited files', () => {+ expect(getEditedFilesCardMode(2)).toBe('aggregate');+ });+});++describe('getEditedFileIconName', () => {+ it('uses the edited file basename to select its file-type icon', () => {+ expect(getEditedFileIconName('/workspace/Acceptance/index.tsx')).toBe('index.tsx');+ });+});++describe('getFilePathDisplayInfo', () => {+ it('keeps the parent directory and basename for long absolute paths', () => {+ expect(getFilePathDisplayInfo('/very/long/workspace/Acceptance/index.tsx')).toEqual({+ displayPath: 'Acceptance/index.tsx',+ name: 'index.tsx',+ });+ });+});++describe('SINGLE_EDITED_FILE_ICON_SIZE', () => {+ it('keeps the single-file icon container compact', () => {+ expect(SINGLE_EDITED_FILE_ICON_SIZE).toBe(40);+ });+});++describe('SingleEditedFileCard', () => {+ it('groups line deltas below the title and exposes the diff action as a secondary control', () => {+ render(createElement(EditedFilesCard, { entries: [singleEntry] }));++ const title = screen.getByText('editedFiles.singleTitle:Acceptance/index.tsx');+ const action = screen.getByRole('button', { name: 'editedFiles.viewChanges' });+ const summary = title.parentElement;++ expect(summary).toHaveTextContent('+7');+ expect(summary).toHaveTextContent('-2');+ expect(summary).not.toContainElement(action);+ expect(action).toHaveAttribute('data-view-changes');+ expect(action).toHaveAttribute('aria-expanded', 'false');++ fireEvent.click(action);+ expect(action).toHaveAttribute('aria-expanded', 'true');+ expect(screen.getByRole('button', { name: 'editedFiles.hideChanges' })).toBeInTheDocument();+ });+});diff --git a/src/features/Conversation/Messages/EditedFilesCard/index.tsx b/src/features/Conversation/Messages/EditedFilesCard/index.tsxindex 9f369d8c692..2fb3383bf70 100644--- a/src/features/Conversation/Messages/EditedFilesCard/index.tsx+++ b/src/features/Conversation/Messages/EditedFilesCard/index.tsx@@ -5,17 +5,23 @@ import {FilePathDisplay,getFileLanguage,getFileName,+ getFilePathDisplayInfo,KindDot,LineStats,} from '@lobechat/shared-tool-ui/components';-import { Flexbox, PatchDiff, Text } from '@lobehub/ui';+import { Center, Flexbox, PatchDiff, Text } from '@lobehub/ui';+import { Button } from '@lobehub/ui/base-ui';import { createStaticStyles, cx } from 'antd-style';-import { ChevronDownIcon, ChevronRightIcon, FilePenLineIcon } from 'lucide-react';+import { ArrowUpRightIcon, ChevronDownIcon, ChevronRightIcon, FilePenLineIcon } from 'lucide-react';import { type KeyboardEvent, memo, useState } from 'react';import { useTranslation } from 'react-i18next';+import FileIcon from '@/components/FileIcon';+import { summarizeEditedFilesTotals } from './deriveEditedFiles';+export const SINGLE_EDITED_FILE_ICON_SIZE = 40;+/** Fire a toggle on Enter/Space so the div-based expander is keyboard operable. */const toggleOnKey = (toggle: () => void) => (event: KeyboardEvent<HTMLDivElement>) => {if (event.key === 'Enter' || event.key === ' ') {@@ -47,6 +53,60 @@ const styles = createStaticStyles(({ css, cssVar }) => ({flex-shrink: 0;color: ${cssVar.colorTextSecondary};`,+ singleHeader: css`+ padding-block: 10px;+ padding-inline: 12px;++ &:hover [data-view-changes],+ &:focus-within [data-view-changes] {+ pointer-events: auto;+ transform: translateX(0);+ opacity: 1;+ }+ `,+ singleIcon: css`+ flex-shrink: 0;++ width: ${SINGLE_EDITED_FILE_ICON_SIZE}px;+ height: ${SINGLE_EDITED_FILE_ICON_SIZE}px;+ border-radius: 10px;++ background: ${cssVar.colorFillTertiary};+ `,+ singleTitle: css`+ min-width: 0;+ font-size: 14px;+ font-weight: 500;+ `,+ viewChanges: css`+ pointer-events: none;++ transform: translateX(4px);++ align-self: center;++ height: 22px;+ padding: 0;++ color: ${cssVar.colorTextSecondary};++ opacity: 0;++ transition:+ opacity 150ms ease,+ transform 150ms ease;++ @media (hover: none) {+ pointer-events: auto;+ transform: translateX(0);+ opacity: 1;+ }+ `,+ viewChangesVisible: css`+ pointer-events: auto;+ transform: translateX(0);+ opacity: 1;+ `,chevron: css`flex-shrink: 0;color: ${cssVar.colorTextTertiary};@@ -152,6 +212,74 @@ interface EditedFilesCardProps {entries: EditedFileEntry[];}+export const getEditedFilesCardMode = (fileCount: number) => {+ if (fileCount === 0) return 'hidden';+ if (fileCount === 1) return 'single';+ return 'aggregate';+};++export const getEditedFileIconName = (filePath: string) => getFileName(filePath);++const SingleEditedFileCard = memo<{ entry: EditedFileEntry }>(({ entry }) => {+ const { t } = useTranslation('chat');+ const [showDiff, setShowDiff] = useState(false);+ const hasDiff = entry.diffTexts.length > 0;+ const fileName = getFileName(entry.path);+ const { displayPath } = getFilePathDisplayInfo(entry.path);+ const language = getFileLanguage(entry.path);++ return (+ <Flexbox className={styles.card}>+ <Flexbox horizontal align={'center'} className={styles.singleHeader} gap={10}>+ <Center className={styles.singleIcon}>+ <FileIcon fileName={getEditedFileIconName(entry.path)} size={24} />+ </Center>+ <Flexbox flex={1} gap={2}>+ <Text ellipsis className={styles.singleTitle}>+ {t('editedFiles.singleTitle', { path: displayPath })}+ </Text>+ <LineStats+ hideZeroDeltas+ className={styles.stats}+ linesAdded={entry.linesAdded}+ linesDeleted={entry.linesDeleted}+ />+ </Flexbox>+ {hasDiff && (+ <Button+ data-view-changes+ aria-expanded={showDiff}+ className={cx(styles.viewChanges, showDiff && styles.viewChangesVisible)}+ icon={<ArrowUpRightIcon size={14} />}+ iconPosition={'end'}+ size={'small'}+ type={'text'}+ onClick={() => setShowDiff((prev) => !prev)}+ >+ {t(showDiff ? 'editedFiles.hideChanges' : 'editedFiles.viewChanges')}+ </Button>+ )}+ </Flexbox>+ {hasDiff && showDiff && (+ <div className={styles.patch}>+ {entry.diffTexts.map((patch, index) => (+ <PatchDiff+ fileName={fileName}+ key={index}+ language={language}+ patch={patch}+ showHeader={false}+ variant={'borderless'}+ viewMode={'unified'}+ />+ ))}+ </div>+ )}+ </Flexbox>+ );+});+SingleEditedFileCard.displayName = 'SingleEditedFileCard';+/*** Codex-style aggregate card mounted at the tail of an assistant round: "edited* N files +x -y" with an expandable per-file list. Data is purely derived from@@ -163,6 +291,7 @@ const EditedFilesCard = memo<EditedFilesCardProps>(({ entries }) => {const [expanded, setExpanded] = useState(false);if (entries.length === 0) return null;+ if (entries.length === 1) return <SingleEditedFileCard entry={entries[0]} />;const totals = summarizeEditedFilesTotals(entries);@@ -179,11 +308,6 @@ const EditedFilesCard = memo<EditedFilesCardProps>(({ entries }) => {onClick={() => setExpanded((prev) => !prev)}onKeyDown={toggleOnKey(() => setExpanded((prev) => !prev))}>- {expanded ? (- <ChevronDownIcon className={styles.chevron} size={16} />- ) : (- <ChevronRightIcon className={styles.chevron} size={16} />- )}<FilePenLineIcon className={styles.headerIcon} size={16} /><Text ellipsis className={styles.title}>{t('editedFiles.title', { count: entries.length })}@@ -195,6 +319,11 @@ const EditedFilesCard = memo<EditedFilesCardProps>(({ entries }) => {linesAdded={totals.linesAdded}linesDeleted={totals.linesDeleted}/>+ {expanded ? (+ <ChevronDownIcon className={styles.chevron} size={16} />+ ) : (+ <ChevronRightIcon className={styles.chevron} size={16} />+ )}</Flexbox>{expanded && (<Flexbox className={styles.list}>