g1t/apps/web/app/routes/home.tsx
| 1 | import { ArrowRight, Hand, Plus, Settings, Users } from "lucide-react"; |
| 2 | import { env } from "cloudflare:workers"; |
| 3 | import { type ReactNode, useEffect } from "react"; |
| 4 | import { Link, data, useRevalidator, useRouteLoaderData } from "react-router"; |
| 5 | |
| 6 | import type { Lifecycle, Pull, Repo } from "@g1t/contracts"; |
| 7 | |
| 8 | import type { Route } from "./+types/home"; |
| 9 | import { Landing } from "../components/landing"; |
| 10 | import type { ShellData } from "../components/shell"; |
| 11 | import { STAGE_LABEL, StageDots } from "../components/lifecycle"; |
| 12 | import { RepoList } from "../components/repo-list"; |
| 13 | import { |
| 14 | Avatar, |
| 15 | ButtonLink, |
| 16 | CopyLine, |
| 17 | EmptyState, |
| 18 | TimeAgo, |
| 19 | } from "../components/ui"; |
| 20 | import { Assignee, IssueIcon, PullIcon } from "../components/work"; |
| 21 | import { repos as reposApi, work } from "../lib/services.server"; |
| 22 | import { getViewer } from "../lib/session.server"; |
| 23 | |
| 24 | const REFRESH_MS = 5000; |
| 25 | |
| 26 | const dollars = (micros: number) => `$${(Math.max(0, micros) / 1_000_000).toFixed(2)}`; |
| 27 | |
| 28 | export function meta({}: Route.MetaArgs) { |
| 29 | return [ |
| 30 | { title: "g1t — Git for AI scale" }, |
| 31 | { |
| 32 | name: "description", |
| 33 | content: |
| 34 | "A git forge for thousands of agents working on the same code at once: every change isolated, every decision recorded, every change landed in order. Open source, built on Cloudflare.", |
| 35 | }, |
| 36 | ]; |
| 37 | } |
| 38 | |
| 39 | export function headers({ loaderHeaders }: Route.HeadersArgs) { |
| 40 | return { "Server-Timing": loaderHeaders.get("Server-Timing") ?? "" }; |
| 41 | } |
| 42 | |
| 43 | export async function loader({ context }: Route.LoaderArgs) { |
| 44 | const viewer = getViewer(context); |
| 45 | const started = Date.now(); |
| 46 | const times: Record<string, number> = {}; |
| 47 | const timed = <T,>(name: string, promise: Promise<T>) => |
| 48 | promise.then((value) => ((times[name] = Date.now() - started), value)); |
| 49 | // The workspace the sidebar shows, as the shell picks it. |
| 50 | const workspace = viewer?.workspaces?.[0]?.slug ?? null; |
| 51 | const [repos, pulls, assigned, models] = await Promise.all([ |
| 52 | timed("repos", reposApi.list(viewer, { memberOnly: Boolean(viewer) })), |
| 53 | timed("pulls", work.listActivePulls(viewer)), |
| 54 | timed("assigned", work.listAssignedIssues(viewer)), |
| 55 | // Whether its agents can reach a model: g1t's, or one it connected. |
| 56 | workspace ? timed("models", env.RUNNER.modelAccess(workspace).catch(() => null)) : Promise.resolve(null), |
| 57 | ]); |
| 58 | // Each issue and pull request is shown under its repository. Most are in |
| 59 | // the viewer's own, already listed; the rest are looked up once each, all |
| 60 | // at once. One the viewer can no longer see drops out. |
| 61 | const known = new Map<string, Repo>(repos.map((repo) => [repo.id, repo])); |
| 62 | const missing = [ |
| 63 | ...new Set([...assigned.map((issue) => issue.repoId), ...pulls.map(({ pull }) => pull.repoId)]), |
| 64 | ].filter((id) => !known.has(id)); |
| 65 | const looked = await Promise.all(missing.map((id) => reposApi.getById(id, viewer))); |
| 66 | for (const found of looked) if (found.ok) known.set(found.value.id, found.value); |
| 67 | times.lookups = Date.now() - started; |
| 68 | const serverTiming = Object.entries(times) |
| 69 | .map(([name, ms]) => `${name};dur=${ms}`) |
| 70 | .join(", "); |
| 71 | return data({ |
| 72 | viewer, |
| 73 | repos, |
| 74 | canRunAgents: models == null || models.hosted || models.own != null, |
| 75 | // Its free allowance on g1t's models, when that is what it runs on. |
| 76 | trial: models?.own == null ? (models?.trial ?? null) : null, |
| 77 | assigned: assigned.flatMap((issue) => { |
| 78 | const repo = known.get(issue.repoId); |
| 79 | return repo ? [{ issue, repo }] : []; |
| 80 | }), |
| 81 | active: pulls.flatMap((item) => { |
| 82 | const repo = known.get(item.pull.repoId); |
| 83 | return repo ? [{ ...item, repo }] : []; |
| 84 | }), |
| 85 | }, { headers: { "Server-Timing": serverTiming } }); |
| 86 | } |
| 87 | |
| 88 | type Active = { pull: Pull; lifecycle: Lifecycle | null; repo: Repo }; |
| 89 | |
| 90 | /** What a pull request is waiting on, in a word or two. */ |
| 91 | function standing({ pull, lifecycle }: Active): string { |
| 92 | if (lifecycle) return STAGE_LABEL[lifecycle.stage]; |
| 93 | return pull.status === "draft" ? "In progress" : "Ready for review"; |
| 94 | } |
| 95 | |
| 96 | function PullRows({ items, detail }: { items: Active[]; detail?: boolean }) { |
| 97 | return ( |
| 98 | <ul className="divide-y divide-line overflow-hidden rounded-xl border border-line bg-surface"> |
| 99 | {items.map((item) => { |
| 100 | const { pull, lifecycle, repo } = item; |
| 101 | return ( |
| 102 | <li key={pull.id}> |
| 103 | <Link |
| 104 | prefetch="intent" |
| 105 | to={`/${repo.namespace}/${repo.name}/pull/${pull.number}`} |
| 106 | className="flex items-center gap-3 px-4 py-3 transition-colors hover:bg-raised" |
| 107 | > |
| 108 | <PullIcon status={pull.status} /> |
| 109 | <span className="min-w-0 grow"> |
| 110 | <span className="block truncate font-medium">{pull.title}</span> |
| 111 | <span className="block truncate font-mono text-xs text-muted"> |
| 112 | {repo.namespace}/{repo.name}#{pull.number} |
| 113 | {pull.issue != null && ` · for #${pull.issue}`} · {pull.agent} |
| 114 | </span> |
| 115 | {detail && lifecycle && ( |
| 116 | <span className="mt-1 block text-xs text-muted">{lifecycle.detail}</span> |
| 117 | )} |
| 118 | </span> |
| 119 | {lifecycle && ( |
| 120 | <span className="hidden shrink-0 sm:block"> |
| 121 | <StageDots stage={lifecycle.stage} /> |
| 122 | </span> |
| 123 | )} |
| 124 | <span className="w-28 shrink-0 text-right text-xs text-muted"> |
| 125 | {standing(item)} |
| 126 | </span> |
| 127 | <span className="hidden w-14 shrink-0 text-right text-xs text-faint sm:block"> |
| 128 | <TimeAgo at={pull.updatedAt} /> |
| 129 | </span> |
| 130 | </Link> |
| 131 | </li> |
| 132 | ); |
| 133 | })} |
| 134 | </ul> |
| 135 | ); |
| 136 | } |
| 137 | |
| 138 | function Section({ title, children }: { title: ReactNode; children: ReactNode }) { |
| 139 | return ( |
| 140 | <section> |
| 141 | <h2 className="flex items-center gap-2 text-sm font-medium text-muted">{title}</h2> |
| 142 | <div className="mt-3">{children}</div> |
| 143 | </section> |
| 144 | ); |
| 145 | } |
| 146 | |
| 147 | function plural(count: number, one: string, many: string): string { |
| 148 | return `${count} ${count === 1 ? one : many}`; |
| 149 | } |
| 150 | |
| 151 | type Step = { done: boolean; title: string; about: string; to: string | null; action: string }; |
| 152 | |
| 153 | /** |
| 154 | * The workspace being looked at, from mission control: what it holds and |
| 155 | * what is moving in it, and the way to its people and settings. The rest of |
| 156 | * the page stays the viewer's own, across every workspace. |
| 157 | */ |
| 158 | function WorkspaceCard({ slug, role, repos, active }: { slug: string; role: string; repos: Repo[]; active: Active[] }) { |
| 159 | const mine = active.filter((item) => item.repo.namespace.toLowerCase() === slug); |
| 160 | const stats = [ |
| 161 | { value: repos.filter((repo) => repo.namespace.toLowerCase() === slug).length, label: "repositories" }, |
| 162 | { value: mine.length, label: "pull requests open" }, |
| 163 | { value: mine.filter((item) => item.lifecycle?.stage === "needs_you").length, label: "need you" }, |
| 164 | ]; |
| 165 | return ( |
| 166 | <div className="rounded-xl border border-line bg-surface p-5"> |
| 167 | <div className="flex items-center gap-3"> |
| 168 | <Avatar name={slug} size={32} square /> |
| 169 | <div className="min-w-0"> |
| 170 | <Link to={`/${slug}`} className="block truncate font-medium hover:underline"> |
| 171 | {slug} |
| 172 | </Link> |
| 173 | <p className="text-xs text-muted">Workspace · {role}</p> |
| 174 | </div> |
| 175 | </div> |
| 176 | <dl className="mt-4 grid grid-cols-3 gap-2"> |
| 177 | {stats.map((stat) => ( |
| 178 | <div key={stat.label} className="rounded-lg bg-bg/60 px-2.5 py-2 ring-1 ring-line"> |
| 179 | <dt className="sr-only">{stat.label}</dt> |
| 180 | <dd className="text-lg font-semibold tabular-nums tracking-tight">{stat.value}</dd> |
| 181 | <dd className="text-[0.6875rem] leading-tight text-muted">{stat.label}</dd> |
| 182 | </div> |
| 183 | ))} |
| 184 | </dl> |
| 185 | <div className="mt-4 flex flex-wrap gap-x-4 gap-y-1 text-sm"> |
| 186 | <Link to={`/${slug}/-/people`} className="inline-flex items-center gap-1.5 text-muted hover:text-fg"> |
| 187 | <Users size={13} /> |
| 188 | Members |
| 189 | </Link> |
| 190 | <Link |
| 191 | to={role === "owner" ? `/${slug}/-/settings` : `/${slug}/-/people`} |
| 192 | className="inline-flex items-center gap-1.5 text-muted hover:text-fg" |
| 193 | > |
| 194 | <Settings size={13} /> |
| 195 | Settings |
| 196 | </Link> |
| 197 | <Link to={`/${slug}`} className="inline-flex items-center gap-1 text-accent hover:underline"> |
| 198 | Its page <ArrowRight size={13} /> |
| 199 | </Link> |
| 200 | </div> |
| 201 | </div> |
| 202 | ); |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * The first things to do, ticked off as they are done, until an outcome has |
| 207 | * been handed to agents. Shown above everything else on mission control. |
| 208 | */ |
| 209 | function GetStarted({ steps }: { steps: Step[] }) { |
| 210 | const left = steps.filter((step) => !step.done).length; |
| 211 | return ( |
| 212 | <section className="rounded-2xl bg-surface p-5 ring-1 ring-line"> |
| 213 | <div className="flex items-baseline justify-between gap-3"> |
| 214 | <h2 className="font-semibold tracking-tight">Get started</h2> |
| 215 | <span className="text-xs text-muted"> |
| 216 | {steps.length - left} of {steps.length} done |
| 217 | </span> |
| 218 | </div> |
| 219 | <ol className="mt-4 space-y-2"> |
| 220 | {steps.map((step, index) => ( |
| 221 | <li |
| 222 | key={step.title} |
| 223 | className={`flex items-start gap-3 rounded-xl px-3 py-2.5 ${step.done ? "" : "bg-bg/50 ring-1 ring-line"}`} |
| 224 | > |
| 225 | <span |
| 226 | className={`mt-0.5 flex size-5 shrink-0 items-center justify-center rounded-full text-[0.6875rem] font-medium ${ |
| 227 | step.done ? "bg-accent text-bg" : "text-muted ring-1 ring-line-strong" |
| 228 | }`} |
| 229 | > |
| 230 | {step.done ? "✓" : index + 1} |
| 231 | </span> |
| 232 | <span className="min-w-0 grow"> |
| 233 | <span className={`block text-sm font-medium ${step.done ? "text-muted line-through decoration-faint" : ""}`}> |
| 234 | {step.title} |
| 235 | </span> |
| 236 | {!step.done && <span className="mt-0.5 block text-xs leading-5 text-muted">{step.about}</span>} |
| 237 | </span> |
| 238 | {!step.done && step.to && ( |
| 239 | <Link |
| 240 | to={step.to} |
| 241 | className="shrink-0 rounded-md bg-fg px-2.5 py-1 text-xs font-medium text-bg transition-colors hover:bg-white" |
| 242 | > |
| 243 | {step.action} |
| 244 | </Link> |
| 245 | )} |
| 246 | </li> |
| 247 | ))} |
| 248 | </ol> |
| 249 | </section> |
| 250 | ); |
| 251 | } |
| 252 | |
| 253 | export default function Home({ loaderData }: Route.ComponentProps) { |
| 254 | const { viewer, repos, active, assigned, canRunAgents, trial } = loaderData; |
| 255 | |
| 256 | const needsYou = active.filter((item) => item.lifecycle?.stage === "needs_you"); |
| 257 | const ready = active.filter((item) => item.lifecycle?.stage === "ready"); |
| 258 | const moving = active.filter( |
| 259 | (item) => item.lifecycle?.stage !== "needs_you" && item.lifecycle?.stage !== "ready", |
| 260 | ); |
| 261 | // Agents are at work, so the page changes without anyone touching it. |
| 262 | const changing = moving.some((item) => item.lifecycle || item.pull.status === "draft"); |
| 263 | const revalidator = useRevalidator(); |
| 264 | useEffect(() => { |
| 265 | if (!changing) return; |
| 266 | const timer = setInterval(() => { |
| 267 | if (document.visibilityState === "visible") revalidator.revalidate(); |
| 268 | }, REFRESH_MS); |
| 269 | return () => clearInterval(timer); |
| 270 | }, [changing, revalidator]); |
| 271 | |
| 272 | const shell = useRouteLoaderData("root")?.shell as ShellData | null | undefined; |
| 273 | if (!viewer) return <Landing repos={repos} />; |
| 274 | |
| 275 | const workspace = shell?.workspace?.slug; |
| 276 | const first = repos[0]; |
| 277 | const handedOff = active.length > 0 || (shell?.monthUsageMicros ?? 0) > 0; |
| 278 | const steps: Step[] = [ |
| 279 | { |
| 280 | done: Boolean(workspace), |
| 281 | title: "Create a workspace", |
| 282 | about: "Repositories, people and agent credit live in one.", |
| 283 | to: "/workspaces/new", |
| 284 | action: "Create", |
| 285 | }, |
| 286 | { |
| 287 | done: repos.length > 0, |
| 288 | title: "Add a repository", |
| 289 | about: "Create one, or import one from GitHub by its address. Push to it with git as usual.", |
| 290 | to: workspace ? `/new?workspace=${workspace}` : "/new", |
| 291 | action: "Add", |
| 292 | }, |
| 293 | trial?.open |
| 294 | ? { |
| 295 | done: true, |
| 296 | title: "Try g1t's agents free", |
| 297 | about: `This workspace has ${dollars(trial.limitMicros - trial.usedMicros)} of its free ${dollars(trial.limitMicros)} left on g1t's models${trial.endsAt ? `, until ${new Date(trial.endsAt).toLocaleDateString("en-US", { month: "long", day: "numeric", timeZone: "America/Los_Angeles" })}` : ""}: assign issues and watch agents land them. Connect your own model under Integrations any time for more.`, |
| 298 | to: workspace ? `/${workspace}/-/integrations` : null, |
| 299 | action: "Connect", |
| 300 | } |
| 301 | : canRunAgents |
| 302 | ? { |
| 303 | // Nothing to pay while g1t is being built out. |
| 304 | done: Boolean(shell?.free) || shell?.creditMicros == null || shell.creditMicros > 0, |
| 305 | title: "Add agent credit", |
| 306 | about: "g1t's agents are paid for from the workspace's credit, at what the model costs plus 20%.", |
| 307 | to: workspace ? `/${workspace}/-/billing` : null, |
| 308 | action: "Add credit", |
| 309 | } |
| 310 | : { |
| 311 | done: false, |
| 312 | title: "Connect a model", |
| 313 | about: `${ |
| 314 | trial?.reason === "used" |
| 315 | ? "This workspace has used its free allowance on g1t's models. " |
| 316 | : trial?.reason === "pool" || trial?.reason === "ended" |
| 317 | ? "The free allowance on g1t's models has ended. " |
| 318 | : "" |
| 319 | }Agents need a model to think with. Connect your Anthropic or OpenAI key, or any compatible endpoint; g1t itself costs nothing while it is being built out.`, |
| 320 | to: workspace ? `/${workspace}/-/integrations` : null, |
| 321 | action: "Connect", |
| 322 | }, |
| 323 | { |
| 324 | done: handedOff, |
| 325 | title: "Hand off an outcome", |
| 326 | about: "Write what you want on a repository's Plan page. A planner splits it into issues, and agents take them and land them on main.", |
| 327 | to: first ? `/${first.namespace}/${first.name}/plans` : null, |
| 328 | action: "Write one", |
| 329 | }, |
| 330 | ]; |
| 331 | const starting = steps.some((step) => !step.done); |
| 332 | |
| 333 | const summary = [ |
| 334 | moving.length > 0 && `${moving.length} in progress`, |
| 335 | ready.length > 0 && `${ready.length} ready to merge`, |
| 336 | needsYou.length > 0 && plural(needsYou.length, "needs you", "need you"), |
| 337 | assigned.length > 0 && `${assigned.length} assigned to you`, |
| 338 | ].filter(Boolean); |
| 339 | return ( |
| 340 | <main className="mx-auto grid max-w-6xl gap-10 px-4 py-10 lg:grid-cols-[1fr_20rem]"> |
| 341 | <div className="min-w-0 space-y-10"> |
| 342 | <section> |
| 343 | <div className="flex items-center gap-3"> |
| 344 | <Avatar name={viewer.username} size={36} /> |
| 345 | <div> |
| 346 | <h1 className="text-xl font-semibold tracking-tight"> |
| 347 | Mission control |
| 348 | </h1> |
| 349 | <p className="text-sm text-muted"> |
| 350 | {summary.length === 0 |
| 351 | ? "Nothing is being worked on right now." |
| 352 | : `${summary.join(" · ")}.`} |
| 353 | </p> |
| 354 | </div> |
| 355 | </div> |
| 356 | </section> |
| 357 | |
| 358 | {starting && <GetStarted steps={steps} />} |
| 359 | |
| 360 | {needsYou.length > 0 && ( |
| 361 | <Section |
| 362 | title={ |
| 363 | <> |
| 364 | <Hand size={14} className="text-warn" /> |
| 365 | Needs you |
| 366 | </> |
| 367 | } |
| 368 | > |
| 369 | <PullRows items={needsYou} detail /> |
| 370 | </Section> |
| 371 | )} |
| 372 | |
| 373 | {ready.length > 0 && ( |
| 374 | <Section title="Ready to merge"> |
| 375 | <PullRows items={ready} /> |
| 376 | </Section> |
| 377 | )} |
| 378 | |
| 379 | {assigned.length > 0 && ( |
| 380 | <Section title="Assigned to you"> |
| 381 | <ul className="divide-y divide-line overflow-hidden rounded-xl border border-line bg-surface"> |
| 382 | {assigned.map(({ issue, repo }) => ( |
| 383 | <li key={issue.id}> |
| 384 | <Link |
| 385 | prefetch="intent" |
| 386 | to={`/${repo.namespace}/${repo.name}/issues/${issue.number}`} |
| 387 | className="flex items-center gap-3 px-4 py-3 transition-colors hover:bg-raised" |
| 388 | > |
| 389 | <IssueIcon issue={issue} /> |
| 390 | <span className="min-w-0 grow"> |
| 391 | <span className="block truncate font-medium">{issue.title}</span> |
| 392 | <span className="block truncate font-mono text-xs text-muted"> |
| 393 | {repo.namespace}/{repo.name}#{issue.number} |
| 394 | </span> |
| 395 | </span> |
| 396 | {issue.agent && <Assignee agent={issue.agent} />} |
| 397 | <span className="hidden w-14 shrink-0 text-right text-xs text-faint sm:block"> |
| 398 | <TimeAgo at={issue.updatedAt} /> |
| 399 | </span> |
| 400 | </Link> |
| 401 | </li> |
| 402 | ))} |
| 403 | </ul> |
| 404 | </Section> |
| 405 | )} |
| 406 | |
| 407 | <Section title="In progress"> |
| 408 | {moving.length === 0 ? ( |
| 409 | <EmptyState title="No pull requests in progress"> |
| 410 | Assign issues to the g1t agent from a repository's Issues tab, |
| 411 | or point your own agent at one. |
| 412 | </EmptyState> |
| 413 | ) : ( |
| 414 | <PullRows items={moving} /> |
| 415 | )} |
| 416 | </Section> |
| 417 | |
| 418 | <section> |
| 419 | <div className="flex items-center justify-between"> |
| 420 | <h2 className="text-sm font-medium text-muted">Your repositories</h2> |
| 421 | <ButtonLink to="/new" variant="quiet"> |
| 422 | <Plus size={14} /> |
| 423 | New |
| 424 | </ButtonLink> |
| 425 | </div> |
| 426 | <RepoList repos={repos} /> |
| 427 | </section> |
| 428 | </div> |
| 429 | |
| 430 | <aside className="space-y-4"> |
| 431 | {shell?.workspace && ( |
| 432 | <WorkspaceCard |
| 433 | slug={shell.workspace.slug.toLowerCase()} |
| 434 | role={shell.workspace.role} |
| 435 | repos={repos} |
| 436 | active={active} |
| 437 | /> |
| 438 | )} |
| 439 | <div className="rounded-xl border border-line bg-surface p-5"> |
| 440 | <h2 className="font-medium">Connect an agent</h2> |
| 441 | <p className="mt-1.5 text-sm text-muted"> |
| 442 | Add g1t to Claude Code, then run /mcp in it to sign in through |
| 443 | your browser. |
| 444 | </p> |
| 445 | <div className="mt-4 space-y-2"> |
| 446 | <CopyLine |
| 447 | prompt |
| 448 | text="claude mcp add --transport http g1t https://mcp.g1t.sh" |
| 449 | /> |
| 450 | </div> |
| 451 | <Link |
| 452 | to="https://docs.g1t.sh/guides/bring-your-own-agent/" |
| 453 | className="mt-4 inline-flex items-center gap-1 text-sm text-accent hover:underline" |
| 454 | > |
| 455 | How it works <ArrowRight size={13} /> |
| 456 | </Link> |
| 457 | </div> |
| 458 | <div className="rounded-xl border border-line bg-surface p-5"> |
| 459 | <h2 className="font-medium">Explore</h2> |
| 460 | <p className="mt-1.5 text-sm text-muted"> |
| 461 | Browse public repositories and the issues open on them. |
| 462 | </p> |
| 463 | <Link |
| 464 | to="/explore" |
| 465 | className="mt-3 inline-flex items-center gap-1 text-sm text-accent hover:underline" |
| 466 | > |
| 467 | Public repositories <ArrowRight size={13} /> |
| 468 | </Link> |
| 469 | </div> |
| 470 | </aside> |
| 471 | </main> |
| 472 | ); |
| 473 | } |