From ba0a755040f0b4e02798d22070c34d9c1e8ac59b Mon Sep 17 00:00:00 2001 From: Bohdan Triapitsyn Date: Mon, 15 Jun 2026 15:26:08 +0300 Subject: [PATCH] fix: sync pending changes with active directory Uses the effective directory for composer git status Prevents stale pending changes after commit or push Keeps the dropdown aligned with the git panel --- packages/ui/src/components/chat/ChatInput.tsx | 4 +++- packages/ui/src/components/chat/PendingChangesBar.tsx | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/ui/src/components/chat/ChatInput.tsx b/packages/ui/src/components/chat/ChatInput.tsx index 64696d3f..df5e191d 100644 --- a/packages/ui/src/components/chat/ChatInput.tsx +++ b/packages/ui/src/components/chat/ChatInput.tsx @@ -64,6 +64,7 @@ import { useDirectoryStore } from '@/stores/useDirectoryStore'; import { useSkillsStore } from '@/stores/useSkillsStore'; import { useCommandsStore } from '@/stores/useCommandsStore'; import { useRuntimeAPIs } from '@/hooks/useRuntimeAPIs'; +import { useEffectiveDirectory } from '@/hooks/useEffectiveDirectory'; import { createWorktreeDraft } from '@/lib/worktreeSessionCreator'; import { buildSessionTargetOptions } from '@/sync/session-worktree-contract'; import { usePermissionStore } from '@/stores/permissionStore'; @@ -988,7 +989,8 @@ const ChatInputComponent: React.FC = ({ onOpenSettings, scrollTo Promise.resolve((useSessionUIStore.getState().sendMessage as (...a: unknown[]) => unknown)(...args)), ).current; const currentSessionId = useSessionUIStore((s) => s.currentSessionId); - const currentDirectory = useDirectoryStore((s) => s.currentDirectory); + const fallbackDirectory = useDirectoryStore((s) => s.currentDirectory); + const currentDirectory = useEffectiveDirectory() ?? fallbackDirectory; const currentSessionDirectoryForSync = useSessionUIStore( React.useCallback((s) => currentSessionId ? s.getDirectoryForSession(currentSessionId) : null, [currentSessionId]), ); diff --git a/packages/ui/src/components/chat/PendingChangesBar.tsx b/packages/ui/src/components/chat/PendingChangesBar.tsx index bd8cb31d..9427b5a0 100644 --- a/packages/ui/src/components/chat/PendingChangesBar.tsx +++ b/packages/ui/src/components/chat/PendingChangesBar.tsx @@ -1,9 +1,9 @@ import React from 'react'; -import { useDirectoryStore } from '@/stores/useDirectoryStore'; import { useGitStore, useIsGitRepo } from '@/stores/useGitStore'; import { useUIStore } from '@/stores/useUIStore'; import { RuntimeAPIContext } from '@/contexts/runtimeAPIContext'; import { useMobileAppActions } from '@/apps/mobileAppContext'; +import { useEffectiveDirectory } from '@/hooks/useEffectiveDirectory'; import { Icon } from "@/components/icon/Icon"; import { cn } from '@/lib/utils'; import { @@ -20,7 +20,7 @@ export const PendingChangesBar: React.FC = React.memo(() => { const { t } = useI18n(); const [isExpanded, setIsExpanded] = React.useState(false); const popoverRef = React.useRef(null); - const currentDirectory = useDirectoryStore((s) => s.currentDirectory); + const currentDirectory = useEffectiveDirectory() ?? null; const runtime = React.useContext(RuntimeAPIContext); const isGitRepo = useIsGitRepo(currentDirectory); const gitStatus = useGitStore((s) => @@ -43,7 +43,7 @@ export const PendingChangesBar: React.FC = React.memo(() => { }, [isExpanded]); const gitChangedFiles = React.useMemo(() => { - if (isGitRepo !== true || !gitStatus || gitStatus.isClean) return []; + if (!currentDirectory || isGitRepo !== true || !gitStatus || gitStatus.isClean) return []; return extractGitChangedFiles(gitStatus.files, gitStatus.diffStats, currentDirectory); }, [isGitRepo, gitStatus, currentDirectory]); @@ -57,7 +57,7 @@ export const PendingChangesBar: React.FC = React.memo(() => { return { totalAdded: added, totalRemoved: removed }; }, [gitChangedFiles]); - if (isGitRepo !== true) return null; + if (!currentDirectory || isGitRepo !== true) return null; if (gitChangedFiles.length === 0) return null; const handleOpenFile = (file: ChangedFileEntry) => {