Skip to content

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

417 linesCodeBlameRaw
1import { ArrowRight, Bot, Cloud, Laptop, Plus, ServerCog, Workflow } from "lucide-react";
2import type { ReactNode } from "react";
3import { Link } from "react-router";
4
5import { RUN_KIND_LABEL, type Runner, type RunKind } from "@g1t/contracts";
6
7import { money } from "../lib/money";
8import { type CloudWork, machineTime, perMinute } from "../lib/runners";
9import type { RunnersAction, RunnersPageData } from "../lib/runners.server";
10import { DesktopRunners } from "./desktop-runners";
11import { Groups, NewRunner, RunnerRow, RunnerSettingsForm, STATUS } from "./runners";
12import { EmptyState, ErrorText, TimeAgo } from "./ui";
13import { Tooltip, TooltipContent, TooltipTrigger } from "./ui/tooltip";
14
15/** The most of what runs on g1t's cloud the card lists before saying how many more. */
16const CLOUD_SHOWN = 6;
17
18function Section({ id, title, about, action, children }: { id?: string; title: string; about?: ReactNode; action?: ReactNode; children: ReactNode }) {
19 return (
20 <section id={id} className="scroll-mt-6 space-y-3">
21 <div className="flex flex-wrap items-end justify-between gap-x-4 gap-y-1">
22 <div className="min-w-0">
23 <h2 className="text-base font-semibold tracking-tight">{title}</h2>
24 {about && <div className="mt-0.5 text-sm text-muted">{about}</div>}
25 </div>
26 {action}
27 </div>
28 {children}
29 </section>
30 );
31}
32
33/** One figure in a place's card: a label and its value. */
34function Figure({ label, hint, children }: { label: string; hint?: string; children: ReactNode }) {
35 return (
36 <div className="flex items-baseline justify-between gap-3 py-2 text-sm">
37 <dt className="text-muted">
38 {hint ? (
39 <Tooltip>
40 <TooltipTrigger asChild>
41 <span className="cursor-help underline decoration-line-strong decoration-dotted underline-offset-4">{label}</span>
42 </TooltipTrigger>
43 <TooltipContent>{hint}</TooltipContent>
44 </Tooltip>
45 ) : (
46 label
47 )}
48 </dt>
49 <dd className="min-w-0 text-right text-fg tabular-nums">{children}</dd>
50 </div>
51 );
52}
53
54function Unknown({ what }: { what: string }) {
55 return <span className="text-faint">{what} didn&apos;t answer</span>;
56}
57
58function PlaceCard({
59 icon,
60 title,
61 tag,
62 about,
63 headline,
64 children,
65}: {
66 icon: ReactNode;
67 title: string;
68 tag: ReactNode;
69 about: string;
70 headline: ReactNode;
71 children: ReactNode;
72}) {
73 return (
74 <section className="flex min-w-0 flex-col rounded-2xl border border-line bg-surface">
75 <header className="px-5 pt-4">
76 <div className="flex items-center gap-2">
77 <span className="grid size-7 shrink-0 place-items-center rounded-lg bg-raised text-fg-soft">{icon}</span>
78 <h2 className="text-sm font-semibold">{title}</h2>
79 <span className="ml-auto">{tag}</span>
80 </div>
81 <p className="mt-2 text-sm leading-relaxed text-muted">{about}</p>
82 </header>
83 <div className="px-5 pt-4">{headline}</div>
84 <dl className="mt-2 divide-y divide-line border-t border-line px-5 py-1">{children}</dl>
85 </section>
86 );
87}
88
89function kindLabel(work: CloudWork): string {
90 if (work.kind === "workflow") return "Workflow job";
91 return RUN_KIND_LABEL[work.detail as RunKind] ?? "Sandbox run";
92}
93
94function CloudList({ data }: { data: RunnersPageData }) {
95 const cloud = data.cloud;
96 if (!cloud) return <p className="px-5 py-4 text-sm text-muted">What runs on g1t&apos;s cloud can&apos;t be read right now.</p>;
97 if (cloud.running.length === 0) {
98 return (
99 <p className="px-5 py-4 text-sm text-muted">
100 Nothing is running here now. A sandbox starts for each run or job and stops when it ends{cloud.queued > 0 ? `; ${cloud.queued} waiting to start` : ""}.
101 </p>
102 );
103 }
104 const shown = cloud.running.slice(0, CLOUD_SHOWN);
105 const rest = cloud.running.length - shown.length;
106 return (
107 <ul className="divide-y divide-line">
108 {shown.map((work) => (
109 <li key={`${work.kind}:${work.id}`} className="flex items-center gap-3 px-5 py-2.5">
110 <span className="grid size-6 shrink-0 place-items-center rounded-md bg-info/12 text-info" aria-hidden>
111 {work.kind === "agent" ? <Bot size={13} /> : <Workflow size={13} />}
112 </span>
113 <div className="min-w-0 grow">
114 <Link to={work.href} className="block truncate text-sm text-fg hover:underline">
115 {work.title}
116 </Link>
117 <p className="truncate text-xs text-muted">
118 {kindLabel(work)} · {work.repo}
119 </p>
120 </div>
121 {work.startedAt && (
122 <span className="shrink-0 text-xs text-faint">
123 <TimeAgo at={work.startedAt} />
124 </span>
125 )}
126 </li>
127 ))}
128 {(rest > 0 || cloud.more || cloud.queued > 0) && (
129 <li className="px-5 py-2.5 text-xs text-muted">
130 {[
131 rest > 0 || cloud.more ? `${rest > 0 ? rest : "More"}${cloud.more ? "+" : ""} more running` : null,
132 cloud.queued > 0 ? `${cloud.queued} waiting to start` : null,
133 ]
134 .filter(Boolean)
135 .join(" · ")}
136 </li>
137 )}
138 </ul>
139 );
140}
141
142function StatusCounts({ runners }: { runners: Runner[] }) {
143 const counts = { busy: 0, online: 0, offline: 0 } as Record<Runner["status"], number>;
144 for (const runner of runners) counts[runner.status] += 1;
145 return (
146 <ul className="flex flex-wrap gap-x-4 gap-y-1 text-xs text-muted">
147 {(["busy", "online", "offline"] as const).map((status) => (
148 <li key={status} className="flex items-center gap-1.5">
149 <span className={`size-2 rounded-full ${STATUS[status].dot}`} aria-hidden />
150 <span className="text-fg tabular-nums">{counts[status]}</span> {STATUS[status].label.toLowerCase()}
151 </li>
152 ))}
153 </ul>
154 );
155}
156
157/** The workspace's Runners page: g1t's cloud and its own runners, side by side. */
158export function RunnersPage({ data, action, slug }: { data: RunnersPageData; action: RunnersAction | undefined; slug: string }) {
159 const own = data.runners;
160 const online = own.filter((runner) => runner.status !== "offline").length;
161 const cost = data.cost;
162 const running = data.cloud?.running.length ?? null;
163 const usage = `/${slug}/-/usage`;
164 return (
165 <div className="space-y-10">
166 <header className="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between">
167 <div className="min-w-0">
168 <h1 className="text-[1.75rem] leading-tight font-semibold tracking-tight">Runners</h1>
169 <p className="mt-1.5 max-w-2xl text-sm leading-relaxed text-muted">
170 The machines your workflow jobs, checks and merge queue run on. g1t&apos;s cloud needs nothing set up; your own runners are any machine with{" "}
171 <code className="font-mono text-fg-soft">g1t-runner</code> on it, and time on them is free.
172 </p>
173 </div>
174 <a
175 href="#add"
176 className="inline-flex h-9 shrink-0 items-center gap-1.5 self-start rounded-lg bg-accent px-3.5 text-sm font-medium text-bg transition-colors hover:bg-accent-hover"
177 >
178 <Plus size={15} />
179 Add a runner
180 </a>
181 </header>
182
183 {(action?.notice || action?.error || data.error) && (
184 <div>
185 {action?.notice && <p className="text-sm text-success">{action.notice}</p>}
186 <ErrorText>{action?.error ?? data.error ?? null}</ErrorText>
187 </div>
188 )}
189
190 <div className="grid items-start gap-5 lg:grid-cols-2">
191 <PlaceCard
192 icon={<Cloud size={15} />}
193 title="g1t cloud"
194 tag={<span className="rounded-full bg-raised px-2 py-0.5 text-xs text-fg-soft">Managed by g1t</span>}
195 about="A fresh sandbox for every run and workflow job, stopped when it ends. Billed by the second at the price below."
196 headline={
197 <div className="flex items-baseline gap-2">
198 <span className="text-3xl font-semibold tracking-tight tabular-nums">{running ?? "–"}</span>
199 <span className="text-sm text-muted">running now</span>
200 </div>
201 }
202 >
203 <Figure label="This month" hint="Runner minutes on your usage, at price, from the first of the month. Each job's time is rounded up to the minute.">
204 {cost ? (
205 <>
206 {machineTime(cost.cloudSeconds)} · {money(cost.cloudMicros)}
207 </>
208 ) : (
209 <Unknown what="Billing" />
210 )}
211 </Figure>
212 <Figure label="Price" hint={`A minute of each machine: ${data.prices.map((price) => price.title).join("; ")}.`}>
213 <span className="flex flex-wrap justify-end gap-x-2">
214 {data.prices.map((price) => (
215 <span key={price.machine} className="whitespace-nowrap">
216 {price.machine} {perMinute(price.perMinuteMicros)}/min
217 </span>
218 ))}
219 </span>
220 </Figure>
221 </PlaceCard>
222
223 <PlaceCard
224 icon={<ServerCog size={15} />}
225 title="Your runners"
226 tag={<span className="rounded-full bg-success/12 px-2 py-0.5 text-xs font-medium text-success">Free</span>}
227 about="Your own machines: Linux, macOS or Windows, anywhere they can reach g1t. They only connect out, and take the work whose labels they have."
228 headline={
229 <div className="space-y-2">
230 <div className="flex items-baseline gap-2">
231 <span className="text-3xl font-semibold tracking-tight tabular-nums">{own.length === 0 ? 0 : online}</span>
232 <span className="text-sm text-muted">{own.length === 0 ? "runners yet" : `of ${own.length} online`}</span>
233 </div>
234 {own.length > 0 && <StatusCounts runners={own} />}
235 </div>
236 }
237 >
238 <Figure label="This month" hint="Self-hosted runner time on your usage, from the first of the month. It is never charged.">
239 {cost ? (
240 <>
241 {machineTime(cost.ownSeconds)} · {money(0)}
242 </>
243 ) : (
244 <Unknown what="Billing" />
245 )}
246 </Figure>
247 <Figure label="Waiting for one of them">
248 {data.waiting ? (
249 data.waiting.jobs + data.waiting.tasks === 0 ? (
250 "Nothing"
251 ) : (
252 [
253 data.waiting.jobs > 0 ? `${data.waiting.jobs} ${data.waiting.jobs === 1 ? "job" : "jobs"}` : null,
254 data.waiting.tasks > 0 ? `${data.waiting.tasks} sandbox ${data.waiting.tasks === 1 ? "run" : "runs"}` : null,
255 ]
256 .filter(Boolean)
257 .join(", ")
258 )
259 ) : (
260 <Unknown what="Actions" />
261 )}
262 </Figure>
263 <Figure label="Takes sandbox runs">
264 {data.settings ? (data.settings.agentsOnSelfHosted ? `Yes, labelled ${data.settings.agentLabels.join(", ")}` : "No") : "–"}
265 </Figure>
266 </PlaceCard>
267 </div>
268
269 <div className="grid items-start gap-5 lg:grid-cols-2">
270 <Section title="On g1t cloud now" about="Sandbox runs and workflow jobs in g1t's sandboxes.">
271 <div className="rounded-2xl border border-line bg-surface">
272 <CloudList data={data} />
273 </div>
274 </Section>
275 <Section
276 title="Machine time"
277 about={cost ? `${cost.from} to ${cost.until}, as your usage shows it.` : "From your usage."}
278 action={
279 <Link to={usage} className="inline-flex items-center gap-1 text-xs text-muted hover:text-fg">
280 Usage
281 <ArrowRight size={12} />
282 </Link>
283 }
284 >
285 <TimeSplit data={data} />
286 </Section>
287 </div>
288
289 <Section
290 title="Your runners"
291 about={own.length === 0 ? "None yet." : `${online} of ${own.length} online. A runner that hasn't been heard from for 90 seconds is offline.`}
292 >
293 {own.length === 0 ? (
294 <EmptyState title="No runners of your own yet">
295 <a href="#add" className="underline underline-offset-2">
296 Add one
297 </a>{" "}
298 to run jobs on your hardware. It connects out to g1t; nothing needs to reach the machine.
299 </EmptyState>
300 ) : (
301 <ul className="divide-y divide-line rounded-2xl border border-line bg-surface">
302 {own.map((runner) => (
303 <RunnerRow key={runner.id} runner={runner} manage />
304 ))}
305 </ul>
306 )}
307 </Section>
308
309 <Section
310 id="desktops"
311 title="Desktops"
312 about="Computers with the g1t desktop app, whose runner runs while g1t is open there: what each is doing, and when it isn't running, why and the fix."
313 >
314 <DesktopRunners desktops={data.desktops} slug={slug} runners={own} />
315 </Section>
316
317 <Section title="Where work runs" about="For every project in the workspace, unless a project says otherwise in its own settings.">
318 <div className="grid gap-3 md:grid-cols-3">
319 <WhereCard icon={<Workflow size={15} />} title="Workflow jobs">
320 Each job&apos;s <code className="font-mono text-fg-soft">runs-on</code> decides. <code className="font-mono text-fg-soft">ubuntu-latest</code>,{" "}
321 <code className="font-mono text-fg-soft">g1t-4core</code> and other Linux labels run on g1t cloud;{" "}
322 <code className="font-mono text-fg-soft">self-hosted</code> and your own labels run on your runners.
323 </WhereCard>
324 <WhereCard icon={<Bot size={15} />} title="Checks and the merge queue">
325 {data.settings?.agentsOnSelfHosted
326 ? `Checks, merge checks and the merge queue run on your runners labelled ${data.settings.agentLabels.join(", ")}.`
327 : "Checks, merge checks and the merge queue run on g1t cloud. Switch them to your runners below."}
328 </WhereCard>
329 <WhereCard icon={<Laptop size={15} />} title="Your desktop">
330 The g1t desktop app runs a runner while it&apos;s open, sandboxed and labelled <code className="font-mono text-fg-soft">desktop</code>, for jobs
331 that ask for <code className="font-mono text-fg-soft">self-hosted</code>. Each desktop is under{" "}
332 <a href="#desktops" className="underline underline-offset-2">
333 Desktops
334 </a>
335 .
336 </WhereCard>
337 </div>
338 <RunnerSettingsForm
339 key={data.settings ? `${data.settings.agentsOnSelfHosted}:${data.settings.forkPullRequests}:${data.settings.agentLabels.join(",")}` : "none"}
340 data={data}
341 manage
342 scope="workspace"
343 />
344 </Section>
345
346 <Section
347 id="add"
348 title="Add a runner"
349 about="Download g1t-runner, register it with a token made here, and start it. Linux, macOS and Windows, x64 and arm64, or Docker."
350 >
351 <NewRunner token={action?.token ?? null} groups={data.groups} repoScoped={false} />
352 </Section>
353
354 <Section
355 title="Groups"
356 about="Which repositories may use which runners. A runner joins the default group, every repository, unless its token names another."
357 >
358 <Groups groups={data.groups} repositories={data.repositories} manage action={action} />
359 </Section>
360 </div>
361 );
362}
363
364function WhereCard({ icon, title, children }: { icon: ReactNode; title: string; children: ReactNode }) {
365 return (
366 <div className="rounded-2xl border border-line bg-surface p-4">
367 <h3 className="flex items-center gap-2 text-sm font-medium">
368 <span className="text-muted">{icon}</span>
369 {title}
370 </h3>
371 <p className="mt-2 text-sm leading-relaxed text-muted">{children}</p>
372 </div>
373 );
374}
375
376/** This month's machine time, g1t cloud's against the workspace's own, as one bar. */
377function TimeSplit({ data }: { data: RunnersPageData }) {
378 const cost = data.cost;
379 if (!cost) {
380 return (
381 <div className="rounded-2xl border border-line bg-surface px-5 py-4 text-sm text-muted">
382 Billing didn&apos;t answer, so this month&apos;s time can&apos;t be shown right now.
383 </div>
384 );
385 }
386 const total = cost.cloudSeconds + cost.ownSeconds;
387 return (
388 <div className="rounded-2xl border border-line bg-surface px-5 py-4">
389 {total === 0 ? (
390 <p className="text-sm text-muted">No machine time yet this month.</p>
391 ) : (
392 <div className="flex h-2.5 gap-0.5 overflow-hidden rounded-full" role="img" aria-label="This month's machine time by where it ran">
393 {cost.cloudSeconds > 0 && <span className="h-full min-w-0.75 bg-info" style={{ flexGrow: cost.cloudSeconds }} />}
394 {cost.ownSeconds > 0 && <span className="h-full min-w-0.75 bg-success" style={{ flexGrow: cost.ownSeconds }} />}
395 </div>
396 )}
397 <ul className="mt-3 space-y-2 text-sm">
398 <li className="flex items-center gap-2">
399 <span className="size-2 shrink-0 rounded-xs bg-info" aria-hidden />
400 <span className="min-w-0 grow truncate text-fg-soft">g1t cloud</span>
401 <span className="text-muted tabular-nums">{machineTime(cost.cloudSeconds)}</span>
402 <span className="w-20 text-right text-fg tabular-nums">{money(cost.cloudMicros)}</span>
403 </li>
404 <li className="flex items-center gap-2">
405 <span className="size-2 shrink-0 rounded-xs bg-success" aria-hidden />
406 <span className="min-w-0 grow truncate text-fg-soft">Your runners</span>
407 <span className="text-muted tabular-nums">{machineTime(cost.ownSeconds)}</span>
408 <span className="w-20 text-right text-fg tabular-nums">{money(0)}</span>
409 </li>
410 </ul>
411 <p className="mt-4 text-[0.6875rem] leading-relaxed text-faint">
412 {cost.free ? "Usage at cost: g1t charges nothing for it now." : "At price, before your plan's included usage or credit paid for any of it."} Models are
413 separate.
414 </p>
415 </div>
416 );
417}