Skip to content

Commit a629dd0

Browse files
authored
feat(desktop): show git branch in working directory badge (#5082)
1 parent 99d4c12 commit a629dd0

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

packages/desktop/apps/electron/src/renderer/components/app-shell/input/FreeFormInput.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
ChevronDown,
1212
AlertCircle,
1313
CornerDownRight,
14+
GitBranch,
1415
X,
1516
} from 'lucide-react';
1617
import { Icon_Home, Icon_Folder } from '@craft-agent/ui';
@@ -2753,15 +2754,22 @@ function WorkingDirectoryBadge({
27532754

27542755
// Fetch git branch when working directory changes
27552756
React.useEffect(() => {
2757+
let cancelled = false;
2758+
setGitBranch(null);
2759+
27562760
if (workingDirectory) {
27572761
window.electronAPI
27582762
?.getGitBranch?.(workingDirectory)
27592763
.then((branch: string | null) => {
2760-
setGitBranch(branch);
2764+
if (!cancelled) {
2765+
setGitBranch(branch);
2766+
}
27612767
});
2762-
} else {
2763-
setGitBranch(null);
27642768
}
2769+
2770+
return () => {
2771+
cancelled = true;
2772+
};
27652773
}, [workingDirectory]);
27662774

27672775
// Reset filter, refresh history, and focus input when popover opens
@@ -2833,6 +2841,7 @@ function WorkingDirectoryBadge({
28332841
const folderName = hasFolder
28342842
? getPathBasename(workingDirectory) || 'Folder'
28352843
: 'Work in Folder';
2844+
const visibleGitBranch = hasFolder ? gitBranch : null;
28362845

28372846
// Show reset option when a folder is selected and it differs from session folder
28382847
const showReset =
@@ -2854,6 +2863,21 @@ function WorkingDirectoryBadge({
28542863
<FreeFormInputContextBadge
28552864
icon={<Icon_Home className="h-4 w-4" />}
28562865
label={folderName}
2866+
ariaLabel={
2867+
visibleGitBranch
2868+
? `${folderName}, ${t('chat.onBranch', {
2869+
branch: visibleGitBranch,
2870+
})}`
2871+
: folderName
2872+
}
2873+
trailingContent={
2874+
visibleGitBranch ? (
2875+
<span className="inline-flex min-w-0 max-w-[120px] shrink items-center gap-1 text-muted-foreground">
2876+
<GitBranch className="h-3 w-3 shrink-0" />
2877+
<span className="truncate">{visibleGitBranch}</span>
2878+
</span>
2879+
) : undefined
2880+
}
28572881
isExpanded={isEmptySession}
28582882
hasSelection={hasFolder}
28592883
showChevron={true}

packages/desktop/apps/electron/src/renderer/components/app-shell/input/FreeFormInputContextBadge.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ export interface FreeFormInputContextBadgeProps {
99
icon: React.ReactNode
1010
/** Label text - shown in expanded state or collapsed with selection */
1111
label: string
12+
/** Accessible label for the full badge when visible metadata is appended */
13+
ariaLabel?: string
14+
/** Optional trailing metadata shown after the label */
15+
trailingContent?: React.ReactNode
1216
/** Whether to show expanded state (icon + label + chevron) vs collapsed */
1317
isExpanded?: boolean
1418
/** Whether there's an active selection (affects collapsed state styling and shows label) */
@@ -45,6 +49,8 @@ export const FreeFormInputContextBadge = React.forwardRef<HTMLButtonElement, Fre
4549
{
4650
icon,
4751
label,
52+
ariaLabel,
53+
trailingContent,
4854
isExpanded = false,
4955
hasSelection = false,
5056
showChevron = false,
@@ -68,7 +74,7 @@ export const FreeFormInputContextBadge = React.forwardRef<HTMLButtonElement, Fre
6874
<button
6975
ref={mergedRef as React.Ref<HTMLButtonElement>}
7076
type="button"
71-
aria-label={label}
77+
aria-label={ariaLabel ?? label}
7278
onClick={onClick}
7379
disabled={disabled}
7480
data-tutorial={dataTutorial}
@@ -107,6 +113,8 @@ export const FreeFormInputContextBadge = React.forwardRef<HTMLButtonElement, Fre
107113
)
108114
)}
109115

116+
{showLabel && trailingContent}
117+
110118
{/* Optional chevron - only in expanded state */}
111119
{isExpanded && showChevron && (
112120
<ChevronDown className="h-3 w-3 opacity-50 shrink-0" />

0 commit comments

Comments
 (0)