Skip to content

🤯 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.

✨ feat(agent,working-sidebar): add Review tab with bulk git diffs (#14334)

Arvin Xub7ecf2fd4d4a
diff --git a/apps/desktop/src/main/controllers/GitCtr.ts b/apps/desktop/src/main/controllers/GitCtr.ts
index 6ff6d487e1b..88cd84eb3ef 100644
--- a/apps/desktop/src/main/controllers/GitCtr.ts
+++ b/apps/desktop/src/main/controllers/GitCtr.ts
@@ -8,10 +8,13 @@ import type {
GitBranchInfo,
GitBranchListItem,
GitCheckoutResult,
+ GitFileDiffStatus,
GitLinkedPullRequestResult,
GitPullResult,
GitPushResult,
GitWorkingTreeFiles,
+ GitWorkingTreePatch,
+ GitWorkingTreePatches,
GitWorkingTreeStatus,
} from '@lobechat/electron-client-ipc';
@@ -261,6 +264,168 @@ export default class GitController extends ControllerModule {
}
}
+ /**
+ * Pull every dirty file's unified diff in one shot — one IPC call returns
+ * the patches the renderer needs to render `<PatchDiff />` per file. We do
+ * the per-file `git diff` invocations in parallel inside this method so
+ * the renderer doesn't have to fan out N IPC round trips.
+ *
+ * Tracked changes (modified / deleted / staged-A) come from
+ * `git diff HEAD -- <file>`; pure untracked files come from
+ * `git diff --no-index /dev/null <file>` (which exits with code 1 when
+ * there are differences — that's success, not failure).
+ *
+ * Per-file patches are capped at 256 KB; oversized or binary entries get an
+ * empty `patch` string and a flag the renderer can use for a placeholder.
+ */
+ @IpcMethod()
+ async getGitWorkingTreePatches(dirPath: string): Promise<GitWorkingTreePatches> {
+ const MAX_PATCH_BYTES = 256 * 1024;
+ const execFileAsync = promisify(execFile);
+
+ interface Entry {
+ filePath: string;
+ isUntracked: boolean;
+ status: GitFileDiffStatus;
+ }
+
+ // Step 1 — classify every dirty path. Mirrors getGitWorkingTreeFiles but
+ // also distinguishes untracked (`??`) from staged-add (`A`) so we can pick
+ // the right diff command per entry.
+ const entries: Entry[] = [];
+ try {
+ const { stdout } = await execFileAsync('git', ['status', '--porcelain', '-z'], {
+ cwd: dirPath,
+ timeout: 5000,
+ });
+ const tokens = stdout.split('\0');
+ let i = 0;
+ while (i < tokens.length) {
+ const entry = tokens[i];
+ i++;
+ if (entry.length < 3) continue;
+ const x = entry[0];
+ const y = entry[1];
+ const filePath = entry.slice(3);
+ // R/C entries carry an extra source-path token we must consume.
+ if (x === 'R' || x === 'C') i++;
+ if (!filePath) continue;
+ if (x === '?' && y === '?') {
+ entries.push({ filePath, isUntracked: true, status: 'added' });
+ } else if (x === '!' && y === '!') {
+ // ignored
+ } else if (x === 'D' || y === 'D') {
+ entries.push({ filePath, isUntracked: false, status: 'deleted' });
+ } else if (x === 'A' || y === 'A') {
+ entries.push({ filePath, isUntracked: false, status: 'added' });
+ } else {
+ entries.push({ filePath, isUntracked: false, status: 'modified' });
+ }
+ }
+ } catch (error: any) {
+ logger.warn('[getGitWorkingTreePatches] status failed', {
+ cwd: dirPath,
+ stderr: error?.stderr?.toString?.() ?? error?.stderr,
+ });
+ return { patches: [] };
+ }
+
+ // Walk the patch line-by-line counting `+`/`-` payload lines while
+ // skipping the `+++ b/...` / `--- a/...` headers (they look like
+ // additions/deletions but aren't). Cheap enough to do inline per file —
+ // each patch is capped at MAX_PATCH_BYTES.
+ const countAddDel = (patch: string): { additions: number; deletions: number } => {
+ let additions = 0;
+ let deletions = 0;
+ for (const line of patch.split('\n')) {
+ if (line.startsWith('+++') || line.startsWith('---')) continue;
+ if (line.startsWith('+')) additions++;
+ else if (line.startsWith('-')) deletions++;
+ }
+ return { additions, deletions };
+ };
+
+ // Step 2 — per-file diff in parallel. `--no-index` exits 1 when there's a
+ // diff (which is the expected outcome for untracked files), so we have to
+ // pull stdout off the rejected error rather than letting it throw.
+ const patches = await Promise.all(
+ entries.map(async ({ filePath, isUntracked, status }): Promise<GitWorkingTreePatch> => {
+ const args = isUntracked
+ ? ['diff', '--no-color', '--no-index', '/dev/null', filePath]
+ : ['diff', '--no-color', 'HEAD', '--', filePath];
+
+ let text: string;
+ try {
+ const { stdout } = await execFileAsync('git', args, {
+ cwd: dirPath,
+ encoding: 'utf8',
+ maxBuffer: MAX_PATCH_BYTES * 4,
+ timeout: 10_000,
+ });
+ text = stdout as string;
+ } catch (error: any) {
+ if (error?.stdout == null) {
+ logger.debug('[getGitWorkingTreePatches] diff failed', {
+ filePath,
+ status,
+ stderr: error?.stderr?.toString?.() ?? error?.stderr,
+ });
+ return {
+ additions: 0,
+ deletions: 0,
+ filePath,
+ isBinary: false,
+ patch: '',
+ status,
+ truncated: false,
+ };
+ }
+ text = error.stdout.toString();
+ }
+
+ if (text.length > MAX_PATCH_BYTES) {
+ return {
+ additions: 0,
+ deletions: 0,
+ filePath,
+ isBinary: false,
+ patch: '',
+ status,
+ truncated: true,
+ };
+ }
+ if (/^Binary files .* differ$/m.test(text)) {
+ return {
+ additions: 0,
+ deletions: 0,
+ filePath,
+ isBinary: true,
+ patch: '',
+ status,
+ truncated: false,
+ };
+ }
+ const { additions, deletions } = countAddDel(text);
+ return {
+ additions,
+ deletions,
+ filePath,
+ isBinary: false,
+ patch: text,
+ status,
+ truncated: false,
+ };
+ }),
+ );
+
+ // Re-bucket so the UI sees added → modified → deleted (matches the
+ // working-tree popover order).
+ const order: Record<GitFileDiffStatus, number> = { added: 0, modified: 1, deleted: 2 };
+ patches.sort((a, b) => order[a.status] - order[b.status]);
+
+ return { patches };
+ }
+
/**
* Count commits HEAD is ahead/behind its upstream tracking ref.
* Returns `hasUpstream: false` when the branch has no upstream configured
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index 4b4e225d06a..a38a7c6c868 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -833,6 +833,15 @@
"workingPanel.resources.renameSuccess": "Document renamed",
"workingPanel.resources.viewMode.list": "List view",
"workingPanel.resources.viewMode.tree": "Tree view",
+ "workingPanel.review.binary": "Binary file — diff not shown",
+ "workingPanel.review.empty": "No working tree changes",
+ "workingPanel.review.error": "Couldn't load this file's diff",
+ "workingPanel.review.title": "Review",
+ "workingPanel.review.tooLarge": "File is too large to diff inline",
+ "workingPanel.review.unstaged": "Unstaged",
+ "workingPanel.review.viewMode.split": "Switch to split view",
+ "workingPanel.review.viewMode.unified": "Switch to unified view",
+ "workingPanel.space": "Space",
"workingPanel.title": "Working Panel",
"you": "You",
"zenMode": "Zen Mode"
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index a32aa7f07ed..9a665bee067 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -833,6 +833,15 @@
"workingPanel.resources.renameSuccess": "重命名成功",
"workingPanel.resources.viewMode.list": "列表视图",
"workingPanel.resources.viewMode.tree": "树状视图",
+ "workingPanel.review.binary": "二进制文件,无法展示 diff",
+ "workingPanel.review.empty": "工作区没有未提交的变更",
+ "workingPanel.review.error": "无法加载该文件的 diff",
+ "workingPanel.review.title": "审查",
+ "workingPanel.review.tooLarge": "文件过大,未在面板内展示 diff",
+ "workingPanel.review.unstaged": "未暂存",
+ "workingPanel.review.viewMode.split": "切换到双栏对比",
+ "workingPanel.review.viewMode.unified": "切换到合并视图",
+ "workingPanel.space": "空间",
"workingPanel.title": "工作面板",
"you": "你",
"zenMode": "专注模式"
diff --git a/packages/electron-client-ipc/src/types/git.ts b/packages/electron-client-ipc/src/types/git.ts
index 0a746f96a27..25780b7f75c 100644
--- a/packages/electron-client-ipc/src/types/git.ts
+++ b/packages/electron-client-ipc/src/types/git.ts
@@ -48,6 +48,40 @@ export interface GitWorkingTreeFiles {
modified: string[];
}
+export type GitFileDiffStatus = 'added' | 'modified' | 'deleted';
+
+export interface GitWorkingTreePatch {
+ /** Number of `+` lines in the patch (excluding the `+++ b/...` header). */
+ additions: number;
+ /** Number of `-` lines in the patch (excluding the `--- a/...` header). */
+ deletions: number;
+ /** Repo-relative path of the file. */
+ filePath: string;
+ /**
+ * True when git reported `Binary files … differ` for this entry — the UI
+ * should show a placeholder instead of a textual diff.
+ */
+ isBinary: boolean;
+ /**
+ * Unified diff patch text exactly as `git diff` produced it (including the
+ * `diff --git` header line). Empty when isBinary or truncated.
+ */
+ patch: string;
+ /** Same status bucket as GitWorkingTreeFiles. */
+ status: GitFileDiffStatus;
+ /** Patch was elided because it exceeded the per-file size cap. */
+ truncated: boolean;
+}
+
+export interface GitWorkingTreePatches {
+ /**
+ * All dirty file patches, ordered added → modified → deleted to match the
+ * working-tree file listing. Each entry corresponds to one file path in
+ * GitWorkingTreeFiles.
+ */
+ patches: GitWorkingTreePatch[];
+}
+
export interface GitCheckoutResult {
error?: string;
success: boolean;
diff --git a/src/locales/default/chat.ts b/src/locales/default/chat.ts
index fdd94a4687a..51984773ad2 100644
--- a/src/locales/default/chat.ts
+++ b/src/locales/default/chat.ts
@@ -886,6 +886,15 @@ export default {
'workingPanel.resources.renameSuccess': 'Document renamed',
'workingPanel.resources.viewMode.list': 'List view',
'workingPanel.resources.viewMode.tree': 'Tree view',
+ 'workingPanel.review.binary': 'Binary file — diff not shown',
+ 'workingPanel.review.empty': 'No working tree changes',
+ 'workingPanel.review.error': "Couldn't load this file's diff",
+ 'workingPanel.review.title': 'Review',
+ 'workingPanel.review.tooLarge': 'File is too large to diff inline',
+ 'workingPanel.review.unstaged': 'Unstaged',
+ 'workingPanel.review.viewMode.split': 'Switch to split view',
+ 'workingPanel.review.viewMode.unified': 'Switch to unified view',
+ 'workingPanel.space': 'Space',
'workingPanel.documents.close': 'Close',
'workingPanel.documents.error': 'Failed to load document',
'workingPanel.documents.loading': 'Loading document...',
diff --git a/src/routes/(main)/agent/features/Conversation/WorkingSidebar/Review/FileItem.tsx b/src/routes/(main)/agent/features/Conversation/WorkingSidebar/Review/FileItem.tsx
new file mode 100644
index 00000000000..6d4cdb86305
--- /dev/null
+++ b/src/routes/(main)/agent/features/Conversation/WorkingSidebar/Review/FileItem.tsx
@@ -0,0 +1,112 @@
+'use client';
+
+import type { GitFileDiffStatus } from '@lobechat/electron-client-ipc';
+import { PatchDiff } from '@lobehub/ui';
+import { createStaticStyles } from 'antd-style';
+import path from 'path-browserify-esm';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+const styles = createStaticStyles(({ css, cssVar }) => ({
+ additions: css`
+ color: ${cssVar.colorSuccess};
+ `,
+ deletions: css`
+ color: ${cssVar.colorError};
+ `,
+ empty: css`
+ padding-block: 12px;
+ color: ${cssVar.colorTextTertiary};
+ text-align: center;
+ `,
+ header: css`
+ display: flex;
+ gap: 12px;
+ align-items: center;
+
+ width: 100%;
+ min-width: 0;
+
+ font-size: 12px;
+ `,
+ path: css`
+ overflow: hidden;
+ flex: 1;
+
+ color: ${cssVar.colorText};
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ `,
+ stats: css`
+ flex: none;
+ font-family: ${cssVar.fontFamilyCode};
+ font-size: 12px;
+ font-variant-numeric: tabular-nums;
+ `,
+}));
+
+interface FileItemHeaderProps {
+ additions: number;
+ deletions: number;
+ filePath: string;
+ // Status reserved for future use (e.g. dim deleted entries) — keep on the
+ // shape so the parent doesn't need to re-derive it later.
+ status: GitFileDiffStatus;
+}
+
+export const FileItemHeader = memo<FileItemHeaderProps>(({ filePath, additions, deletions }) => {
+ return (
+ <span className={styles.header}>
+ <span className={styles.path} title={filePath}>
+ {filePath}
+ </span>
+ <span className={styles.stats}>
+ {additions > 0 && <span className={styles.additions}>+{additions}</span>}
+ {additions > 0 && deletions > 0 && ' '}
+ {deletions > 0 && <span className={styles.deletions}>-{deletions}</span>}
+ </span>
+ </span>
+ );
+});
+
+FileItemHeader.displayName = 'ReviewFileItemHeader';
+
+interface FileItemBodyProps {
+ /** Whether the Collapse panel is expanded — gates the heavy PatchDiff render. */
+ expanded: boolean;
+ filePath: string;
+ isBinary: boolean;
+ patch: string;
+ truncated: boolean;
+ viewMode: 'unified' | 'split';
+}
+
+const FileItemBody = memo<FileItemBodyProps>(
+ ({ filePath, patch, isBinary, truncated, expanded, viewMode }) => {
+ const { t } = useTranslation('chat');
+
+ if (!expanded) return null;
+
+ if (isBinary) return <div className={styles.empty}>{t('workingPanel.review.binary')}</div>;
+ if (truncated) return <div className={styles.empty}>{t('workingPanel.review.tooLarge')}</div>;
+ if (!patch) return <div className={styles.empty}>{t('workingPanel.review.error')}</div>;
+
+ const fileName = path.basename(filePath);
+ const ext = path.extname(filePath).slice(1).toLowerCase();
+
+ return (
+ <PatchDiff
+ fileName={fileName}
+ language={ext || undefined}
+ patch={patch}
+ showHeader={false}
+ variant={'borderless'}
+ viewMode={viewMode}
+ />
+ );
+ },
+);
+
+FileItemBody.displayName = 'ReviewFileItemBody';
+
+export default FileItemBody;
diff --git a/src/routes/(main)/agent/features/Conversation/WorkingSidebar/Review/index.tsx b/src/routes/(main)/agent/features/Conversation/WorkingSidebar/Review/index.tsx
new file mode 100644
index 00000000000..1ae5fb5a172
--- /dev/null
+++ b/src/routes/(main)/agent/features/Conversation/WorkingSidebar/Review/index.tsx
@@ -0,0 +1,169 @@
+'use client';
+
+import { ActionIcon, Center, Collapse, Empty, Flexbox } from '@lobehub/ui';
+import { Spin } from 'antd';
+import { createStaticStyles } from 'antd-style';
+import {
+ ChevronDownIcon,
+ ChevronRightIcon,
+ Columns2Icon,
+ GitCompareIcon,
+ Rows2Icon,
+} from 'lucide-react';
+import { memo, useMemo, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import FileItemBody, { FileItemHeader } from './FileItem';
+import { useWorkingTreePatches } from './useWorkingTreePatches';
+
+interface ReviewProps {
+ workingDirectory: string;
+}
+
+const itemKey = (entry: { filePath: string; status: string }) =>
+ `${entry.status}:${entry.filePath}`;
+
+const styles = createStaticStyles(({ css, cssVar }) => ({
+ caret: css`
+ color: ${cssVar.colorTextTertiary};
+ `,
+ count: css`
+ padding-block: 1px;
+ padding-inline: 6px;
+ border-radius: 999px;
+
+ font-family: ${cssVar.fontFamilyCode};
+ font-size: 11px;
+ font-variant-numeric: tabular-nums;
+ color: ${cssVar.colorTextSecondary};
+
+ background: ${cssVar.colorFillTertiary};
+ `,
+ scopeChip: css`
+ display: inline-flex;
+ gap: 6px;
+ align-items: center;
+
+ font-size: 12px;
+ color: ${cssVar.colorTextSecondary};
+ `,
+ subheader: css`
+ display: flex;
+ flex-shrink: 0;
+ gap: 8px;
+ align-items: center;
+ justify-content: space-between;
+
+ padding-block: 4px 8px;
+ padding-inline: 8px;
+ `,
+}));
+
+const Review = memo<ReviewProps>(({ workingDirectory }) => {
+ const { t } = useTranslation('chat');
+ const { data, isLoading } = useWorkingTreePatches(workingDirectory);
+ // Memo-stabilise the fallback so downstream useMemo deps don't flap on
+ // every render while the SWR result is undefined.
+ const patches = useMemo(() => data?.patches ?? [], [data]);
+ const [viewMode, setViewMode] = useState<'unified' | 'split'>('unified');
+
+ // Default-expand every entry (Codex-style review). Re-syncing on signature
+ // change auto-expands files the agent writes during the panel being open;
+ // panels the user manually closed earlier stay closed because their key is
+ // already absent.
+ const signature = useMemo(() => patches.map(itemKey).join('|'), [patches]);
+ const [seenSignature, setSeenSignature] = useState('');
+ const [activeKeys, setActiveKeys] = useState<string[]>([]);
+ if (signature !== seenSignature) {
+ setSeenSignature(signature);
+ setActiveKeys(patches.map(itemKey));
+ }
+
+ if (!data && isLoading) {
+ return (
+ <Center flex={1}>
+ <Spin />
+ </Center>
+ );
+ }
+
+ if (patches.length === 0) {
+ return (
+ <Center flex={1} gap={8} paddingBlock={24}>
+ <Empty description={t('workingPanel.review.empty')} icon={GitCompareIcon} />
+ </Center>
+ );
+ }
+
+ const items = patches.map((entry) => {
+ const key = itemKey(entry);
+ return {
+ children: (
+ <FileItemBody
+ expanded={activeKeys.includes(key)}
+ filePath={entry.filePath}
+ isBinary={entry.isBinary}
+ patch={entry.patch}
+ truncated={entry.truncated}
+ viewMode={viewMode}
+ />
+ ),
+ key,
+ label: (
+ <FileItemHeader
+ additions={entry.additions}
+ deletions={entry.deletions}
+ filePath={entry.filePath}
+ status={entry.status}
+ />
+ ),
+ };
+ });
+
+ return (
+ <Flexbox style={{ overflow: 'hidden' }} width={'100%'}>
+ <div className={styles.subheader}>
+ <span className={styles.scopeChip}>
+ {t('workingPanel.review.unstaged')}
+ <span className={styles.count}>{patches.length}</span>
+ <ChevronDownIcon className={styles.caret} size={12} />
+ </span>
+ <ActionIcon
+ active={viewMode === 'split'}
+ icon={viewMode === 'unified' ? Columns2Icon : Rows2Icon}
+ size={'small'}
+ title={
+ viewMode === 'unified'
+ ? t('workingPanel.review.viewMode.split')
+ : t('workingPanel.review.viewMode.unified')
+ }
+ onClick={() => setViewMode((m) => (m === 'unified' ? 'split' : 'unified'))}
+ />
+ </div>
+ <Flexbox gap={6} paddingInline={8} style={{ overflow: 'auto' }} width={'100%'}>
+ <Collapse
+ activeKey={activeKeys}
+ expandIconPlacement={'end'}
+ items={items}
+ padding={{ body: 0, header: '6px 12px' }}
+ variant={'outlined'}
+ expandIcon={({ isActive }) => (
+ <ChevronRightIcon
+ size={14}
+ style={{
+ color: 'var(--ant-color-text-tertiary)',
+ transform: isActive ? 'rotate(90deg)' : 'rotate(0deg)',
+ transition: 'transform 0.2s',
+ }}
+ />
+ )}
+ onChange={(next) => setActiveKeys(Array.isArray(next) ? next : [next])}
+ />
+ </Flexbox>
+ </Flexbox>
+ );
+});
+
+Review.displayName = 'AgentWorkingSidebarReview';
+
+export default Review;
diff --git a/src/routes/(main)/agent/features/Conversation/WorkingSidebar/Review/useWorkingTreePatches.ts b/src/routes/(main)/agent/features/Conversation/WorkingSidebar/Review/useWorkingTreePatches.ts
new file mode 100644
index 00000000000..21f095dd1e8
--- /dev/null
+++ b/src/routes/(main)/agent/features/Conversation/WorkingSidebar/Review/useWorkingTreePatches.ts
@@ -0,0 +1,21 @@
+import { isDesktop } from '@lobechat/const';
+
+import { useClientDataSWR } from '@/libs/swr';
+import { electronGitService } from '@/services/electron/git';
+
+/**
+ * Single bulk fetch for every dirty file's unified diff patch. Replaces the
+ * old N-call-per-file pattern — one IPC, one SWR cache key, the renderer
+ * iterates the result. Mirrors the dirty-counts SWR shape (always-on, focus
+ * revalidate) so opening the panel doesn't show a loading state when the
+ * working tree has already been polled.
+ */
+export const useWorkingTreePatches = (dirPath?: string) => {
+ const key = isDesktop && dirPath ? ['git-working-tree-patches', dirPath] : null;
+
+ return useClientDataSWR(key, () => electronGitService.getGitWorkingTreePatches(dirPath!), {
+ focusThrottleInterval: 5 * 1000,
+ revalidateOnFocus: true,
+ shouldRetryOnError: false,
+ });
+};
diff --git a/src/routes/(main)/agent/features/Conversation/WorkingSidebar/index.test.tsx b/src/routes/(main)/agent/features/Conversation/WorkingSidebar/index.test.tsx
index b580807e2f4..99ced7cc8eb 100644
--- a/src/routes/(main)/agent/features/Conversation/WorkingSidebar/index.test.tsx
+++ b/src/routes/(main)/agent/features/Conversation/WorkingSidebar/index.test.tsx
@@ -86,6 +86,28 @@ vi.mock('antd', () => ({
}),
},
Progress: () => <div data-testid="workspace-progress-bar" />,
+ Segmented: ({
+ options,
+ value,
+ onChange,
+ }: {
+ onChange?: (value: string) => void;
+ options?: Array<{ label?: ReactNode; value: string }>;
+ value?: string;
+ }) => (
+ <div data-testid="working-sidebar-tabs">
+ {options?.map((opt) => (
+ <button
+ data-active={String(opt.value === value)}
+ key={opt.value}
+ type="button"
+ onClick={() => onChange?.(opt.value)}
+ >
+ {opt.label}
+ </button>
+ ))}
+ </div>
+ ),
Spin: () => <div data-testid="spin" />,
}));
@@ -94,8 +116,8 @@ vi.mock('react-i18next', () => ({
t: (key: string) =>
(
({
- 'workingPanel.resources': 'Resources',
'workingPanel.resources.empty': 'No agent documents yet',
+ 'workingPanel.space': 'Space',
}) as Record<string, string>
)[key] || key,
}),
@@ -123,6 +145,9 @@ vi.mock('@/store/chat/selectors', () => ({
chatPortalSelectors: {
portalDocumentId: () => null,
},
+ topicSelectors: {
+ currentTopicWorkingDirectory: () => undefined,
+ },
}));
beforeEach(() => {
@@ -153,8 +178,8 @@ describe('AgentWorkingSidebar', () => {
it('renders panel header title and resources empty state', () => {
render(<AgentWorkingSidebar />);
- // Panel-level title
- expect(screen.getAllByText('Resources').length).toBeGreaterThan(0);
+ // Panel-level title (Space tab when no working directory)
+ expect(screen.getAllByText('Space').length).toBeGreaterThan(0);
const resources = screen.getByTestId('workspace-resources');
expect(resources).toHaveTextContent('No agent documents yet');
diff --git a/src/routes/(main)/agent/features/Conversation/WorkingSidebar/index.tsx b/src/routes/(main)/agent/features/Conversation/WorkingSidebar/index.tsx
index 516749d87df..0dce281cf6c 100644
--- a/src/routes/(main)/agent/features/Conversation/WorkingSidebar/index.tsx
+++ b/src/routes/(main)/agent/features/Conversation/WorkingSidebar/index.tsx
@@ -1,17 +1,20 @@
import { ActionIcon, Flexbox, Text } from '@lobehub/ui';
import { createStaticStyles } from 'antd-style';
import { PanelRightCloseIcon } from 'lucide-react';
-import { memo } from 'react';
+import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { DESKTOP_HEADER_ICON_SMALL_SIZE } from '@/const/layoutTokens';
import RightPanel from '@/features/RightPanel';
+import { useChatStore } from '@/store/chat';
+import { topicSelectors } from '@/store/chat/selectors';
import { useGlobalStore } from '@/store/global';
import ProgressSection from './ProgressSection';
import ResourcesSection from './ResourcesSection';
+import Review from './Review';
-const styles = createStaticStyles(({ css }) => ({
+const styles = createStaticStyles(({ css, cssVar }) => ({
body: css`
overflow-y: auto;
flex: 1;
@@ -20,11 +23,59 @@ const styles = createStaticStyles(({ css }) => ({
header: css`
flex-shrink: 0;
`,
+ pane: css`
+ overflow-y: auto;
+ flex: 1;
+ min-height: 0;
+ `,
+ paneHidden: css`
+ display: none;
+ `,
+ tab: css`
+ cursor: pointer;
+
+ padding-block: 4px;
+ padding-inline: 10px;
+ border: none;
+ border-radius: 6px;
+
+ font-size: 13px;
+ color: ${cssVar.colorTextTertiary};
+
+ background: transparent;
+
+ transition:
+ color 0.15s,
+ background 0.15s;
+
+ &:hover {
+ color: ${cssVar.colorText};
+ }
+ `,
+ tabActive: css`
+ color: ${cssVar.colorText};
+ background: ${cssVar.colorFillTertiary};
+ `,
+ tabs: css`
+ display: flex;
+ gap: 4px;
+ align-items: center;
+ `,
}));
+type Tab = 'review' | 'resources';
+
const AgentWorkingSidebar = memo(() => {
const { t } = useTranslation('chat');
const toggleRightPanel = useGlobalStore((s) => s.toggleRightPanel);
+ const workingDirectory = useChatStore(topicSelectors.currentTopicWorkingDirectory);
+
+ const reviewAvailable = !!workingDirectory;
+ // When the topic has a working directory we lead with Review — that's why
+ // the sidebar is open in agent-coding flows. Otherwise no tab strip at all,
+ // we just show the resources view as before.
+ const [tab, setTab] = useState<Tab>(reviewAvailable ? 'review' : 'resources');
+ const activeTab: Tab = reviewAvailable ? tab : 'resources';
return (
<RightPanel stableLayout defaultWidth={360} maxWidth={720} minWidth={300}>
@@ -37,16 +88,46 @@ const AgentWorkingSidebar = memo(() => {
justify={'space-between'}
paddingInline={16}
>
- <Text strong>{t('workingPanel.resources')}</Text>
+ {reviewAvailable ? (
+ <div className={styles.tabs}>
+ <button
+ className={`${styles.tab} ${activeTab === 'resources' ? styles.tabActive : ''}`}
+ type="button"
+ onClick={() => setTab('resources')}
+ >
+ {t('workingPanel.space')}
+ </button>
+ <button
+ className={`${styles.tab} ${activeTab === 'review' ? styles.tabActive : ''}`}
+ type="button"
+ onClick={() => setTab('review')}
+ >
+ {t('workingPanel.review.title')}
+ </button>
+ </div>
+ ) : (
+ <Text strong>{t('workingPanel.space')}</Text>
+ )}
<ActionIcon
icon={PanelRightCloseIcon}
size={DESKTOP_HEADER_ICON_SMALL_SIZE}
onClick={() => toggleRightPanel(false)}
/>
</Flexbox>
- <Flexbox className={styles.body} gap={8} width={'100%'}>
- <ProgressSection />
- <ResourcesSection />
+ <Flexbox className={styles.body} width={'100%'}>
+ {reviewAvailable && (
+ <Flexbox className={activeTab === 'review' ? styles.pane : styles.paneHidden}>
+ <Review workingDirectory={workingDirectory} />
+ </Flexbox>
+ )}
+ <Flexbox
+ className={activeTab === 'resources' ? styles.pane : styles.paneHidden}
+ gap={8}
+ width={'100%'}
+ >
+ <ProgressSection />
+ <ResourcesSection />
+ </Flexbox>
</Flexbox>
</Flexbox>
</RightPanel>
diff --git a/src/services/electron/git.ts b/src/services/electron/git.ts
index 8a6b0daf1d2..098f2a3bc4a 100644
--- a/src/services/electron/git.ts
+++ b/src/services/electron/git.ts
@@ -7,6 +7,7 @@ import {
type GitPullResult,
type GitPushResult,
type GitWorkingTreeFiles,
+ type GitWorkingTreePatches,
type GitWorkingTreeStatus,
} from '@lobechat/electron-client-ipc';
@@ -49,6 +50,10 @@ class ElectronGitService {
return this.ipc.git.getGitWorkingTreeFiles(dirPath);
}
+ async getGitWorkingTreePatches(dirPath: string): Promise<GitWorkingTreePatches> {
+ return this.ipc.git.getGitWorkingTreePatches(dirPath);
+ }
+
async getGitAheadBehind(dirPath: string): Promise<GitAheadBehind> {
return this.ipc.git.getGitAheadBehind(dirPath);
}