g1t/apps/web/app/root.tsx

405 lines13,982 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Initial g1t: services, event bus, intents and attempts1import {
Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed)2 BookOpen,
3 ChevronDown,
4 LayoutDashboard,
5 LogOut,
6 Plus,
7 Search,
8 Settings,
9} from "lucide-react";
10import {
Initial g1t: services, event bus, intents and attempts11 Form,
12 isRouteErrorResponse,
13 Link,
14 Links,
15 Meta,
API and MCP server, Rust identity service, registration, site redesign16 NavLink,
Initial g1t: services, event bus, intents and attempts17 Outlet,
18 Scripts,
19 ScrollRestoration,
Agents as a team: lifecycle, merge queue, billing and a new shell20 type ShouldRevalidateFunctionArgs,
Initial g1t: services, event bus, intents and attempts21 useRouteLoaderData,
Acceptance checks in sandboxes, line comments and review verdicts22 useSubmit,
Initial g1t: services, event bus, intents and attempts23} from "react-router";
24
Email verification, password reset, and Git for AI scale positioning25import type { User } from "@g1t/contracts";
26
Initial g1t: services, event bus, intents and attempts27import type { Route } from "./+types/root";
28import "./app.css";
29import { Logo } from "./components/logo";
Agents as a team: lifecycle, merge queue, billing and a new shell30import { Avatar, ButtonLink, notACredential } from "./components/ui";
Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed)31import {
32 DropdownMenu,
33 DropdownMenuContent,
34 DropdownMenuItem,
35 DropdownMenuLabel,
36 DropdownMenuSeparator,
37 DropdownMenuTrigger,
38} from "./components/ui/dropdown-menu";
Agents as a team: lifecycle, merge queue, billing and a new shell39import { AppShell, Progress, type ShellData } from "./components/shell";
40import { billing, repos, work } from "./lib/services.server";
41import { getViewer, roleIn, viewerMiddleware } from "./lib/session.server";
Initial g1t: services, event bus, intents and attempts42
43export const links: Route.LinksFunction = () => [
44 { rel: "icon", type: "image/svg+xml", href: "/favicon.svg" },
45 { rel: "preconnect", href: "https://fonts.googleapis.com" },
46 {
47 rel: "preconnect",
48 href: "https://fonts.gstatic.com",
49 crossOrigin: "anonymous",
50 },
51 {
52 rel: "stylesheet",
API and MCP server, Rust identity service, registration, site redesign53 href: "https://fonts.googleapis.com/css2?family=Inter:opsz,wght@14..32,400..700&family=JetBrains+Mono:wght@400;500;600&display=swap",
Initial g1t: services, event bus, intents and attempts54 },
55];
56
57export const middleware: Route.MiddlewareFunction[] = [viewerMiddleware];
58
Agents as a team: lifecycle, merge queue, billing and a new shell59export async function loader({ context, params }: Route.LoaderArgs) {
60 const user = getViewer(context);
61 return { user, shell: user ? await shellFor(user, params) : null };
Initial g1t: services, event bus, intents and attempts62}
63
Agents as a team: lifecycle, merge queue, billing and a new shell64/**
65 * The sidebar only changes with the workspace or repository being looked
66 * at, or after something was submitted: not on every page within them.
67 */
68export function shouldRevalidate({
69 currentParams,
70 nextParams,
71 formMethod,
72 defaultShouldRevalidate,
73}: ShouldRevalidateFunctionArgs) {
74 if (formMethod && formMethod !== "GET") return defaultShouldRevalidate;
75 return currentParams.owner !== nextParams.owner || currentParams.repo !== nextParams.repo;
76}
77
78/**
79 * The sidebar: the workspace being looked at if they belong to it, else
80 * their first; its repositories; and the repository being looked at.
81 */
82async function shellFor(
83 user: User,
84 params: { owner?: string; repo?: string },
85): Promise<ShellData> {
86 const memberships = user.workspaces ?? [];
87 const here = params.owner ? memberships.find((m) => m.slug === params.owner?.toLowerCase()) : undefined;
88 const workspace = here ?? memberships[0] ?? null;
89 const path = params.owner && params.repo ? { namespace: params.owner, name: params.repo } : null;
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request90 const now = new Date();
91 const monthStart = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1)).toISOString();
92 const [listed, counts, account, usage] = await Promise.all([
Agents as a team: lifecycle, merge queue, billing and a new shell93 workspace ? repos.list(user, { namespace: workspace.slug }) : Promise.resolve([]),
94 path ? work.counts(path, user) : Promise.resolve(null),
95 workspace ? billing.account(workspace.slug, user) : Promise.resolve(null),
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request96 workspace ? billing.usage(workspace.slug, user, monthStart) : Promise.resolve(null),
Agents as a team: lifecycle, merge queue, billing and a new shell97 ]);
98 return {
99 workspace,
100 repos: listed
101 .filter((repo) => !repo.forkOf)
102 .map(({ namespace, name, isPrivate }) => ({ namespace, name, isPrivate })),
103 repo:
104 path && counts?.ok
105 ? {
106 ...path,
107 member: roleIn(user, path.namespace) != null,
108 issues: counts.value.issues,
109 pulls: counts.value.pulls,
110 }
111 : null,
Free while g1t is being built out; agents can check out their own forks112 // While g1t is being built out nothing is charged, so no credit is shown.
Agents as a team: lifecycle, merge queue, billing and a new shell113 creditMicros:
Free while g1t is being built out; agents can check out their own forks114 account?.ok && account.value.status.enabled && !account.value.status.free ? account.value.balanceMicros : null,
115 free: account?.ok ? Boolean(account.value.status.free) : false,
Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request116 monthSpentMicros: usage?.ok ? usage.value.spentMicros : null,
Agents as a team: lifecycle, merge queue, billing and a new shell117 };
118}
119
API and MCP server, Rust identity service, registration, site redesign120function HeaderLink({ to, children }: { to: string; children: React.ReactNode }) {
121 return (
122 <NavLink
123 to={to}
124 className={({ isActive }) =>
125 `rounded-md px-2.5 py-1.5 text-sm transition-colors hover:bg-raised hover:text-fg ${
126 isActive ? "text-fg" : "text-muted"
127 }`
128 }
129 >
130 {children}
131 </NavLink>
132 );
133}
134
Email verification, password reset, and Git for AI scale positioning135function Header({ user }: { user: User | null | undefined }) {
Acceptance checks in sandboxes, line comments and review verdicts136 const submit = useSubmit();
API and MCP server, Rust identity service, registration, site redesign137 return (
138 <header className="sticky top-0 z-40 border-b border-line bg-surface/85 backdrop-blur">
139 <div className="mx-auto flex h-14 max-w-6xl items-center gap-2 px-4">
140 <Link to="/" aria-label="g1t home" className="mr-2">
141 <Logo />
142 </Link>
143 <Form action="/search" role="search" className="relative hidden grow sm:block sm:max-w-xs">
144 <Search
145 size={14}
146 className="pointer-events-none absolute top-1/2 left-3 -translate-y-1/2 text-faint"
147 />
148 <input
149 name="q"
Agents as a team: lifecycle, merge queue, billing and a new shell150 {...notACredential()}
API and MCP server, Rust identity service, registration, site redesign151 placeholder="Search repositories"
152 aria-label="Search repositories"
153 className="w-full rounded-md border border-line bg-bg py-1.5 pr-3 pl-8 text-sm outline-none transition-colors placeholder:text-faint hover:border-line-strong focus:border-accent-dim"
154 />
155 </Form>
156 <nav className="flex items-center gap-0.5">
157 <HeaderLink to="/explore">Explore</HeaderLink>
Docs as their own app; shared theme package158 <HeaderLink to="https://docs.g1t.sh/">Docs</HeaderLink>
API and MCP server, Rust identity service, registration, site redesign159 </nav>
160 <div className="ml-auto flex items-center gap-2">
161 {user ? (
162 <>
163 <Link
164 to="/new"
165 aria-label="New repository"
166 className="rounded-md border border-line p-1.5 text-muted transition-colors hover:border-line-strong hover:text-fg"
167 >
168 <Plus size={16} />
169 </Link>
Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed)170 <DropdownMenu>
171 <DropdownMenuTrigger
172 aria-label="Account menu"
173 className="flex items-center gap-1.5 rounded-md p-1 outline-none transition-colors hover:bg-raised data-[state=open]:bg-raised"
API and MCP server, Rust identity service, registration, site redesign174 >
Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed)175 <Avatar name={user.username} size={24} />
176 <ChevronDown size={14} className="text-faint" />
177 </DropdownMenuTrigger>
178 <DropdownMenuContent align="end" className="w-56">
179 <DropdownMenuLabel>
180 Signed in as{" "}
181 <span className="font-mono font-medium text-fg">
182 {user.username}
183 </span>
184 </DropdownMenuLabel>
185 <DropdownMenuSeparator />
Workspaces own repositories186 {(user.workspaces ?? []).map((membership) => (
187 <DropdownMenuItem asChild key={membership.slug}>
188 <Link to={`/${membership.slug}`}>
Agents as a team: lifecycle, merge queue, billing and a new shell189 <Avatar name={membership.slug} size={16} square />
Workspaces own repositories190 {membership.slug}
191 </Link>
192 </DropdownMenuItem>
193 ))}
Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed)194 <DropdownMenuItem asChild>
Workspaces own repositories195 <Link to="/workspaces/new">
196 <Plus />
197 New workspace
Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed)198 </Link>
199 </DropdownMenuItem>
Workspaces own repositories200 <DropdownMenuSeparator />
Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed)201 <DropdownMenuItem asChild>
202 <Link to="/">
203 <LayoutDashboard />
204 Mission control
205 </Link>
206 </DropdownMenuItem>
207 <DropdownMenuItem asChild>
208 <Link to="/new">
209 <Plus />
210 New repository
211 </Link>
212 </DropdownMenuItem>
213 <DropdownMenuSeparator />
214 <DropdownMenuItem asChild>
215 <Link to="/settings">
216 <Settings />
217 Settings
218 </Link>
219 </DropdownMenuItem>
220 <DropdownMenuItem asChild>
Docs as their own app; shared theme package221 <Link to="https://docs.g1t.sh/quickstart/">
Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed)222 <BookOpen />
223 Documentation
224 </Link>
225 </DropdownMenuItem>
226 <DropdownMenuSeparator />
Acceptance checks in sandboxes, line comments and review verdicts227 {/* Submitted from here: the menu closes on select, and a button
228 that has left the page cannot submit a form. */}
229 <DropdownMenuItem
230 onSelect={() => submit(null, { method: "post", action: "/logout" })}
231 >
232 <LogOut />
233 Sign out
Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed)234 </DropdownMenuItem>
235 </DropdownMenuContent>
236 </DropdownMenu>
API and MCP server, Rust identity service, registration, site redesign237 </>
238 ) : (
239 <>
240 <HeaderLink to="/login">Sign in</HeaderLink>
241 <ButtonLink to="/register">Sign up</ButtonLink>
242 </>
243 )}
244 </div>
245 </div>
246 </header>
247 );
248}
249
250const FOOTER_LINKS: { title: string; links: [string, string][] }[] = [
251 {
252 title: "Product",
253 links: [
docs.g1t.sh, generated OpenAPI with an interactive reference, full footer254 ["Explore repositories", "/explore"],
Docs as their own app; shared theme package255 ["g1t agents", "https://docs.g1t.sh/guides/g1t-agents/"],
256 ["Bring your own agent", "https://docs.g1t.sh/guides/bring-your-own-agent/"],
Polish: phones, copy boxes, the plan page, the landing page, a real glide257 ["Integrations", "https://docs.g1t.sh/guides/integrations/"],
258 ["Model providers", "https://docs.g1t.sh/guides/models/"],
API and MCP server, Rust identity service, registration, site redesign259 ["Sign up", "/register"],
260 ],
261 },
262 {
docs.g1t.sh, generated OpenAPI with an interactive reference, full footer263 title: "Developers",
API and MCP server, Rust identity service, registration, site redesign264 links: [
Docs as their own app; shared theme package265 ["Quickstart", "https://docs.g1t.sh/quickstart/"],
Polish: phones, copy boxes, the plan page, the landing page, a real glide266 ["How g1t works", "https://docs.g1t.sh/concepts/overview/"],
Docs as their own app; shared theme package267 ["API reference", "https://docs.g1t.sh/api/reference/"],
docs.g1t.sh, generated OpenAPI with an interactive reference, full footer268 ["OpenAPI", "https://api.g1t.sh/openapi.json"],
269 ["llms.txt", "/llms.txt"],
API and MCP server, Rust identity service, registration, site redesign270 ],
271 },
docs.g1t.sh, generated OpenAPI with an interactive reference, full footer272 {
273 title: "Project",
274 links: [
275 ["Source on g1t", "/syntaqx/g1t"],
276 ["Source on GitHub", "https://github.com/syntaqx/g1t"],
277 ["MIT license", "/syntaqx/g1t/blob/main/LICENSE"],
278 ],
279 },
API and MCP server, Rust identity service, registration, site redesign280];
281
282function Footer() {
283 return (
284 <footer className="mt-24 border-t border-line">
285 <div className="mx-auto flex max-w-6xl flex-wrap gap-x-20 gap-y-8 px-4 py-12">
286 <div className="grow">
287 <Logo />
288 <p className="mt-3 max-w-xs text-sm text-muted">
289 A git forge for agents. Open source under the MIT license, built on
290 Cloudflare Workers and Artifacts.
291 </p>
292 </div>
293 {FOOTER_LINKS.map((group) => (
294 <div key={group.title}>
295 <p className="text-sm font-medium">{group.title}</p>
296 <ul className="mt-3 space-y-2 text-sm text-muted">
297 {group.links.map(([label, to]) => (
298 <li key={to}>
docs.g1t.sh, generated OpenAPI with an interactive reference, full footer299 {/* Plain links: some targets are files or other hosts. */}
300 <a href={to} className="hover:text-fg">
API and MCP server, Rust identity service, registration, site redesign301 {label}
docs.g1t.sh, generated OpenAPI with an interactive reference, full footer302 </a>
API and MCP server, Rust identity service, registration, site redesign303 </li>
304 ))}
305 </ul>
306 </div>
307 ))}
308 </div>
docs.g1t.sh, generated OpenAPI with an interactive reference, full footer309 <div className="border-t border-line">
310 <p className="mx-auto max-w-6xl px-4 py-5 text-xs text-faint">
311 g1t is open source software, built on Cloudflare Workers and
312 Artifacts.
313 </p>
314 </div>
API and MCP server, Rust identity service, registration, site redesign315 </footer>
316 );
317}
318
Initial g1t: services, event bus, intents and attempts319export function Layout({ children }: { children: React.ReactNode }) {
320 // Undefined when the root loader itself failed.
Agents as a team: lifecycle, merge queue, billing and a new shell321 const root = useRouteLoaderData<typeof loader>("root");
322 const user = root?.user;
323 const banner = user && !user.verified && (
324 <Form
325 method="post"
326 action="/verify"
327 className="flex flex-wrap items-center justify-center gap-x-3 gap-y-1 border-b border-warn/30 bg-warn/10 px-4 py-2 text-sm"
328 >
329 <span>
330 Confirm your email address to create repositories and push. We
331 sent you a link.
332 </span>
333 <button type="submit" className="font-medium underline underline-offset-4">
334 Send it again
335 </button>
336 </Form>
337 );
Initial g1t: services, event bus, intents and attempts338 return (
339 <html lang="en">
340 <head>
341 <meta charSet="utf-8" />
342 <meta name="viewport" content="width=device-width, initial-scale=1" />
Dark gray base with lavender as an accent, and a live outcome view for plans343 <meta name="theme-color" content="#0f0f11" />
Initial g1t: services, event bus, intents and attempts344 <Meta />
345 <Links />
346 </head>
API and MCP server, Rust identity service, registration, site redesign347 <body className="flex min-h-screen flex-col">
Agents as a team: lifecycle, merge queue, billing and a new shell348 {user && root?.shell ? (
349 <AppShell user={user} shell={root.shell} banner={banner}>
350 {children}
351 </AppShell>
352 ) : (
353 <>
354 <Progress />
355 <Header user={user} />
356 {banner}
357 <div className="grow">{children}</div>
358 <Footer />
359 </>
Email verification, password reset, and Git for AI scale positioning360 )}
Initial g1t: services, event bus, intents and attempts361 <ScrollRestoration />
362 <Scripts />
363 </body>
364 </html>
365 );
366}
367
368export default function App() {
369 return <Outlet />;
370}
371
372export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
API and MCP server, Rust identity service, registration, site redesign373 let title = "Something went wrong";
374 let details = "An unexpected error occurred. Try again in a moment.";
Initial g1t: services, event bus, intents and attempts375 let stack: string | undefined;
376
377 if (isRouteErrorResponse(error)) {
API and MCP server, Rust identity service, registration, site redesign378 if (error.status === 404) {
379 title = "Page not found";
380 details = "There is nothing at this address, or you do not have access to it.";
381 } else if (typeof error.data === "string" && error.data) {
382 details = error.data;
383 }
384 } else if (import.meta.env.DEV && error instanceof Error) {
Initial g1t: services, event bus, intents and attempts385 details = error.message;
386 stack = error.stack;
387 }
388
389 return (
API and MCP server, Rust identity service, registration, site redesign390 <main className="mx-auto max-w-xl px-4 py-32 text-center">
391 <h1 className="text-2xl font-semibold tracking-tight">{title}</h1>
392 <p className="mt-3 text-muted">{details}</p>
393 <div className="mt-8">
394 <ButtonLink to="/" variant="quiet">
395 Back to home
396 </ButtonLink>
397 </div>
Initial g1t: services, event bus, intents and attempts398 {stack && (
API and MCP server, Rust identity service, registration, site redesign399 <pre className="mt-8 overflow-x-auto rounded-lg border border-line p-4 text-left text-xs">
Initial g1t: services, event bus, intents and attempts400 <code>{stack}</code>
401 </pre>
402 )}
403 </main>
404 );
405}