'use client'; import { memo, useState } from 'react'; import Link from 'next/link'; import { useRouter } from 'next/navigation'; import { IconArrowLeft, IconBug, IconCopy, IconDots, IconGitBranch, IconCheck, IconSettings, } from '@tabler/icons-react'; import { Button } from '@kandev/ui/button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, DropdownMenuSeparator, } from '@kandev/ui/dropdown-menu'; import { Tooltip, TooltipContent, TooltipTrigger } from '@kandev/ui/tooltip'; import { Popover, PopoverContent, PopoverTrigger } from '@kandev/ui/popover'; import { CommitStatBadge } from '@/components/diff-stat'; import { useSessionGitStatus } from '@/hooks/domains/session/use-session-git-status'; import { formatUserHomePath } from '@/lib/utils'; import { EditorsMenu } from '@/components/task/editors-menu'; import { DocumentControls } from '@/components/task/document/document-controls'; import { VcsSplitButton } from '@/components/vcs-split-button'; import { DEBUG_UI } from '@/lib/config'; type TaskTopBarProps = { taskId?: string | null; activeSessionId?: string | null; taskTitle?: string; taskDescription?: string; baseBranch?: string; onStartAgent?: (agentProfileId: string) => void; onStopAgent?: () => void; isAgentRunning?: boolean; isAgentLoading?: boolean; worktreePath?: string | null; worktreeBranch?: string | null; repositoryPath?: string | null; repositoryName?: string | null; showDebugOverlay?: boolean; onToggleDebugOverlay?: () => void; }; const TaskTopBar = memo(function TaskTopBar({ activeSessionId, taskTitle, baseBranch, worktreePath, worktreeBranch, repositoryPath, repositoryName, showDebugOverlay, onToggleDebugOverlay, }: TaskTopBarProps) { const [copiedBranch, setCopiedBranch] = useState(false); const [popoverOpen, setPopoverOpen] = useState(false); const [copiedRepo, setCopiedRepo] = useState(false); const [copiedWorktree, setCopiedWorktree] = useState(false); const [moreMenuOpen, setMoreMenuOpen] = useState(false); const router = useRouter(); const gitStatus = useSessionGitStatus(activeSessionId ?? null); // Use worktree branch if available, otherwise fall back to base branch const displayBranch = worktreeBranch || baseBranch; const handleBranchClick = (e: React.MouseEvent) => { e.stopPropagation(); if (displayBranch) { navigator.clipboard?.writeText(displayBranch); setCopiedBranch(true); setTimeout(() => setCopiedBranch(false), 500); } }; // Preview controls are handled by a dedicated component. const handleCopyRepo = (e: React.MouseEvent) => { e.stopPropagation(); if (repositoryPath) { navigator.clipboard?.writeText(formatUserHomePath(repositoryPath)); setCopiedRepo(true); setTimeout(() => setCopiedRepo(false), 500); } }; const handleCopyWorktree = (e: React.MouseEvent) => { e.stopPropagation(); if (worktreePath) { navigator.clipboard?.writeText(formatUserHomePath(worktreePath)); setCopiedWorktree(true); setTimeout(() => setCopiedWorktree(false), 500); } }; return (
{repositoryName && ( <> {repositoryName} › )} {taskTitle ?? 'Task details'} {displayBranch && (
{displayBranch}
Current branch
{repositoryPath && (
Repository
{formatUserHomePath(repositoryPath)}
)} {worktreePath && (
Worktree
{formatUserHomePath(worktreePath)}
)}
)} {/* Git Status: Ahead/Behind */} {((gitStatus?.ahead ?? 0) > 0 || (gitStatus?.behind ?? 0) > 0) && (
{(gitStatus?.ahead ?? 0) > 0 && ( {gitStatus?.ahead ?? 0} commit{(gitStatus?.ahead ?? 0) !== 1 ? 's' : ''} ahead of {gitStatus?.remote_branch || 'remote'} )} {(gitStatus?.behind ?? 0) > 0 && ( {gitStatus?.behind ?? 0} commit{(gitStatus?.behind ?? 0) !== 1 ? 's' : ''} behind {gitStatus?.remote_branch || 'remote'} )}
)}
{DEBUG_UI && onToggleDebugOverlay && ( {showDebugOverlay ? 'Hide Debug Info' : 'Show Debug Info'} )} {/* More Options (3-dot) Dropdown */} { if (worktreePath) { navigator.clipboard?.writeText(worktreePath); } }} disabled={!worktreePath} > Copy workspace path router.push('/settings/general')} > Open Settings
); }); export { TaskTopBar };