Open-source, local-first AI agent for real work.
TypeScript agent-toolsai-agentbyokcoding-agentcross-platformdesktop-appdeveloper-toolselectronharnessknowledge-basellmwikilocal-firstmcpplugin-systemprivacy-firstskillstypescriptvettaworkflow-automation
import { useTranslation } from "@vetta-org/plugin-sdk";
import type { TurnFileChange } from "../git/turnSnapshot";
import { FileTypeIcon } from "./FileTypeIcon";
import { CommentIcon, RedoIcon, UndoIcon } from "./icons";
import { StatusBadge } from "./StatusBadge";
function splitPath(path: string): { dir: string; name: string } {
const slash = path.lastIndexOf("/");
return slash < 0 ? { dir: "", name: path } : { dir: path.slice(0, slash + 1), name: path.slice(slash + 1) };
}
/**
* One file of a turn, as listed by the turn card and the review view.
*
* The row body opens the file; the trailing button puts it back (or forward
* again). The button only shows on hover or focus so a list of ten files does
* not read as ten calls to action, but it stays keyboard-reachable.
*/
export function TurnFileRow({
file,
reverted,
active = false,
commentCount = 0,
busy,
onOpen,
onToggle,
}: {
file: TurnFileChange;
reverted: boolean;
active?: boolean;
commentCount?: number;
busy: boolean;
onOpen: () => void;
onToggle: () => void;
}): JSX.Element {
const { t } = useTranslation();
const { dir, name } = splitPath(file.path);
const title = file.origPath ? `${file.origPath} → ${file.path}` : file.path;
return (
<div
className={`group/row flex items-center rounded-md transition-colors ${active ? "bg-accent/60" : "hover:bg-accent/40"}`}
data-reverted={reverted || undefined}
>
<button
type="button"
onClick={onOpen}
title={title}
aria-current={active || undefined}
className="flex min-w-0 flex-1 items-center gap-2 py-1 pl-1 text-left text-foreground outline-none focus-visible:ring-1 focus-visible:ring-ring/50 rounded-md"
>
<FileTypeIcon path={file.path} className={`h-4 w-4 shrink-0 ${reverted ? "opacity-40" : ""}`} />
<span className={`min-w-0 flex-1 truncate ${reverted ? "text-muted-foreground line-through decoration-muted-foreground/40" : ""}`}>
<span>{name}</span>
{dir && <span className="text-muted-foreground/50"> {dir}</span>}
</span>
{commentCount > 0 && (
<span className="flex shrink-0 items-center gap-0.5 text-[11px] text-sky-500" title={t("review.commentCount", { count: commentCount })}>
<CommentIcon className="h-3 w-3" />
{commentCount}
</span>
)}
{reverted ? (
<span className="shrink-0 text-[11px] text-muted-foreground">{t("review.revertedTag")}</span>
) : file.binary ? (
<span className="shrink-0 text-[11px] text-muted-foreground">{t("review.binaryTag")}</span>
) : (
<span className="flex shrink-0 items-center gap-1 text-[11px] tabular-nums">
{file.additions > 0 && <span className="text-emerald-500/90">+{file.additions}</span>}
{file.deletions > 0 && <span className="text-rose-500/90">−{file.deletions}</span>}
</span>
)}
<StatusBadge code={file.code} />
</button>
<button
type="button"
disabled={busy}
onClick={onToggle}
title={t(reverted ? "review.restoreFile" : "review.revertFile")}
aria-label={t(reverted ? "review.restoreFile" : "review.revertFile")}
className="mx-0.5 flex size-6 shrink-0 items-center justify-center rounded-md text-muted-foreground opacity-0 outline-none transition-[opacity,color,background-color] hover:bg-accent hover:text-foreground focus-visible:opacity-100 focus-visible:ring-1 focus-visible:ring-ring/50 group-hover/row:opacity-100 disabled:pointer-events-none disabled:opacity-30 data-[pinned=true]:opacity-100"
data-pinned={reverted || undefined}
>
{reverted ? <RedoIcon className="h-3.5 w-3.5" /> : <UndoIcon className="h-3.5 w-3.5" />}
</button>
</div>
);
}