flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

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

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