diff --git a/apps/web/components/task/chat/messages/chat-message.tsx b/apps/web/components/task/chat/messages/chat-message.tsx
index c17b0ebff6..5b69b2a9fc 100644
--- a/apps/web/components/task/chat/messages/chat-message.tsx
+++ b/apps/web/components/task/chat/messages/chat-message.tsx
@@ -181,12 +181,12 @@ export const ChatMessage = memo(function ChatMessage({ comment, label, className
return
+
{children}
), diff --git a/apps/web/components/task/chat/messages/diff-view-block.tsx b/apps/web/components/task/chat/messages/diff-view-block.tsx index 9d6acd54d2..ef2485f25f 100644 --- a/apps/web/components/task/chat/messages/diff-view-block.tsx +++ b/apps/web/components/task/chat/messages/diff-view-block.tsx @@ -1,6 +1,5 @@ 'use client'; -import { IconCode } from '@tabler/icons-react'; import { cn } from '@/lib/utils'; import { DiffViewInline } from '@/components/diff'; import type { FileDiffData } from '@/lib/diff/types'; @@ -8,28 +7,13 @@ import type { FileDiffData } from '@/lib/diff/types'; type DiffViewBlockProps = { /** Diff data in the new format */ data: FileDiffData; - /** Title to display */ - title?: string; - /** Whether to show the title */ - showTitle?: boolean; /** Additional class name */ className?: string; }; -export function DiffViewBlock({ - data, - title = 'Diff', - showTitle = true, - className -}: DiffViewBlockProps) { +export function DiffViewBlock({ data, className }: DiffViewBlockProps) { return (
diff --git a/apps/web/components/task/file-editor-content.tsx b/apps/web/components/task/file-editor-content.tsx
index ed9635580b..82ad02d7a3 100644
--- a/apps/web/components/task/file-editor-content.tsx
+++ b/apps/web/components/task/file-editor-content.tsx
@@ -10,6 +10,7 @@ import { Button } from '@kandev/ui/button';
import { IconDeviceFloppy, IconLoader2, IconTrash, IconTextWrap, IconTextWrapDisabled, IconMessagePlus } from '@tabler/icons-react';
import { Tooltip, TooltipContent, TooltipTrigger } from '@kandev/ui/tooltip';
import { formatDiffStats } from '@/lib/utils/file-diff';
+import { toRelativePath } from '@/lib/utils';
import { vscodeDark } from '@uiw/codemirror-theme-vscode';
import { useDiffCommentsStore, useFileComments } from '@/lib/state/slices/diff-comments/diff-comments-slice';
import type { DiffComment } from '@/lib/diff/types';
@@ -24,6 +25,7 @@ type FileEditorContentProps = {
isDirty: boolean;
isSaving: boolean;
sessionId?: string;
+ worktreePath?: string;
enableComments?: boolean;
onChange: (newContent: string) => void;
onSave: () => void;
@@ -129,6 +131,7 @@ export function FileEditorContent({
isDirty,
isSaving,
sessionId,
+ worktreePath,
enableComments = false,
onChange,
onSave,
@@ -516,7 +519,7 @@ export function FileEditorContent({
{/* Editor header with save button */}
- {path}
+ {toRelativePath(path, worktreePath)}
{isDirty && diffStats && (
{formatDiffStats(diffStats.additions, diffStats.deletions)}
diff --git a/apps/web/components/task/task-center-panel.tsx b/apps/web/components/task/task-center-panel.tsx
index 428e82187b..b5b933b1e2 100644
--- a/apps/web/components/task/task-center-panel.tsx
+++ b/apps/web/components/task/task-center-panel.tsx
@@ -644,6 +644,7 @@ export const TaskCenterPanel = memo(function TaskCenterPanel({
isDirty={tab.isDirty}
isSaving={savingFiles.has(tab.path)}
sessionId={activeSessionId || undefined}
+ worktreePath={activeSession?.worktree_path ?? undefined}
enableComments={!!activeSessionId}
onChange={(newContent) => handleFileChange(tab.path, newContent)}
onSave={() => handleFileSave(tab.path)}
diff --git a/apps/web/hooks/domains/session/use-session-git-status.ts b/apps/web/hooks/domains/session/use-session-git-status.ts
index eece63d732..3b78f908a4 100644
--- a/apps/web/hooks/domains/session/use-session-git-status.ts
+++ b/apps/web/hooks/domains/session/use-session-git-status.ts
@@ -1,5 +1,6 @@
-import { useEffect, useRef } from 'react';
-import { useAppStore } from '@/components/state-provider';
+import { useEffect, useRef, useCallback } from 'react';
+import { useShallow } from 'zustand/react/shallow';
+import { useAppStore, useAppStoreApi } from '@/components/state-provider';
import { getWebSocketClient } from '@/lib/ws/connection';
import type { GitSnapshot } from '@/lib/state/slices/session-runtime/types';
@@ -10,12 +11,73 @@ import type { GitSnapshot } from '@/lib/state/slices/session-runtime/types';
* For historical snapshots, use useSessionGitSnapshots hook.
*/
export function useSessionGitStatus(sessionId: string | null) {
- const gitStatus = useAppStore((state) =>
- sessionId ? state.gitStatus.bySessionId[sessionId] : undefined
+ // Use shallow comparison to prevent re-renders when object reference changes but values are the same
+ const gitStatus = useAppStore(
+ useShallow((state) =>
+ sessionId ? state.gitStatus.bySessionId[sessionId] : undefined
+ )
);
- const setGitStatus = useAppStore((state) => state.setGitStatus);
const connectionStatus = useAppStore((state) => state.connection.status);
+ const storeApi = useAppStoreApi();
const prevSessionIdRef = useRef(null);
+ const hasFetchedRef = useRef(false);
+
+ // Stable reference to fetch function
+ const fetchSnapshot = useCallback(async (sid: string) => {
+ const client = getWebSocketClient();
+ if (!client) return;
+
+ const setGitStatus = storeApi.getState().setGitStatus;
+
+ try {
+ const response = await client.request<{ snapshots?: GitSnapshot[] }>(
+ 'session.git.snapshots',
+ {
+ session_id: sid,
+ limit: 1, // Only fetch the latest snapshot
+ }
+ );
+
+ if (response?.snapshots && response.snapshots.length > 0) {
+ const latest = response.snapshots[0];
+
+ // Extract file paths by status from the files object
+ const modified: string[] = [];
+ const added: string[] = [];
+ const deleted: string[] = [];
+ const untracked: string[] = [];
+ const renamed: string[] = [];
+
+ if (latest.files) {
+ Object.entries(latest.files).forEach(([path, fileInfo]) => {
+ const status = fileInfo.status?.toLowerCase();
+ if (status === 'modified') modified.push(path);
+ else if (status === 'added') added.push(path);
+ else if (status === 'deleted') deleted.push(path);
+ else if (status === 'untracked') untracked.push(path);
+ else if (status === 'renamed') renamed.push(path);
+ });
+ }
+
+ // Populate git status from latest snapshot
+ setGitStatus(sid, {
+ branch: latest.branch,
+ remote_branch: latest.remote_branch,
+ modified,
+ added,
+ deleted,
+ untracked,
+ renamed,
+ ahead: latest.ahead,
+ behind: latest.behind,
+ files: latest.files,
+ timestamp: latest.created_at,
+ });
+ }
+ } catch (error) {
+ console.error('Failed to fetch latest git snapshot:', error);
+ }
+ }, [storeApi]);
// Fetch initial status on mount if not already loaded
// Also refetch when switching to a different session or when WebSocket connects
@@ -28,70 +90,21 @@ export function useSessionGitStatus(sessionId: string | null) {
// Detect session change to force refetch
const sessionChanged = prevSessionIdRef.current !== null &&
prevSessionIdRef.current !== sessionId;
+
+ if (sessionChanged) {
+ hasFetchedRef.current = false;
+ }
prevSessionIdRef.current = sessionId;
- // Skip fetch if status exists and session hasn't changed
- if (gitStatus && !sessionChanged) {
+ // Skip fetch if we already have status or already fetched for this session
+ const currentStatus = storeApi.getState().gitStatus.bySessionId[sessionId];
+ if (currentStatus || hasFetchedRef.current) {
return;
}
- // Fetch latest git snapshot
- const fetchSnapshot = async () => {
- const client = getWebSocketClient();
- if (!client) return;
-
- try {
- const response = await client.request<{ snapshots?: GitSnapshot[] }>(
- 'session.git.snapshots',
- {
- session_id: sessionId,
- limit: 1, // Only fetch the latest snapshot
- }
- );
-
- if (response?.snapshots && response.snapshots.length > 0) {
- const latest = response.snapshots[0];
-
- // Extract file paths by status from the files object
- const modified: string[] = [];
- const added: string[] = [];
- const deleted: string[] = [];
- const untracked: string[] = [];
- const renamed: string[] = [];
-
- if (latest.files) {
- Object.entries(latest.files).forEach(([path, fileInfo]) => {
- const status = fileInfo.status?.toLowerCase();
- if (status === 'modified') modified.push(path);
- else if (status === 'added') added.push(path);
- else if (status === 'deleted') deleted.push(path);
- else if (status === 'untracked') untracked.push(path);
- else if (status === 'renamed') renamed.push(path);
- });
- }
-
- // Populate git status from latest snapshot
- setGitStatus(sessionId, {
- branch: latest.branch,
- remote_branch: latest.remote_branch,
- modified,
- added,
- deleted,
- untracked,
- renamed,
- ahead: latest.ahead,
- behind: latest.behind,
- files: latest.files,
- timestamp: latest.created_at,
- });
- }
- } catch (error) {
- console.error('Failed to fetch latest git snapshot:', error);
- }
- };
-
- fetchSnapshot();
- }, [sessionId, gitStatus, setGitStatus, connectionStatus]);
+ hasFetchedRef.current = true;
+ fetchSnapshot(sessionId);
+ }, [sessionId, connectionStatus, fetchSnapshot, storeApi]);
// Subscribe to session updates to receive git status via WebSocket
useEffect(() => {
diff --git a/apps/web/lib/state/slices/session-runtime/session-runtime-slice.ts b/apps/web/lib/state/slices/session-runtime/session-runtime-slice.ts
index 90533e469a..3d1f790b5a 100644
--- a/apps/web/lib/state/slices/session-runtime/session-runtime-slice.ts
+++ b/apps/web/lib/state/slices/session-runtime/session-runtime-slice.ts
@@ -84,8 +84,43 @@ export const createSessionRuntimeSlice: StateCreator<
}),
setGitStatus: (sessionId, gitStatus) =>
set((draft) => {
- // Always update git status - the timestamp and file diffs may have changed
- // even if the file lists are the same. The backend sends updates when content changes.
+ const existing = draft.gitStatus.bySessionId[sessionId];
+
+ // Skip update if key fields haven't changed to prevent unnecessary re-renders
+ if (existing) {
+ const branchChanged = existing.branch !== gitStatus.branch ||
+ existing.remote_branch !== gitStatus.remote_branch;
+ const syncStatusChanged = existing.ahead !== gitStatus.ahead ||
+ existing.behind !== gitStatus.behind;
+
+ // Compare file list (keys) and total stats, not individual file contents
+ const existingFileKeys = existing.files ? Object.keys(existing.files).sort().join(',') : '';
+ const newFileKeys = gitStatus.files ? Object.keys(gitStatus.files).sort().join(',') : '';
+ const fileListChanged = existingFileKeys !== newFileKeys;
+
+ // Compare total additions/deletions across all files
+ const existingTotal = { additions: 0, deletions: 0 };
+ const newTotal = { additions: 0, deletions: 0 };
+ if (existing.files) {
+ for (const f of Object.values(existing.files)) {
+ existingTotal.additions += f.additions || 0;
+ existingTotal.deletions += f.deletions || 0;
+ }
+ }
+ if (gitStatus.files) {
+ for (const f of Object.values(gitStatus.files)) {
+ newTotal.additions += f.additions || 0;
+ newTotal.deletions += f.deletions || 0;
+ }
+ }
+ const statsChanged = existingTotal.additions !== newTotal.additions ||
+ existingTotal.deletions !== newTotal.deletions;
+
+ if (!branchChanged && !syncStatusChanged && !fileListChanged && !statsChanged) {
+ return; // No meaningful change, skip update
+ }
+ }
+
draft.gitStatus.bySessionId[sessionId] = gitStatus;
}),
clearGitStatus: (sessionId) =>