g1t/apps/web/app/components/mission-control.tsx
| 1 | import { ArrowDownWideNarrow, ArrowRight, ArrowUpRight, Check, ChevronDown, ChevronRight, Plus, Sparkles } from "lucide-react"; |
| 2 | import { type ReactNode, useEffect, useState } from "react"; |
| 3 | import { Link, useFetcher, useRouteLoaderData, useSearchParams } from "react-router"; |
| 4 | |
| 5 | import { trialClosed } from "../lib/trial"; |
| 6 | import { type ActivityGroup, type Verb, greetingFor, isAgent } from "../lib/mission"; |
| 7 | import { |
| 8 | BLOCKING, |
| 9 | type Fact, |
| 10 | type LandedRow, |
| 11 | type NeedRow, |
| 12 | type QuickAction, |
| 13 | REASON_LABEL, |
| 14 | type Reason, |
| 15 | type Sort, |
| 16 | type Tab, |
| 17 | type WaitingRow, |
| 18 | type Week, |
| 19 | type Who, |
| 20 | change, |
| 21 | dateLine, |
| 22 | parseSort, |
| 23 | parseTab, |
| 24 | signedPercent, |
| 25 | sortRows, |
| 26 | usd, |
| 27 | whyFor, |
| 28 | } from "../lib/mission-control"; |
| 29 | import { cn } from "../lib/cn"; |
| 30 | import { AgentComposer, type ComposerResult } from "./agent-composer"; |
| 31 | import { AgentSetup } from "./agent-setup"; |
| 32 | import type { ShellData } from "./shell"; |
| 33 | import { useLiveRefresh } from "./agents"; |
| 34 | import { Unavailable } from "./mission"; |
| 35 | import { TokenUsagePanel } from "./token-usage"; |
| 36 | import { Avatar, TimeAgo } from "./ui"; |
| 37 | import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuTrigger } from "./ui/dropdown-menu"; |
| 38 | import type { Loaded } from "../routes/home"; |
| 39 | |
| 40 | /* |
| 41 | * Mission control: the home page of someone signed in. It answers where |
| 42 | * the viewer is needed, what agents are doing, and what landed without |
| 43 | * them. It is a chunk of its own, loaded only for them, so the signed-out |
| 44 | * home page does not carry it. routes/home.tsx loads its data; |
| 45 | * lib/mission-control.ts shapes it. |
| 46 | */ |
| 47 | |
| 48 | /** The viewer's time zone, set by the page itself, so the greeting fits their day. */ |
| 49 | const TZ_COOKIE = "g1t_tz"; |
| 50 | /** Rows a tab shows before "See all". */ |
| 51 | const ROWS = 6; |
| 52 | |
| 53 | const dollars = (micros: number) => `$${(Math.max(0, micros) / 1_000_000).toFixed(2)}`; |
| 54 | const plural = (n: number, one: string, many = `${one}s`) => `${n.toLocaleString("en-US")} ${n === 1 ? one : many}`; |
| 55 | |
| 56 | // --- Small pieces ----------------------------------------------------------------- |
| 57 | |
| 58 | const CHIP_TONE: Record<Reason, string> = { |
| 59 | blocking: "border-danger/35 bg-danger/10 text-danger", |
| 60 | checks_failing: "border-danger/35 bg-danger/10 text-danger", |
| 61 | outside_guardrails: "border-warn/35 bg-warn/10 text-warn", |
| 62 | low_confidence: "border-warn/35 bg-warn/10 text-warn", |
| 63 | stalled: "border-warn/35 bg-warn/10 text-warn", |
| 64 | asked_for_you: "border-merged/35 bg-merged/10 text-merged", |
| 65 | needs_review: "border-info/35 bg-info/10 text-info", |
| 66 | ready_to_merge: "border-accent/35 bg-accent/10 text-accent", |
| 67 | }; |
| 68 | |
| 69 | function Chip({ children, tone }: { children: ReactNode; tone: string }) { |
| 70 | return ( |
| 71 | <span |
| 72 | className={cn( |
| 73 | "inline-flex shrink-0 items-center rounded border px-1.5 py-px font-mono text-[0.625rem] font-medium tracking-wider whitespace-nowrap uppercase", |
| 74 | tone, |
| 75 | )} |
| 76 | > |
| 77 | {children} |
| 78 | </span> |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | /** A person or an agent, by name, wearing the mark that tells them apart. */ |
| 83 | function Person({ who, size = 16, className }: { who: Who; size?: number; className?: string }) { |
| 84 | return ( |
| 85 | <span className={cn("inline-flex min-w-0 items-center gap-1.5", className)}> |
| 86 | <Avatar name={who.name} size={size} /> |
| 87 | <span className="truncate">{who.name}</span> |
| 88 | </span> |
| 89 | ); |
| 90 | } |
| 91 | |
| 92 | function Eyebrow({ children }: { children: ReactNode }) { |
| 93 | return <p className="font-mono text-[0.625rem] font-medium tracking-[0.12em] text-faint uppercase">{children}</p>; |
| 94 | } |
| 95 | |
| 96 | const FACT_TONE = { good: "text-accent", warn: "text-warn", bad: "text-danger" } as const; |
| 97 | |
| 98 | function Facts({ facts }: { facts: Fact[] }) { |
| 99 | if (facts.length === 0) return <p className="text-sm text-muted">Nothing more is known about it yet.</p>; |
| 100 | return ( |
| 101 | <dl className="grid grid-cols-2 gap-x-4 gap-y-2.5"> |
| 102 | {facts.map((fact) => ( |
| 103 | <div key={fact.label} className={cn("min-w-0", fact.wide && "col-span-2")}> |
| 104 | <dt className="text-xs text-faint">{fact.label}</dt> |
| 105 | <dd |
| 106 | className={cn( |
| 107 | "mt-0.5 text-sm font-medium tabular-nums", |
| 108 | fact.wide ? "leading-5" : "truncate", |
| 109 | fact.tone ? FACT_TONE[fact.tone] : "text-fg-soft", |
| 110 | )} |
| 111 | > |
| 112 | {fact.value} |
| 113 | </dd> |
| 114 | </div> |
| 115 | ))} |
| 116 | </dl> |
| 117 | ); |
| 118 | } |
| 119 | |
| 120 | /** A form that acts on a pull request from here, saying so before the page catches up. */ |
| 121 | function QuickForm({ quick, variant = "quiet" }: { quick: QuickAction; variant?: "quiet" | "accent" }) { |
| 122 | const fetcher = useFetcher<{ error?: string } | null>(); |
| 123 | const [sent, setSent] = useState(false); |
| 124 | const busy = fetcher.state !== "idle"; |
| 125 | // Shown as done the moment it is sent, and undone if it fails: the page |
| 126 | // reloads behind it, which takes longer than the action. |
| 127 | const done = sent && (busy || !fetcher.data?.error); |
| 128 | return ( |
| 129 | <fetcher.Form method="post" action={quick.to} onSubmit={() => setSent(true)} className="contents"> |
| 130 | {Object.entries(quick.fields).map(([name, value]) => ( |
| 131 | <input key={name} type="hidden" name={name} value={value} /> |
| 132 | ))} |
| 133 | <button |
| 134 | type="submit" |
| 135 | disabled={busy || done} |
| 136 | className={cn( |
| 137 | "inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-sm font-medium transition-colors disabled:cursor-default", |
| 138 | variant === "accent" |
| 139 | ? "bg-merged text-bg hover:bg-[#c9bfff]" |
| 140 | : "border border-line-strong text-fg/90 hover:bg-raised hover:text-fg", |
| 141 | done && "border-accent/40 text-accent", |
| 142 | )} |
| 143 | > |
| 144 | {done ? <Check size={14} /> : null} |
| 145 | {done ? quick.done : quick.label} |
| 146 | </button> |
| 147 | {fetcher.data?.error && <span className="basis-full text-xs text-danger">{fetcher.data.error}</span>} |
| 148 | </fetcher.Form> |
| 149 | ); |
| 150 | } |
| 151 | |
| 152 | function ProjectMark({ repo }: { repo: { namespace: string; name: string } | null }) { |
| 153 | return <Avatar name={repo ? repo.name : "g1t"} size={32} square />; |
| 154 | } |
| 155 | |
| 156 | /** A row that opens to what is known about it; the first one starts open. */ |
| 157 | function Row({ |
| 158 | open, |
| 159 | repo, |
| 160 | by, |
| 161 | title, |
| 162 | sub, |
| 163 | chip, |
| 164 | at, |
| 165 | children, |
| 166 | }: { |
| 167 | open: boolean; |
| 168 | repo: { namespace: string; name: string } | null; |
| 169 | by: Who | null; |
| 170 | title: ReactNode; |
| 171 | sub: ReactNode; |
| 172 | chip: ReactNode; |
| 173 | at: number; |
| 174 | children: ReactNode; |
| 175 | }) { |
| 176 | return ( |
| 177 | <li> |
| 178 | <details open={open} className="group"> |
| 179 | <summary className="flex cursor-pointer list-none items-center gap-3 px-4 py-3 transition-colors select-none hover:bg-raised/60 sm:px-5 [&::-webkit-details-marker]:hidden"> |
| 180 | <ProjectMark repo={repo} /> |
| 181 | <span className="min-w-0 grow"> |
| 182 | <span className="block truncate text-sm">{title}</span> |
| 183 | <span className="mt-0.5 flex min-w-0 items-center gap-1.5 text-xs text-muted"> |
| 184 | <span className="shrink-0 font-medium text-fg-soft">{repo ? repo.name : "Workspace"}</span> |
| 185 | {by && ( |
| 186 | <> |
| 187 | <span className="text-faint">·</span> |
| 188 | <Person who={by} size={14} className={cn("shrink-0", by.agent ? "text-merged" : "")} /> |
| 189 | </> |
| 190 | )} |
| 191 | {sub && ( |
| 192 | <> |
| 193 | <span className="text-faint">—</span> |
| 194 | <span className="truncate">{sub}</span> |
| 195 | </> |
| 196 | )} |
| 197 | </span> |
| 198 | </span> |
| 199 | <span className="hidden sm:inline-flex">{chip}</span> |
| 200 | <span className="hidden w-16 shrink-0 text-right text-xs text-faint sm:block"> |
| 201 | <TimeAgo at={at} /> |
| 202 | </span> |
| 203 | <ChevronDown size={16} className="shrink-0 text-faint transition-transform group-open:rotate-180" /> |
| 204 | </summary> |
| 205 | <div className="px-4 pb-4 sm:px-5 sm:pb-5"> |
| 206 | <div className="mb-3 flex items-center gap-2 sm:hidden"> |
| 207 | {chip} |
| 208 | <span className="text-xs text-faint"> |
| 209 | <TimeAgo at={at} /> |
| 210 | </span> |
| 211 | </div> |
| 212 | {children} |
| 213 | </div> |
| 214 | </details> |
| 215 | </li> |
| 216 | ); |
| 217 | } |
| 218 | |
| 219 | function NeedCard({ row, first }: { row: NeedRow; first: boolean }) { |
| 220 | const isPull = row.to.includes("/pull/"); |
| 221 | return ( |
| 222 | <Row |
| 223 | open={first} |
| 224 | repo={row.repo} |
| 225 | by={row.by} |
| 226 | title={ |
| 227 | <> |
| 228 | <span className="font-medium">{row.title}</span> |
| 229 | {row.ref && <span className="ml-1 font-mono text-xs text-faint">{row.ref}</span>} |
| 230 | </> |
| 231 | } |
| 232 | sub={row.ask} |
| 233 | chip={<Chip tone={CHIP_TONE[row.reason]}>{REASON_LABEL[row.reason]}</Chip>} |
| 234 | at={row.at} |
| 235 | > |
| 236 | <div className="grid gap-4 rounded-xl border border-line bg-bg/50 p-4 md:grid-cols-2 md:gap-x-6 2xl:grid-cols-[minmax(0,1.1fr)_minmax(0,1fr)_minmax(0,0.95fr)]"> |
| 237 | <div className="min-w-0"> |
| 238 | <Eyebrow>The ask</Eyebrow> |
| 239 | <p className="mt-2 text-sm leading-6 text-fg-soft">{row.ask}</p> |
| 240 | <p className="mt-2 text-xs leading-5 text-muted"> |
| 241 | <Link to={row.to} className="font-medium text-fg hover:underline"> |
| 242 | {row.repo ? `${row.repo.name}${row.ref ?? ""}` : row.title} |
| 243 | </Link> |
| 244 | {row.for && ( |
| 245 | <> |
| 246 | {" "} |
| 247 | · started for <span className="text-fg-soft">{row.for}</span> |
| 248 | </> |
| 249 | )} |
| 250 | </p> |
| 251 | </div> |
| 252 | <div className="min-w-0"> |
| 253 | <Eyebrow>What the agent already knows</Eyebrow> |
| 254 | <div className="mt-2"> |
| 255 | <Facts facts={row.facts} /> |
| 256 | </div> |
| 257 | </div> |
| 258 | <div className="rounded-lg border border-warn/20 bg-warn/[0.06] p-3.5 md:col-span-2 2xl:col-span-1"> |
| 259 | <p className="text-xs font-semibold text-warn">Why this needs you</p> |
| 260 | <p className="mt-1.5 text-sm leading-6 text-fg-soft">{row.why}</p> |
| 261 | <p className="mt-2 text-xs text-faint"> |
| 262 | Waiting <TimeAgo at={row.at} /> |
| 263 | </p> |
| 264 | </div> |
| 265 | </div> |
| 266 | <div className="mt-3 flex flex-wrap items-center gap-2"> |
| 267 | <Link |
| 268 | to={row.to} |
| 269 | prefetch="intent" |
| 270 | className="inline-flex items-center gap-1.5 rounded-md bg-fg px-3 py-1.5 text-sm font-medium text-bg transition-colors hover:bg-white" |
| 271 | > |
| 272 | Review and respond <ArrowUpRight size={14} /> |
| 273 | </Link> |
| 274 | {row.quick && <QuickForm quick={row.quick} />} |
| 275 | {row.link && ( |
| 276 | <Link |
| 277 | to={row.link.to} |
| 278 | className="inline-flex items-center rounded-md border border-line-strong px-3 py-1.5 text-sm font-medium text-fg/90 hover:bg-raised hover:text-fg" |
| 279 | > |
| 280 | {row.link.label} |
| 281 | </Link> |
| 282 | )} |
| 283 | {row.open !== row.to && ( |
| 284 | <Link to={row.open} prefetch="intent" className="px-2 py-1.5 text-sm text-muted hover:text-fg"> |
| 285 | {row.open.includes("/issues/") ? "Open issue" : isPull ? "See the changes" : "Open pull request"} |
| 286 | </Link> |
| 287 | )} |
| 288 | </div> |
| 289 | </Row> |
| 290 | ); |
| 291 | } |
| 292 | |
| 293 | function WaitingCard({ row, first }: { row: WaitingRow; first: boolean }) { |
| 294 | return ( |
| 295 | <Row |
| 296 | open={first} |
| 297 | repo={row.repo} |
| 298 | by={row.by} |
| 299 | title={ |
| 300 | <> |
| 301 | <span className="font-medium">{row.title}</span> |
| 302 | {row.ref && <span className="ml-1 font-mono text-xs text-faint">{row.ref}</span>} |
| 303 | </> |
| 304 | } |
| 305 | sub={row.detail} |
| 306 | chip={ |
| 307 | <Chip tone="border-line-strong bg-raised text-muted"> |
| 308 | {row.live && <span className="mr-1.5 size-1.5 animate-pulse rounded-full bg-accent" />} |
| 309 | {row.chip} |
| 310 | </Chip> |
| 311 | } |
| 312 | at={row.at} |
| 313 | > |
| 314 | <div className="grid gap-4 rounded-xl border border-line bg-bg/50 p-4 md:grid-cols-2 md:gap-6"> |
| 315 | <div className="min-w-0"> |
| 316 | <Eyebrow>{row.live ? "Doing now" : "Where it stands"}</Eyebrow> |
| 317 | <p className="mt-2 text-sm leading-6 text-fg-soft">{row.detail}</p> |
| 318 | </div> |
| 319 | <div className="min-w-0"> |
| 320 | <Eyebrow>What is known</Eyebrow> |
| 321 | <div className="mt-2"> |
| 322 | <Facts facts={row.facts} /> |
| 323 | </div> |
| 324 | </div> |
| 325 | </div> |
| 326 | <div className="mt-3 flex flex-wrap gap-2"> |
| 327 | <Link |
| 328 | to={row.to} |
| 329 | prefetch="intent" |
| 330 | className="inline-flex items-center gap-1.5 rounded-md border border-line-strong px-3 py-1.5 text-sm font-medium text-fg/90 hover:bg-raised hover:text-fg" |
| 331 | > |
| 332 | {row.to.includes("/runs/") ? "Watch the run" : "Open pull request"} <ArrowUpRight size={14} /> |
| 333 | </Link> |
| 334 | {row.run && row.run !== row.to && ( |
| 335 | <Link to={row.run} prefetch="intent" className="px-2 py-1.5 text-sm text-muted hover:text-fg"> |
| 336 | Watch the run |
| 337 | </Link> |
| 338 | )} |
| 339 | </div> |
| 340 | </Row> |
| 341 | ); |
| 342 | } |
| 343 | |
| 344 | function LandedCard({ row, first }: { row: LandedRow; first: boolean }) { |
| 345 | return ( |
| 346 | <Row |
| 347 | open={first} |
| 348 | repo={row.repo} |
| 349 | by={row.byAgents ? { name: row.agent, agent: isAgent(row.agent) } : row.by} |
| 350 | title={ |
| 351 | <> |
| 352 | <span className="font-medium">{row.title}</span> |
| 353 | <span className="ml-1 font-mono text-xs text-faint">{row.ref}</span> |
| 354 | </> |
| 355 | } |
| 356 | sub={row.byAgents ? "landed without a person" : `merged by ${row.by?.name ?? "a person"}`} |
| 357 | chip={ |
| 358 | row.byAgents ? ( |
| 359 | <Chip tone="border-merged/35 bg-merged/10 text-merged">By agents</Chip> |
| 360 | ) : ( |
| 361 | <Chip tone="border-warn/35 bg-warn/10 text-warn">Needed a person</Chip> |
| 362 | ) |
| 363 | } |
| 364 | at={row.at} |
| 365 | > |
| 366 | <div className="grid gap-4 rounded-xl border border-line bg-bg/50 p-4 md:grid-cols-2 md:gap-6"> |
| 367 | <div className="min-w-0"> |
| 368 | <Eyebrow>How it landed</Eyebrow> |
| 369 | <p className="mt-2 text-sm leading-6 text-fg-soft"> |
| 370 | {row.byAgents |
| 371 | ? `g1t merged it once everything the repository asks for was met, with no one pressing merge.` |
| 372 | : `${row.by?.name ?? "A person"} merged it.`} |
| 373 | {row.agent && isAgent(row.agent) && ` ${row.agent} made the change.`} |
| 374 | </p> |
| 375 | </div> |
| 376 | <div className="min-w-0"> |
| 377 | <Eyebrow>What changed</Eyebrow> |
| 378 | <div className="mt-2"> |
| 379 | <Facts facts={row.facts} /> |
| 380 | </div> |
| 381 | </div> |
| 382 | </div> |
| 383 | <div className="mt-3"> |
| 384 | <Link |
| 385 | to={row.to} |
| 386 | prefetch="intent" |
| 387 | className="inline-flex items-center gap-1.5 rounded-md border border-line-strong px-3 py-1.5 text-sm font-medium text-fg/90 hover:bg-raised hover:text-fg" |
| 388 | > |
| 389 | Open pull request <ArrowUpRight size={14} /> |
| 390 | </Link> |
| 391 | </div> |
| 392 | </Row> |
| 393 | ); |
| 394 | } |
| 395 | |
| 396 | function List({ children }: { children: ReactNode }) { |
| 397 | return <ul className="divide-y divide-line">{children}</ul>; |
| 398 | } |
| 399 | |
| 400 | function Empty({ children, action }: { children: ReactNode; action?: ReactNode }) { |
| 401 | return ( |
| 402 | <div className="px-5 py-10 text-center"> |
| 403 | <div className="mx-auto max-w-md text-sm leading-6 text-muted">{children}</div> |
| 404 | {action && <div className="mt-4 flex flex-wrap justify-center gap-2">{action}</div>} |
| 405 | </div> |
| 406 | ); |
| 407 | } |
| 408 | |
| 409 | // --- The stat strip ----------------------------------------------------------------- |
| 410 | |
| 411 | function Stat({ label, value, hint, dot, title }: { label: string; value: string; hint: ReactNode; dot?: string; title?: string }) { |
| 412 | return ( |
| 413 | <div className="min-w-0 bg-surface px-4 py-3.5 sm:px-5 sm:py-4" title={title}> |
| 414 | <p className="flex items-center gap-1.5 truncate text-xs text-muted"> |
| 415 | {dot && <span className={cn("size-1.5 shrink-0 rounded-full", dot)} />} |
| 416 | {label} |
| 417 | </p> |
| 418 | <p className="mt-1 font-display text-2xl font-semibold tracking-tight tabular-nums sm:text-[1.75rem]">{value}</p> |
| 419 | <p className="mt-0.5 truncate text-xs text-faint">{hint}</p> |
| 420 | </div> |
| 421 | ); |
| 422 | } |
| 423 | |
| 424 | // --- This week ---------------------------------------------------------------------- |
| 425 | |
| 426 | /** Seven days of landed changes, each split into what agents landed alone and what a person merged. */ |
| 427 | function WeekChart({ week }: { week: Week }) { |
| 428 | const max = Math.max(1, ...week.days.map((d) => d.agents + d.people)); |
| 429 | const height = 112; |
| 430 | const delta = change(week.total, week.previous); |
| 431 | return ( |
| 432 | <div> |
| 433 | <div className="flex items-end justify-between gap-3"> |
| 434 | <div> |
| 435 | <p className="font-display text-3xl font-semibold tracking-tight tabular-nums">{week.total.toLocaleString("en-US")}</p> |
| 436 | <p className="text-xs text-muted">changes landed in 7 days</p> |
| 437 | </div> |
| 438 | {delta != null ? ( |
| 439 | <span |
| 440 | className={cn( |
| 441 | "rounded-full px-2 py-0.5 text-xs font-medium tabular-nums ring-1", |
| 442 | delta >= 0 ? "text-accent ring-accent/30" : "text-warn ring-warn/30", |
| 443 | )} |
| 444 | > |
| 445 | {signedPercent(delta)} vs last week |
| 446 | </span> |
| 447 | ) : week.previous === 0 && week.total > 0 ? ( |
| 448 | <span className="text-xs text-faint">none the week before</span> |
| 449 | ) : null} |
| 450 | </div> |
| 451 | {week.total === 0 ? ( |
| 452 | <p className="mt-4 rounded-lg border border-dashed border-line px-4 py-6 text-center text-sm leading-6 text-muted"> |
| 453 | Nothing landed in the last 7 days. Each change that does shows here, by day, split by whether a person had to merge it. |
| 454 | </p> |
| 455 | ) : ( |
| 456 | <div className="relative mt-5" style={{ height: height + 20 }}> |
| 457 | <div className="absolute inset-x-0 border-t border-line" style={{ top: height }} /> |
| 458 | <div className="absolute inset-x-0 top-0 flex items-end justify-between gap-1" style={{ height }}> |
| 459 | {week.days.map((day, index) => { |
| 460 | const total = day.agents + day.people; |
| 461 | const agentsH = Math.round((day.agents / max) * (height - 4)); |
| 462 | const peopleH = Math.round((day.people / max) * (height - 4)); |
| 463 | const today = index === week.days.length - 1; |
| 464 | return ( |
| 465 | <div key={day.key} className="group relative flex h-full flex-1 flex-col items-center justify-end"> |
| 466 | {total > 0 && ( |
| 467 | <span |
| 468 | className={cn( |
| 469 | "mb-1 text-[0.625rem] tabular-nums", |
| 470 | today ? "text-fg-soft" : "text-faint opacity-0 group-hover:opacity-100", |
| 471 | )} |
| 472 | > |
| 473 | {total} |
| 474 | </span> |
| 475 | )} |
| 476 | <div className="flex w-full max-w-6 flex-col items-stretch gap-[2px]"> |
| 477 | {day.people > 0 && <span className="block rounded-t bg-warn" style={{ height: Math.max(3, peopleH) }} />} |
| 478 | {day.agents > 0 && ( |
| 479 | <span className={cn("block bg-merged", day.people > 0 ? "" : "rounded-t")} style={{ height: Math.max(3, agentsH) }} /> |
| 480 | )} |
| 481 | {total === 0 && <span className="block h-[2px] rounded-full bg-line-strong" />} |
| 482 | </div> |
| 483 | <div className="pointer-events-none absolute bottom-full left-1/2 z-10 mb-1 hidden -translate-x-1/2 rounded-md border border-line-strong bg-raised px-2.5 py-1.5 text-xs whitespace-nowrap shadow-lg shadow-black/40 group-hover:block"> |
| 484 | <p className="font-medium text-fg">{day.label}</p> |
| 485 | <p className="mt-0.5 flex items-center gap-1.5 text-muted"> |
| 486 | <span className="size-1.5 rounded-full bg-merged" /> {day.agents} by agents |
| 487 | </p> |
| 488 | <p className="flex items-center gap-1.5 text-muted"> |
| 489 | <span className="size-1.5 rounded-full bg-warn" /> {day.people} needed a person |
| 490 | </p> |
| 491 | </div> |
| 492 | </div> |
| 493 | ); |
| 494 | })} |
| 495 | </div> |
| 496 | <div className="absolute inset-x-0 bottom-0 flex justify-between gap-1"> |
| 497 | {week.days.map((day, index) => ( |
| 498 | <span |
| 499 | key={day.key} |
| 500 | className={cn( |
| 501 | "flex-1 text-center text-[0.6875rem]", |
| 502 | index === week.days.length - 1 ? "font-medium text-fg-soft" : "text-faint", |
| 503 | )} |
| 504 | > |
| 505 | {day.label} |
| 506 | </span> |
| 507 | ))} |
| 508 | </div> |
| 509 | </div> |
| 510 | )} |
| 511 | <div className={cn("mt-3 flex-wrap gap-x-4 gap-y-1 text-xs text-muted", week.total === 0 ? "hidden" : "flex")}> |
| 512 | <span className="inline-flex items-center gap-1.5"> |
| 513 | <span className="size-2 rounded-sm bg-merged" /> Landed by agents |
| 514 | </span> |
| 515 | <span className="inline-flex items-center gap-1.5"> |
| 516 | <span className="size-2 rounded-sm bg-warn" /> Needed a person |
| 517 | </span> |
| 518 | </div> |
| 519 | <table className="sr-only"> |
| 520 | <caption>Changes landed each day</caption> |
| 521 | <thead> |
| 522 | <tr> |
| 523 | <th>Day</th> |
| 524 | <th>Landed by agents</th> |
| 525 | <th>Needed a person</th> |
| 526 | </tr> |
| 527 | </thead> |
| 528 | <tbody> |
| 529 | {week.days.map((day) => ( |
| 530 | <tr key={day.key}> |
| 531 | <td>{day.key}</td> |
| 532 | <td>{day.agents}</td> |
| 533 | <td>{day.people}</td> |
| 534 | </tr> |
| 535 | ))} |
| 536 | </tbody> |
| 537 | </table> |
| 538 | </div> |
| 539 | ); |
| 540 | } |
| 541 | |
| 542 | // --- Activity ----------------------------------------------------------------------- |
| 543 | |
| 544 | const VERB: Record<Verb, string> = { |
| 545 | landed: "landed", |
| 546 | opened_issue: "opened", |
| 547 | closed_issue: "closed", |
| 548 | started: "started on", |
| 549 | ready: "marked ready", |
| 550 | checks_passed: "checks passed on", |
| 551 | checks_failed: "checks failed on", |
| 552 | approved: "approved", |
| 553 | changes_requested: "asked for changes on", |
| 554 | commented: "commented on", |
| 555 | asked: "was asked about", |
| 556 | deployed: "deployed production", |
| 557 | deploy_failed: "production build failed", |
| 558 | learned: "learned", |
| 559 | }; |
| 560 | |
| 561 | /** One line of the feed: who, what, and the one thing it was about, by name. */ |
| 562 | function FeedLine({ group, titles }: { group: ActivityGroup; titles: Record<string, string> }) { |
| 563 | const part = group.parts[0]; |
| 564 | const base = `/${group.repo.namespace}/${group.repo.name}`; |
| 565 | const actor = group.actor ?? "g1t"; |
| 566 | const agent = group.actor == null || isAgent(group.actor); |
| 567 | const number = part.numbers[0]; |
| 568 | const title = number != null ? titles[`${group.repo.namespace}/${group.repo.name}#${number}`.toLowerCase()] : undefined; |
| 569 | const more = group.parts.length - 1 + Math.max(0, part.numbers.length - 1); |
| 570 | return ( |
| 571 | <li className="flex gap-2.5 py-2"> |
| 572 | <span className="mt-px"> |
| 573 | <Avatar name={actor} size={22} /> |
| 574 | </span> |
| 575 | <span className="min-w-0 grow text-[0.8125rem] leading-5 text-muted"> |
| 576 | <span className={cn("font-medium", agent ? "text-merged" : "text-fg")}>{actor}</span> {VERB[part.verb]}{" "} |
| 577 | {part.verb === "learned" ? ( |
| 578 | <Link to={part.to ?? `${base}/memory`} className="text-fg-soft hover:text-fg"> |
| 579 | “{part.texts[0]}” |
| 580 | </Link> |
| 581 | ) : number != null ? ( |
| 582 | <Link to={`${base}/issues/${number}`} prefetch="intent" className="text-fg-soft hover:text-fg"> |
| 583 | <span className="font-mono text-xs">#{number}</span> |
| 584 | {title && <> {title}</>} |
| 585 | </Link> |
| 586 | ) : part.to ? ( |
| 587 | <Link to={part.to} className="text-fg-soft hover:text-fg"> |
| 588 | {group.repo.name} |
| 589 | </Link> |
| 590 | ) : null} |
| 591 | {more > 0 && <span className="text-faint"> and {more} more</span>} |
| 592 | <span className="block text-xs text-faint"> |
| 593 | <span className="font-mono">{group.repo.name}</span> · <TimeAgo at={group.at} /> |
| 594 | </span> |
| 595 | </span> |
| 596 | </li> |
| 597 | ); |
| 598 | } |
| 599 | |
| 600 | // --- Get started -------------------------------------------------------------------- |
| 601 | |
| 602 | type Step = { done: boolean; title: string; about: string; to: string | null; action: string }; |
| 603 | |
| 604 | /** The first things to do, ticked off as they are done, until work has been handed to agents. */ |
| 605 | function GetStarted({ steps }: { steps: Step[] }) { |
| 606 | const left = steps.filter((step) => !step.done).length; |
| 607 | return ( |
| 608 | <section className="rounded-xl border border-line bg-surface p-5"> |
| 609 | <div className="flex items-baseline justify-between gap-3"> |
| 610 | <h2 className="text-base font-semibold tracking-tight">Get started</h2> |
| 611 | <span className="text-xs text-muted"> |
| 612 | {steps.length - left} of {steps.length} done |
| 613 | </span> |
| 614 | </div> |
| 615 | <ol className="mt-4 space-y-2"> |
| 616 | {steps.map((step, index) => ( |
| 617 | <li |
| 618 | key={step.title} |
| 619 | className={cn("flex items-start gap-3 rounded-lg px-3 py-2.5", step.done ? "" : "bg-bg/50 ring-1 ring-line")} |
| 620 | > |
| 621 | <span |
| 622 | className={cn( |
| 623 | "mt-0.5 flex size-5 shrink-0 items-center justify-center rounded-full text-[0.6875rem] font-medium", |
| 624 | step.done ? "bg-accent text-bg" : "text-muted ring-1 ring-line-strong", |
| 625 | )} |
| 626 | > |
| 627 | {step.done ? <Check size={12} /> : index + 1} |
| 628 | </span> |
| 629 | <span className="min-w-0 grow"> |
| 630 | <span className={cn("block text-sm font-medium", step.done && "text-muted line-through decoration-faint")}>{step.title}</span> |
| 631 | {!step.done && <span className="mt-0.5 block text-xs leading-5 text-muted">{step.about}</span>} |
| 632 | </span> |
| 633 | {!step.done && step.to && ( |
| 634 | <Link |
| 635 | to={step.to} |
| 636 | className="shrink-0 rounded-md bg-fg px-2.5 py-1 text-xs font-medium text-bg transition-colors hover:bg-white" |
| 637 | > |
| 638 | {step.action} |
| 639 | </Link> |
| 640 | )} |
| 641 | </li> |
| 642 | ))} |
| 643 | </ol> |
| 644 | </section> |
| 645 | ); |
| 646 | } |
| 647 | |
| 648 | // --- The page ----------------------------------------------------------------------- |
| 649 | |
| 650 | const TAB_LABEL: Record<Tab, string> = { needs: "Needs you", waiting: "Waiting on agents", landed: "Landed today" }; |
| 651 | const TAB_SHORT: Record<Tab, string> = { needs: "Needs you", waiting: "Waiting", landed: "Today" }; |
| 652 | const SORT_LABEL: Record<Sort, string> = { impact: "By impact", newest: "Newest" }; |
| 653 | |
| 654 | export default function MissionControl({ loaderData, delegated = null }: { loaderData: Loaded; delegated?: ComposerResult }) { |
| 655 | const shell = useRouteLoaderData("root")?.shell as ShellData | null | undefined; |
| 656 | const loaded: Loaded = loaderData; |
| 657 | const [params] = useSearchParams(); |
| 658 | // Agents are at work, so the page changes without anyone touching it. |
| 659 | useLiveRefresh(loaded.changing); |
| 660 | const [greeting, setGreeting] = useState(loaded.greeting); |
| 661 | const [date, setDate] = useState(loaded.date); |
| 662 | useEffect(() => { |
| 663 | // The greeting and date follow the viewer's own clock, and the server |
| 664 | // learns their zone for next time. |
| 665 | setGreeting(greetingFor(new Date().getHours())); |
| 666 | try { |
| 667 | const zone = Intl.DateTimeFormat().resolvedOptions().timeZone; |
| 668 | setDate(dateLine(Date.now(), zone ?? null)); |
| 669 | if (zone) document.cookie = `${TZ_COOKIE}=${encodeURIComponent(zone)}; Path=/; Max-Age=31536000; SameSite=Lax`; |
| 670 | } catch { |
| 671 | // Nothing to remember. |
| 672 | } |
| 673 | }, []); |
| 674 | |
| 675 | const { viewer, repos, waiting, landed, liveTotal, week, groups, titles, stats, canRunAgents, trial } = loaded; |
| 676 | const workspace = shell?.workspace?.slug ?? loaded.workspace ?? viewer.workspaces?.[0]?.slug ?? null; |
| 677 | |
| 678 | // The usage limit, as the sidebar knows it, heads the list when it bites. |
| 679 | const limit = shell?.limit && !shell.limit.comped && shell.limit.state !== "ok" && workspace ? shell.limit : null; |
| 680 | const limitRow: NeedRow[] = limit |
| 681 | ? [ |
| 682 | (() => { |
| 683 | const detail = |
| 684 | limit.state === "stopped" |
| 685 | ? "No new agent starts until the limit is raised or a card is added." |
| 686 | : `${dollars(limit.exposureMicros)} of ${dollars(limit.ceilingMicros ?? 0)} used. Add a card so work keeps going.`; |
| 687 | return { |
| 688 | key: "limit", |
| 689 | reason: "blocking" as const, |
| 690 | repo: null, |
| 691 | ref: null, |
| 692 | title: limit.state === "stopped" ? "Agents are stopped: the usage limit was reached" : "Usage is nearing its limit", |
| 693 | ask: detail, |
| 694 | by: null, |
| 695 | for: null, |
| 696 | at: Date.now(), |
| 697 | to: `/${workspace}/-/billing`, |
| 698 | open: `/${workspace}/-/billing`, |
| 699 | facts: [ |
| 700 | { label: "Used", value: `${dollars(limit.exposureMicros)} of ${dollars(limit.ceilingMicros ?? 0)}`, tone: "warn" as const }, |
| 701 | ], |
| 702 | why: whyFor("blocking", { kind: "limit", detail }), |
| 703 | quick: null, |
| 704 | link: null, |
| 705 | }; |
| 706 | })(), |
| 707 | ] |
| 708 | : []; |
| 709 | const needs = [...limitRow, ...loaded.needs]; |
| 710 | const blocking = needs.filter((row) => BLOCKING.has(row.reason)).length; |
| 711 | |
| 712 | const counts: Record<Tab, number> = { needs: needs.length, waiting: waiting.length, landed: landed.length }; |
| 713 | const tab = parseTab(params.get("tab")) ?? "needs"; |
| 714 | const sort = parseSort(params.get("sort")); |
| 715 | const all = params.get("all") === "1"; |
| 716 | const everyActivity = params.get("activity") === "all"; |
| 717 | const link = (changes: Record<string, string | null>) => { |
| 718 | const next = new URLSearchParams(params); |
| 719 | for (const [key, value] of Object.entries(changes)) { |
| 720 | if (value == null) next.delete(key); |
| 721 | else next.set(key, value); |
| 722 | } |
| 723 | const text = next.toString(); |
| 724 | return text ? `?${text}` : "/"; |
| 725 | }; |
| 726 | |
| 727 | const steps: Step[] = [ |
| 728 | { |
| 729 | done: Boolean(workspace), |
| 730 | title: "Create a workspace", |
| 731 | about: "Projects, people and agent credit live in one.", |
| 732 | to: "/workspaces/new", |
| 733 | action: "Create", |
| 734 | }, |
| 735 | { |
| 736 | done: repos.length > 0, |
| 737 | title: "Add a project", |
| 738 | about: "Create a repository, or import one by its address. Push to it with git as usual.", |
| 739 | to: workspace ? `/new?workspace=${workspace}` : "/new", |
| 740 | action: "Add", |
| 741 | }, |
| 742 | trial?.open |
| 743 | ? { |
| 744 | done: true, |
| 745 | title: "Try g1t free", |
| 746 | about: trial.granted |
| 747 | ? `This workspace has ${dollars(trial.limitMicros - trial.usedMicros)} of its ${dollars(trial.limitMicros)} trial credit left, for g1t's models and sandboxes.` |
| 748 | : `This workspace gets ${dollars(trial.limitMicros)} of trial credit, for g1t's models and sandboxes, the first time g1t works here.`, |
| 749 | to: workspace ? `/${workspace}/-/integrations` : null, |
| 750 | action: "Connect", |
| 751 | } |
| 752 | : canRunAgents |
| 753 | ? { |
| 754 | done: Boolean(shell?.free) || shell?.limit == null || shell.limit.comped || shell.limit.state === "ok", |
| 755 | title: "Keep work running", |
| 756 | about: |
| 757 | "Usage is charged after it runs. Add a card under Billing, so g1t charges it as you near your limit instead of stopping work.", |
| 758 | to: workspace ? `/${workspace}/-/billing` : null, |
| 759 | action: "Billing", |
| 760 | } |
| 761 | : { |
| 762 | done: false, |
| 763 | title: "Connect a model", |
| 764 | about: `${ |
| 765 | trialClosed(trial, workspace ?? "This workspace") ? `${trialClosed(trial, workspace ?? "This workspace")} ` : "" |
| 766 | }Agents need a model to think with. Connect your Anthropic or OpenAI key, or any compatible endpoint.`, |
| 767 | to: workspace ? `/${workspace}/-/integrations` : null, |
| 768 | action: "Connect", |
| 769 | }, |
| 770 | { |
| 771 | done: loaded.handedOff, |
| 772 | title: "Hand off an outcome", |
| 773 | about: |
| 774 | "Open an issue and assign it to g1t, or write an outcome on a project's Plans page and let a planner split it into issues.", |
| 775 | to: repos[0] ? `/${repos[0].namespace}/${repos[0].name}/plans` : null, |
| 776 | action: "Write one", |
| 777 | }, |
| 778 | ]; |
| 779 | const starting = steps.some((step) => !step.done); |
| 780 | const noProjects = repos.length === 0; |
| 781 | |
| 782 | const rows = tab === "needs" ? sortRows(needs, sort) : tab === "waiting" ? sortRows(waiting, sort) : sortRows(landed, sort); |
| 783 | const shown = all ? rows : rows.slice(0, ROWS); |
| 784 | const share = week.total > 0 ? week.byAgents / week.total : null; |
| 785 | const delta = change(week.total, week.previous); |
| 786 | const feed = everyActivity ? groups : groups.slice(0, 8); |
| 787 | |
| 788 | // "Put an agent on it" first, with "New issue" beside it as before: one |
| 789 | // split control, the agent the main way in. |
| 790 | const newIssue = |
| 791 | repos.length > 0 ? ( |
| 792 | <div className="flex items-stretch"> |
| 793 | <AgentComposer |
| 794 | repos={repos} |
| 795 | open={params.get("agent") === "new" || delegated != null} |
| 796 | result={delegated} |
| 797 | note={ |
| 798 | canRunAgents ? null : ( |
| 799 | <> |
| 800 | Agents need a model first.{" "} |
| 801 | {workspace && ( |
| 802 | <Link to={`/${workspace}/-/integrations`} className="font-medium text-fg hover:underline"> |
| 803 | Connect one |
| 804 | </Link> |
| 805 | )} |
| 806 | . The issue still opens. |
| 807 | </> |
| 808 | ) |
| 809 | } |
| 810 | > |
| 811 | <span className="inline-flex cursor-pointer items-center gap-1.5 rounded-l-md border border-line-strong bg-raised px-3 py-2 text-sm font-medium text-fg transition-colors hover:bg-line/60 group-open/composer:bg-line/60"> |
| 812 | <Sparkles size={14} className="text-merged" /> Put an agent on it |
| 813 | </span> |
| 814 | </AgentComposer> |
| 815 | <DropdownMenu> |
| 816 | <DropdownMenuTrigger className="-ml-px inline-flex items-center gap-1.5 rounded-r-md border border-line-strong px-3 py-2 text-sm font-medium text-fg/90 transition-colors hover:bg-raised hover:text-fg"> |
| 817 | <Plus size={14} /> New issue |
| 818 | </DropdownMenuTrigger> |
| 819 | <DropdownMenuContent align="end" className="max-h-80 overflow-y-auto"> |
| 820 | <DropdownMenuLabel>In which project?</DropdownMenuLabel> |
| 821 | {repos.map((repo) => ( |
| 822 | <DropdownMenuItem key={repo.name} asChild> |
| 823 | <Link to={`/${repo.namespace}/${repo.name}/issues/new`}> |
| 824 | <Avatar name={repo.name} size={18} square /> |
| 825 | {repo.name} |
| 826 | </Link> |
| 827 | </DropdownMenuItem> |
| 828 | ))} |
| 829 | </DropdownMenuContent> |
| 830 | </DropdownMenu> |
| 831 | </div> |
| 832 | ) : ( |
| 833 | <Link |
| 834 | to={workspace ? `/new?workspace=${workspace}` : "/new"} |
| 835 | className="inline-flex items-center gap-1.5 rounded-md border border-line-strong px-3 py-2 text-sm font-medium text-fg/90 hover:bg-raised hover:text-fg" |
| 836 | > |
| 837 | <Plus size={14} /> New project |
| 838 | </Link> |
| 839 | ); |
| 840 | |
| 841 | return ( |
| 842 | <main className="mx-auto max-w-7xl space-y-6 px-4 py-8 sm:px-6 sm:py-10"> |
| 843 | <header className="flex flex-wrap items-end justify-between gap-x-6 gap-y-4"> |
| 844 | <div className="min-w-0"> |
| 845 | <h1 className="text-[1.75rem] leading-tight font-semibold tracking-tight sm:text-[2rem]" suppressHydrationWarning> |
| 846 | {greeting}, {loaded.name} |
| 847 | </h1> |
| 848 | <p className="mt-1.5 text-sm text-muted" suppressHydrationWarning> |
| 849 | <span className="text-fg-soft">{date}</span> · {loaded.summary} |
| 850 | </p> |
| 851 | </div> |
| 852 | <div className="flex flex-wrap items-center gap-2"> |
| 853 | {newIssue} |
| 854 | {needs.length > 0 && ( |
| 855 | <Link |
| 856 | to={`${link({ tab: "needs", all: null })}#work`} |
| 857 | preventScrollReset |
| 858 | className="inline-flex items-center gap-1.5 rounded-md bg-merged px-3.5 py-2 text-sm font-semibold text-bg transition-colors hover:bg-[#c9bfff]" |
| 859 | > |
| 860 | Review {needs.length} that need{needs.length === 1 ? "s" : ""} you <ArrowRight size={14} /> |
| 861 | </Link> |
| 862 | )} |
| 863 | </div> |
| 864 | </header> |
| 865 | |
| 866 | {starting && <GetStarted steps={steps} />} |
| 867 | |
| 868 | <section |
| 869 | aria-label="At a glance" |
| 870 | className="grid grid-cols-2 gap-px overflow-hidden rounded-xl border border-line bg-line lg:grid-cols-5" |
| 871 | > |
| 872 | <Stat |
| 873 | label="Projects" |
| 874 | value={stats.projects == null ? "—" : String(stats.projects)} |
| 875 | hint={ |
| 876 | stats.projectsThisMonth == null |
| 877 | ? "in this workspace" |
| 878 | : stats.projectsThisMonth > 0 |
| 879 | ? `+${stats.projectsThisMonth} this month` |
| 880 | : "none new this month" |
| 881 | } |
| 882 | /> |
| 883 | <Stat |
| 884 | label="Agents" |
| 885 | value={loaded.runsLoaded || !workspace ? String(liveTotal) : "—"} |
| 886 | dot={liveTotal > 0 ? "bg-accent animate-pulse" : undefined} |
| 887 | hint={ |
| 888 | liveTotal > 0 |
| 889 | ? `live now · ${stats.agentHours < 10 ? stats.agentHours.toFixed(1) : Math.round(stats.agentHours)}h this week` |
| 890 | : stats.agentHours > 0 |
| 891 | ? `none live · ${stats.agentHours < 10 ? stats.agentHours.toFixed(1) : Math.round(stats.agentHours)}h this week` |
| 892 | : "none live now" |
| 893 | } |
| 894 | /> |
| 895 | <Stat |
| 896 | label="Changes this week" |
| 897 | value={loaded.perRepoLoaded ? String(week.total) : "—"} |
| 898 | hint={ |
| 899 | delta != null ? `${signedPercent(delta)} vs last week` : week.previous === 0 ? "none the week before" : "merged pull requests" |
| 900 | } |
| 901 | /> |
| 902 | <Stat |
| 903 | label="Landed without you" |
| 904 | dot="bg-merged" |
| 905 | value={share == null ? "—" : `${Math.round(share * 100)}%`} |
| 906 | hint={share == null ? "nothing landed yet" : `${week.byAgents} of ${week.total}`} |
| 907 | title="Merged by g1t, by auto-merge or the merge queue, with no person pressing merge." |
| 908 | /> |
| 909 | <div className="col-span-2 lg:col-span-1"> |
| 910 | <Stat |
| 911 | label="Need you" |
| 912 | dot="bg-warn" |
| 913 | value={String(needs.length)} |
| 914 | hint={blocking > 0 ? `${blocking} blocking` : needs.length > 0 ? "nothing blocking" : "all clear"} |
| 915 | /> |
| 916 | </div> |
| 917 | </section> |
| 918 | |
| 919 | <div className="grid gap-6 lg:grid-cols-[minmax(0,1fr)_21rem] xl:grid-cols-[minmax(0,1fr)_23rem]"> |
| 920 | <section id="work" className="min-w-0 scroll-mt-20 self-start overflow-hidden rounded-xl border border-line bg-surface"> |
| 921 | <div className="flex items-center gap-2 border-b border-line px-2 sm:px-3"> |
| 922 | <nav className="-mb-px flex min-w-0 grow gap-1 overflow-x-auto [scrollbar-width:none]" aria-label="Mission control"> |
| 923 | {(["needs", "waiting", "landed"] as const).map((value) => ( |
| 924 | <Link |
| 925 | key={value} |
| 926 | to={link({ tab: value, all: null })} |
| 927 | preventScrollReset |
| 928 | aria-current={tab === value ? "page" : undefined} |
| 929 | className={cn( |
| 930 | "flex shrink-0 items-center gap-1.5 border-b-2 px-2 py-3 text-sm whitespace-nowrap transition-colors sm:px-2.5", |
| 931 | tab === value ? "border-merged font-medium text-fg" : "border-transparent text-muted hover:text-fg", |
| 932 | )} |
| 933 | > |
| 934 | <span className="sm:hidden">{TAB_SHORT[value]}</span> |
| 935 | <span className="hidden sm:inline">{TAB_LABEL[value]}</span> |
| 936 | <span |
| 937 | className={cn( |
| 938 | "rounded-full px-1.5 text-[0.6875rem] tabular-nums", |
| 939 | tab === value && value === "needs" && counts.needs > 0 ? "bg-warn/15 text-warn" : "bg-line text-muted", |
| 940 | )} |
| 941 | > |
| 942 | {counts[value]} |
| 943 | </span> |
| 944 | </Link> |
| 945 | ))} |
| 946 | </nav> |
| 947 | <DropdownMenu> |
| 948 | <DropdownMenuTrigger |
| 949 | className="inline-flex shrink-0 items-center gap-1.5 rounded-md px-2 py-1.5 text-xs text-muted hover:bg-raised hover:text-fg" |
| 950 | aria-label="Sort" |
| 951 | > |
| 952 | <ArrowDownWideNarrow size={14} /> |
| 953 | <span className="hidden sm:inline">{SORT_LABEL[sort]}</span> |
| 954 | </DropdownMenuTrigger> |
| 955 | <DropdownMenuContent align="end"> |
| 956 | {(["impact", "newest"] as const).map((value) => ( |
| 957 | <DropdownMenuItem key={value} asChild> |
| 958 | <Link to={link({ sort: value === "impact" ? null : value })} preventScrollReset> |
| 959 | {sort === value ? <Check /> : <span className="size-4" />} |
| 960 | {SORT_LABEL[value]} |
| 961 | </Link> |
| 962 | </DropdownMenuItem> |
| 963 | ))} |
| 964 | </DropdownMenuContent> |
| 965 | </DropdownMenu> |
| 966 | </div> |
| 967 | |
| 968 | {!loaded.perRepoLoaded && tab !== "waiting" ? ( |
| 969 | <div className="p-4"> |
| 970 | <Unavailable what={tab === "needs" ? "Some of what needs you" : "What landed"} /> |
| 971 | </div> |
| 972 | ) : null} |
| 973 | |
| 974 | {tab === "needs" && |
| 975 | (needs.length === 0 ? ( |
| 976 | noProjects ? ( |
| 977 | <Empty |
| 978 | action={ |
| 979 | <Link |
| 980 | to={workspace ? `/new?workspace=${workspace}` : "/new"} |
| 981 | className="rounded-md bg-fg px-3 py-1.5 text-sm font-medium text-bg hover:bg-white" |
| 982 | > |
| 983 | Create or import a project |
| 984 | </Link> |
| 985 | } |
| 986 | > |
| 987 | <p className="font-medium text-fg">No projects yet</p> |
| 988 | <p className="mt-1"> |
| 989 | Create a repository or import one. Assign its issues to g1t, and what needs you shows up here. |
| 990 | </p> |
| 991 | </Empty> |
| 992 | ) : ( |
| 993 | <> |
| 994 | <Empty> |
| 995 | <p className="font-medium text-fg">Nothing needs you</p> |
| 996 | <p className="mt-1"> |
| 997 | Agents are handling everything.{" "} |
| 998 | {landed.length > 0 |
| 999 | ? "Here's what they landed today." |
| 1000 | : "Reviews, stopped work and failed deploys show up here first."} |
| 1001 | </p> |
| 1002 | </Empty> |
| 1003 | {landed.length > 0 && ( |
| 1004 | <div className="border-t border-line"> |
| 1005 | <List> |
| 1006 | {landed.slice(0, ROWS).map((row) => ( |
| 1007 | <LandedCard key={row.key} row={row} first={false} /> |
| 1008 | ))} |
| 1009 | </List> |
| 1010 | </div> |
| 1011 | )} |
| 1012 | </> |
| 1013 | ) |
| 1014 | ) : ( |
| 1015 | <List> |
| 1016 | {(shown as NeedRow[]).map((row, index) => ( |
| 1017 | <NeedCard key={row.key} row={row} first={index === 0} /> |
| 1018 | ))} |
| 1019 | </List> |
| 1020 | ))} |
| 1021 | |
| 1022 | {tab === "waiting" && |
| 1023 | (!loaded.runsLoaded && workspace ? ( |
| 1024 | <div className="p-4"> |
| 1025 | <Unavailable what="Agent runs" /> |
| 1026 | </div> |
| 1027 | ) : waiting.length === 0 ? ( |
| 1028 | <Empty> |
| 1029 | <p className="font-medium text-fg">No agent is at work right now</p> |
| 1030 | <p className="mt-1">Assign an issue to g1t and one starts on it in seconds. Its run shows here while it works.</p> |
| 1031 | </Empty> |
| 1032 | ) : ( |
| 1033 | <List> |
| 1034 | {(shown as WaitingRow[]).map((row, index) => ( |
| 1035 | <WaitingCard key={row.key} row={row} first={index === 0} /> |
| 1036 | ))} |
| 1037 | </List> |
| 1038 | ))} |
| 1039 | |
| 1040 | {tab === "landed" && |
| 1041 | loaded.perRepoLoaded && |
| 1042 | (landed.length === 0 ? ( |
| 1043 | <Empty> |
| 1044 | <p className="font-medium text-fg">Nothing has landed today yet</p> |
| 1045 | <p className="mt-1"> |
| 1046 | {week.total > 0 |
| 1047 | ? `${plural(week.total, "change")} landed in the last 7 days.` |
| 1048 | : "Merged pull requests show up here the moment they land."} |
| 1049 | </p> |
| 1050 | </Empty> |
| 1051 | ) : ( |
| 1052 | <List> |
| 1053 | {(shown as LandedRow[]).map((row, index) => ( |
| 1054 | <LandedCard key={row.key} row={row} first={index === 0} /> |
| 1055 | ))} |
| 1056 | </List> |
| 1057 | ))} |
| 1058 | |
| 1059 | {rows.length > ROWS && ( |
| 1060 | <div className="flex items-center justify-between border-t border-line px-4 py-2.5 text-xs text-muted sm:px-5"> |
| 1061 | <span> |
| 1062 | Showing {shown.length} of {rows.length} |
| 1063 | </span> |
| 1064 | <Link |
| 1065 | to={link({ all: all ? null : "1" })} |
| 1066 | preventScrollReset |
| 1067 | className="inline-flex items-center gap-1 font-medium text-fg-soft hover:text-fg" |
| 1068 | > |
| 1069 | {all ? "Show fewer" : "See all"} <ChevronRight size={12} /> |
| 1070 | </Link> |
| 1071 | </div> |
| 1072 | )} |
| 1073 | </section> |
| 1074 | |
| 1075 | <aside className="min-w-0 space-y-6"> |
| 1076 | <section className="rounded-xl border border-line bg-surface p-5"> |
| 1077 | <div className="flex items-center justify-between"> |
| 1078 | <h2 className="text-base font-semibold tracking-tight">This week</h2> |
| 1079 | {workspace && ( |
| 1080 | <Link to={`/${workspace}/-/agents`} className="text-xs text-muted hover:text-fg"> |
| 1081 | Fleet |
| 1082 | </Link> |
| 1083 | )} |
| 1084 | </div> |
| 1085 | <div className="mt-4">{loaded.perRepoLoaded ? <WeekChart week={week} /> : <Unavailable what="The week" />}</div> |
| 1086 | {workspace && stats.weekCost > 0 && ( |
| 1087 | <Link |
| 1088 | to={`/${workspace}/-/usage`} |
| 1089 | className="mt-4 flex items-center justify-between border-t border-line pt-3 text-xs text-muted hover:text-fg" |
| 1090 | > |
| 1091 | <span>Agents and sandboxes cost {usd(stats.weekCost)} this week</span> |
| 1092 | <ChevronRight size={12} /> |
| 1093 | </Link> |
| 1094 | )} |
| 1095 | </section> |
| 1096 | |
| 1097 | {workspace && ( |
| 1098 | <TokenUsagePanel |
| 1099 | workspace={loaderData.tokens.workspace} |
| 1100 | mine={loaderData.tokens.mine} |
| 1101 | usageHref={`/${workspace}/-/usage`} |
| 1102 | /> |
| 1103 | )} |
| 1104 | |
| 1105 | <section id="activity" className="scroll-mt-20 rounded-xl border border-line bg-surface p-5"> |
| 1106 | <div className="flex items-center justify-between"> |
| 1107 | <h2 className="text-base font-semibold tracking-tight">Activity</h2> |
| 1108 | {groups.length > 8 && ( |
| 1109 | <Link |
| 1110 | to={`${link({ activity: everyActivity ? null : "all" })}#activity`} |
| 1111 | preventScrollReset |
| 1112 | className="inline-flex items-center gap-0.5 text-xs text-muted hover:text-fg" |
| 1113 | > |
| 1114 | {everyActivity ? "Less" : "All activity"} <ChevronRight size={12} /> |
| 1115 | </Link> |
| 1116 | )} |
| 1117 | </div> |
| 1118 | <p className="mt-1 flex items-center gap-3 text-[0.6875rem] text-faint"> |
| 1119 | <span className="inline-flex items-center gap-1.5"> |
| 1120 | <Avatar name="g1t" size={12} /> agents |
| 1121 | </span> |
| 1122 | <span className="inline-flex items-center gap-1.5"> |
| 1123 | <Avatar name={viewer.username} size={12} /> people |
| 1124 | </span> |
| 1125 | </p> |
| 1126 | {!loaded.perRepoLoaded ? ( |
| 1127 | <div className="mt-3"> |
| 1128 | <Unavailable what="Activity" /> |
| 1129 | </div> |
| 1130 | ) : feed.length === 0 ? ( |
| 1131 | <p className="mt-3 text-sm leading-6 text-muted"> |
| 1132 | Nothing has moved yet. Merges, deploys, checks, reviews and what agents learn show up here. |
| 1133 | </p> |
| 1134 | ) : ( |
| 1135 | <ol className="mt-2 divide-y divide-line/70"> |
| 1136 | {feed.map((group) => ( |
| 1137 | <FeedLine key={group.id} group={group} titles={titles} /> |
| 1138 | ))} |
| 1139 | </ol> |
| 1140 | )} |
| 1141 | </section> |
| 1142 | |
| 1143 | <section className="rounded-xl border border-line bg-surface p-5"> |
| 1144 | <h2 className="text-sm font-semibold">Connect your own agent</h2> |
| 1145 | <p className="mt-1.5 text-xs leading-5 text-muted"> |
| 1146 | Add g1t to your coding agent. It signs in through your browser; there is no token to copy. |
| 1147 | </p> |
| 1148 | <AgentSetup className="mt-3" /> |
| 1149 | <Link |
| 1150 | to="https://docs.g1t.sh/guides/bring-your-own-agent/" |
| 1151 | className="mt-3 inline-flex items-center gap-1 text-xs text-muted hover:text-fg" |
| 1152 | > |
| 1153 | How it works <ArrowRight size={12} /> |
| 1154 | </Link> |
| 1155 | </section> |
| 1156 | </aside> |
| 1157 | </div> |
| 1158 | </main> |
| 1159 | ); |
| 1160 | } |