import { Button, LinkButton } from "../ui/button"; import { Badge, ClipboardText } from "../ui/feedback"; import { Breadcrumbs, TabCount, Tabs } from "../ui/navigation"; import { DropdownMenu, Popover, Tooltip } from "../ui/overlay"; import { Empty } from "./empty"; import { LayerCard } from "./surface"; import { ArrowClockwiseIcon, BookOpenIcon, CalendarIcon, CaretDownIcon, ClockCounterClockwiseIcon, CubeIcon, FileIcon, FolderIcon, GitBranchIcon, GitForkIcon, HourglassIcon, TagIcon, } from "../icons"; import { isCommitHash, repoLink, type CommitCheck, type CommitSummary, type LastChanges, type OnlineAgent, type RefList, type RepoSummary, type Tree, type TreeEntry } from "@refs/backend/contract"; import { formatDate } from "../format"; import { Link } from "../provider"; import { AgentAvatar, Avatar } from "./brand"; import { Ago } from "./ago"; export type RepoTab = "code" | "map" | "tasks" | "pulls" | "agents" | "runs" | "settings"; export function RepoTabs({ repo, current, signedIn }: { repo: RepoSummary; current: RepoTab; signedIn: boolean }) { const hrefs: Record = { code: `/${repo.name}`, map: `/${repo.name}/map`, tasks: `/${repo.name}/tasks`, pulls: `/${repo.name}/pulls`, agents: `/${repo.name}/agents`, runs: `/${repo.name}/runs`, settings: `/${repo.name}/settings` }; const tab = (value: RepoTab, label: string, count?: number) => ({ value, label: ( {label} {count ? {count} : null} ), nativeButton: false, render: (props: React.AnchorHTMLAttributes) => , }); const tabs = [ tab("code", "Code"), tab("map", "Map"), ...(signedIn ? [tab("tasks", "Tasks", repo.openTasks), tab("pulls", "Pull requests", repo.openPulls)] : []), ...(signedIn && repo.can.write ? [tab("agents", "Agents")] : []), tab("runs", "Runs"), ...(repo.can.admin ? [tab("settings", "Settings")] : []), ]; return ; } function MetaItem({ icon, children }: { icon: React.ReactNode; children: React.ReactNode }) { return (
  • {icon} {children}
  • ); } export function RepoTitle({ repo, signedIn, agents }: { repo: RepoSummary; signedIn: boolean; agents: readonly OnlineAgent[] }) { const slash = repo.name.indexOf("/"); return (

    {repo.name.slice(0, slash + 1)} {repo.name.slice(slash + 1)}

    {repo.visibility === "public" ? "Public" : "Private"}
    {signedIn && ( }> Fork {repo.forks} )}
    {repo.description &&

    {repo.description}

    }
      {repo.origin?.kind === "fork" && repo.origin.repo && ( }> Forked from{" "} {repo.origin.repo} )} {repo.origin?.kind === "import" && ( }> Imported from {repo.origin.url.replace(/^https:\/\//, "")} )} }>Created {formatDate(repo.createdAt)} {agents.length === 0 && }>No agents online}
    ); } export function AgentsOnline({ repo, agents }: { repo: string; agents: readonly OnlineAgent[] }) { return ( Agents online {agents.length} {agents.length === 0 ? (

    No agents are connected right now.

    ) : (
      {agents.map((agent) => (
    • {agent.runtime} for {agent.onBehalfOf.name} {agent.branch ? {agent.branch} : "idle"}
    • ))}
    )}
    ); } function refLabel(ref: string): string { return isCommitHash(ref) ? ref.slice(0, 7) : ref; } export function BranchPicker({ repo, refs, current }: { repo: string; refs: RefList; current: string }) { return ( }> {refLabel(current)} } /> Branches {refs.branches.map((name) => ( }> {name} {name === refs.defaultRef && default} ))} {refs.tags.length > 0 && ( <> Tags {refs.tags.map((name) => ( }> {name} ))} )} View all branches ); } export function PathBreadcrumbs({ repo, current, path }: { repo: string; current: string; path: readonly string[] }) { return ( {repo} {path.map((segment, i) => ( {i === path.length - 1 ? ( {segment} ) : ( {segment} )} ))} ); } export function CloneMenu({ url }: { url: string }) { return ( Code } /> Clone with HTTPS
    Use an{" "} access token {" "} as the password.
    ); } const CHECK_DOT: Record = { succeeded: "bg-success", running: "bg-needs", failed: "bg-danger" }; function CheckDot({ check }: { check: CommitCheck }) { return ( } className="hit-area relative inline-flex size-2 shrink-0 rounded-full"> ); } export function CommitBar({ repo, current, commit, now, check }: { repo: string; current: string; commit: CommitSummary; now: number; check?: CommitCheck | null }) { const agent = commit.pushedBy?.actor.kind === "agent"; return (
    {agent ? : } {commit.author} {commit.title}
    {check && } {commit.hash.slice(0, 7)} History
    ); } function EntryIcon({ type }: { type: TreeEntry["type"] }) { if (type === "tree") return ; if (type === "gitlink") return ; return ; } const ROW = "grid grid-cols-[minmax(0,1fr)_auto] items-center gap-4 px-4 py-2 text-compact shadow-[inset_0_-1px_0_var(--hairline)] last:shadow-none sm:grid-cols-[minmax(0,2fr)_minmax(0,3fr)_7rem] hover:bg-hover transition-colors duration-150"; export function FileList({ repo, current, path, tree, now, last, check }: { repo: string; current: string; path: readonly string[]; tree: Tree; now: number; last?: LastChanges; check?: CommitCheck | null }) { return (
      {path.length > 0 && (
    • ..
    • )} {tree.entries.map((entry) => { const change = last?.changes[entry.name]; return (
    • {entry.type === "gitlink" ? ( {entry.name} ) : ( {entry.name} )} {change ? ( {change.title} ) : last ? null : ( )} {change ? : null}
    • ); })}
    ); } export function Readme({ readme }: { readme: NonNullable }) { return ( {readme.name}
    ); } export function TreeView({ repo, cloneUrl, refs, current, path, tree, now, last, check, }: { repo: string; cloneUrl: string; refs: RefList; current: string; path: readonly string[]; tree: Tree; now: number; last?: LastChanges; check?: CommitCheck | null; }) { const plural = (count: number, one: string, many: string) => `${count} ${count === 1 ? one : many}`; return (
    {path.length > 0 ? ( ) : (
    {refs.branches.length} {plural(refs.branches.length, "branch", "branches").replace(/^\d+ /, "")} {refs.tags.length} {plural(refs.tags.length, "tag", "tags").replace(/^\d+ /, "")}
    )}
    {tree.readme && }
    ); } export function QuickSetup({ repo, cloneUrl }: { repo: string; cloneUrl: string }) { return ( Quick setup

    Create a new repository on the command line

    {`echo "# ${repo}" >> README.md
    git init -b main
    git add README.md
    git commit -m "first commit"
    git remote add origin ${cloneUrl}
    git push -u origin main`}

    Push an existing repository from the command line

    {`git remote add origin ${cloneUrl}
    git push -u origin main`}

    Use an{" "} access token {" "} as the password when Git asks.

    ); } export function Preparing({ repo }: { repo: string }) { return ( } title="This repository is being prepared" description="Copying history can take a moment for large repositories." contents={ }> Refresh } /> ); }