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.

g1t.sh
128 linesCodeBlameRaw
1import { privacy } from "./lib/services.server";
2import { isRouteErrorResponse, Links, Meta, Outlet, useRouteLoaderData } from "react-router";
3
4import type { Route } from "./+types/root";
5import "./app.css";
6import displayFont from "@g1t/theme/fonts/bricolage-grotesque-latin.woff2?url";
7import sansFont from "@g1t/theme/fonts/hanken-grotesk-latin.woff2?url";
8import { MobileBar, Sidebar } from "./components/shell";
9import { ButtonLink } from "./components/ui";
10import type { NavCounts } from "./lib/nav";
11import { pauseBanner, spendBanner } from "./lib/costs";
12import { admin, statusAdmin } from "./lib/services.server";
13import { settle } from "./lib/settle";
14import { requireStaff, zoneContext } from "./lib/staff";
15
16export const links: Route.LinksFunction = () => [
17 { rel: "icon", type: "image/svg+xml", href: "/favicon.svg" },
18 // The faces are served by sudo itself (@g1t/theme); these two are on every page.
19 { rel: "preload", href: sansFont, as: "font", type: "font/woff2", crossOrigin: "anonymous" },
20 { rel: "preload", href: displayFont, as: "font", type: "font/woff2", crossOrigin: "anonymous" },
21];
22
23export const meta: Route.MetaFunction = () => [
24 { title: "sudo · g1t" },
25 { name: "robots", content: "noindex, nofollow" },
26];
27
28export async function loader({ context }: Route.LoaderArgs) {
29 const { email } = requireStaff(context);
30 // The sidebar's counts: a service that does not answer shows none.
31 const [incidents, alerts, caps, guard, erasures] = await Promise.all([
32 settle(statusAdmin.openCount()),
33 settle(admin.costAlerts()),
34 settle(admin.spendCaps()),
35 settle(admin.platformGuard()),
36 settle(privacy.requests()),
37 ]);
38 const counts: NavCounts = { incidents: incidents.ok ? incidents.value : 0, privacy: erasures.ok ? erasures.value.filter(r => !r.closed_at).length : 0 };
39 // Every page says times in this zone (components/ui.tsx `When`).
40 const { zone, chosen } = context.get(zoneContext);
41 // Margin alerts (billing's margin guard): a red bar on every page until they clear.
42 const rank = ["overall", "margin", "leak"];
43 const margin = alerts.ok
44 ? alerts.value.filter((alert) => rank.includes(alert.kind)).sort((a, b) => rank.indexOf(a.kind) - rank.indexOf(b.kind))
45 : [];
46 // g1t's own spend (billing's budget): the daily breaker open, or a comped
47 // account's monthly budget used up. Red until it clears or staff act.
48 const spend = caps.ok ? spendBanner(caps.value) : null;
49 // A platform pause (billing's platform.rs): red on every page while any
50 // level is paused, by staff or by the usage watcher.
51 const paused = guard.ok ? pauseBanner(guard.value) : null;
52 return { email, counts, zone, zoneChosen: chosen, margin, spend, paused };
53}
54
55export function Layout({ children }: { children: React.ReactNode }) {
56 const root = useRouteLoaderData<typeof loader>("root");
57 return (
58 <html lang="en">
59 <head>
60 <meta charSet="utf-8" />
61 <meta name="viewport" content="width=device-width, initial-scale=1" />
62 <meta name="theme-color" content="#0f0f11" />
63 <Meta />
64 <Links />
65 </head>
66 <body className="min-h-screen">
67 <Sidebar email={root?.email} counts={root?.counts} />
68 <MobileBar email={root?.email} counts={root?.counts} />
69 <div className="lg:pl-60">
70 {root?.margin && root.margin.length > 0 && (
71 <div role="alert" className="border-b border-danger/40 bg-danger/12 px-4 py-2 text-sm text-danger">
72 <span className="font-medium">Margin alert:</span> {root.margin[0]!.detail}
73 {root.margin.length > 1 && <span className="text-danger/80"> And {root.margin.length - 1} more.</span>}{" "}
74 <a href="/costs" className="underline underline-offset-2">
75 Costs &amp; margin
76 </a>
77 </div>
78 )}
79 {root?.spend && (
80 <div role="alert" className="border-b border-danger/40 bg-danger/12 px-4 py-2 text-sm text-danger">
81 <span className="font-medium">Spend cap:</span> {root.spend}{" "}
82 <a href="/costs#spend" className="underline underline-offset-2">
83 g1t's own spend
84 </a>
85 </div>
86 )}
87 {root?.paused && (
88 <div role="alert" className="border-b border-danger/40 bg-danger/12 px-4 py-2 text-sm text-danger">
89 <span className="font-medium">Platform pause:</span> {root.paused}{" "}
90 <a href="/costs#platform" className="underline underline-offset-2">
91 Platform pause
92 </a>
93 </div>
94 )}
95 {children}
96 </div>
97 {/* No <Scripts />: sudo ships no JavaScript, and its policy allows none. */}
98 </body>
99 </html>
100 );
101}
102
103export default function App() {
104 return <Outlet />;
105}
106
107export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
108 let title = "Something went wrong";
109 let details = "An unexpected error occurred.";
110 if (isRouteErrorResponse(error)) {
111 title = error.status === 404 ? "Not found" : `Error ${error.status}`;
112 details = typeof error.data === "string" && error.data ? error.data : error.statusText || details;
113 } else if (error instanceof Error) {
114 // Staff only: the real reason helps more than a polite one.
115 details = error.message;
116 }
117 return (
118 <main className="mx-auto max-w-xl px-4 py-24 text-center">
119 <h1 className="text-2xl font-semibold tracking-tight">{title}</h1>
120 <p className="mt-3 wrap-break-word text-muted">{details}</p>
121 <div className="mt-8">
122 <ButtonLink to="/" variant="quiet">
123 Back to the overview
124 </ButtonLink>
125 </div>
126 </main>
127 );
128}