"use client"; import type { ReactNode } from "react"; import { IconChevronDown, IconPlus, IconRocket } from "@tabler/icons-react"; import { Button } from "@kandev/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@kandev/ui/dropdown-menu"; import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip"; import { cn } from "@kandev/ui/lib/utils"; /** * Split-button: primary "Implement" runs the plan inline in the current * session; the dropdown caret offers "Implement in fresh agent" which starts * a new session with a clean context window. `onClick(fresh)` is invoked * with `false` for the primary path and `true` for the fresh-agent path. */ type ImplementPlanButtonProps = { onClick: (fresh: boolean) => void | Promise; disabled?: boolean; disabledReason?: string; framed?: boolean; testIds?: { root?: string; button?: string; menuTrigger?: string; freshItem?: string; }; }; function legacyRootTestId(rootId: string) { return rootId === "implement-plan-control" ? undefined : "implement-plan-control"; } function DisabledImplementTooltip({ disabledReason, children, }: { disabledReason: string; children: ReactNode; }) { return ( {children} {disabledReason} ); } export function ImplementPlanButton({ onClick, disabled, disabledReason, framed, testIds, }: ImplementPlanButtonProps) { const ids = { root: testIds?.root ?? "implement-plan-control", button: testIds?.button ?? "implement-plan-button", menuTrigger: testIds?.menuTrigger ?? "implement-plan-menu-trigger", freshItem: testIds?.freshItem ?? "implement-fresh-menu-item", }; const primaryButton = ( ); const primary = disabledReason ? ( primaryButton ) : ( {primaryButton} Implement the plan in this session ); const splitButton = (
{primary} onClick(true)} className="cursor-pointer" >
Implement in fresh agent
Starts a new session with a clean context window
); if (!disabledReason) return splitButton; return ( {splitButton} ); }