g1t/apps/web/app/routes/home.tsx

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