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
238 linesCodeBlameRaw
1import { Package, Plus } from "lucide-react";
2import { Outlet, data, redirect, useLocation, useNavigation } from "react-router";
3
4import type { Route } from "./+types/layout";
5import { page } from "../../lib/meta";
6import { ButtonLink } from "../../components/ui";
7import { Avatar } from "../../components/ui/avatar";
8import { Badge } from "../../components/ui/badge";
9import { WelcomeBanner } from "../../components/welcome";
10import { clearWelcome, welcomes } from "../../lib/invites";
11import { notFound } from "../../lib/not-found.server";
12import { redirectIfRenamed } from "../../lib/renamed.server";
13import { rememberWorkspace } from "../../lib/workspace-choice";
14import { workspacePage, workspaceRedirect } from "../../lib/workspace-nav";
15import { WorkspacePageSkeleton } from "../../components/workspace-skeletons";
16import { identity } from "../../lib/services.server";
17import { getViewer, roleIn } from "../../lib/session.server";
18
19export function meta({ loaderData, params, ...args }: Route.MetaArgs) {
20 return page(args, { title: `${loaderData?.workspace.name ?? params.owner} · g1t` });
21}
22
23export async function loader({ params, context, request }: Route.LoaderArgs) {
24 const url = new URL(request.url);
25 // `?tab=projects` and the like, from the tabs this page once had: that
26 // page's own address.
27 const moved = url.search ? workspaceRedirect(url.pathname, url.search) : null;
28 if (moved) throw redirect(moved);
29 const viewer = getViewer(context);
30 const workspace = await identity.getWorkspace(params.owner);
31 if (!workspace) {
32 // A workspace's old name, after a rename: its pages are at the new one.
33 await redirectIfRenamed(request, params.owner);
34 throw notFound("workspace");
35 }
36 const role = roleIn(viewer, workspace.slug);
37 // Opening one of your workspaces makes it the one you are in.
38 if (!role) return { workspace, role, welcome: false };
39 const secure = new URL(request.url).protocol === "https:";
40 const headers = new Headers({ "Set-Cookie": rememberWorkspace(workspace.slug, secure) });
41 // Just joined with an invite: welcomed once (routes/invite.tsx).
42 const welcome = welcomes(request.headers.get("cookie"), workspace.slug);
43 if (welcome) headers.append("Set-Cookie", clearWelcome(secure));
44 return data({ workspace, role, welcome }, { headers });
45}
46
47/** A workspace's own pages, each with its title and what it is for. */
48const PAGES: Record<string, { title: string; about: string }> = {
49 workspace: {
50 title: "Workspace",
51 about: "Who is in it, what it is on, and what it has spent this month. Everything about the workspace itself is in this sidebar.",
52 },
53 settings: { title: "General", about: "The workspace's name, icon, address and description, two-factor authentication, where its data lives, and deleting it." },
54 people: {
55 title: "People",
56 about: "Everyone in the workspace, in one directory: who they are, what they own, the teams they're on and who's around.",
57 },
58 members: {
59 title: "Members",
60 about: "Who is in the workspace and their roles. Owners invite people, manage members and owners, and see the outside collaborators; what members may do is under Permissions.",
61 },
62 "members/invitations": {
63 title: "Invitations",
64 about: "Every invitation to join the workspace: who it is for, who sent it, the role, and where it stands. Send one again, revoke it, or copy its link.",
65 },
66 permissions: {
67 title: "Permissions",
68 about: "Who may do what in the workspace, part by part: repositories, teams, chat, artifacts, deployments and packages. Owners only.",
69 },
70 projects: {
71 title: "Projects",
72 about: "Everything the workspace builds and runs. Search, filter and sort them, and pin the ones you use most to keep them in your sidebar.",
73 },
74 teams: {
75 title: "Teams",
76 about: "People with a lead, a channel and roles on repositories. Everyone on a team knows who their teammates are.",
77 },
78 repositories: {
79 title: "Repositories",
80 about: "Every repository in the workspace: who can see it, whether it is archived, and the ones deleted recently.",
81 },
82 tokens: {
83 title: "Access tokens",
84 about: "Tokens that belong to the workspace, not a person: for CI, integrations and coding agents that work for the whole team. Each has the permissions an owner gives it, in all of the workspace's repositories or the ones chosen.",
85 },
86 "personal-access-tokens": {
87 title: "Personal access tokens",
88 about: "Which of your members' own tokens may reach the workspace and for how long, the tokens made for it that wait for an owner's approval, and every token that can reach it.",
89 },
90 packages: {
91 title: "Packages",
92 about: "What the workspace publishes and installs, beside its code: container images, npm, Composer, Go, Cargo, Maven, NuGet and RubyGems, with the same members, roles and tokens.",
93 },
94 usage: { title: "Usage", about: "What the workspace used and what it cost, by product, project and day." },
95 billing: { title: "Billing and plans", about: "The g1t plan, the trial, your spend limit, prepaying, and every charge." },
96 memory: {
97 title: "Workspace memory",
98 about: "What holds across all of the workspace's projects, beside each project's own memory. Coding agents read it with the MCP server's recall.",
99 },
100 audit: {
101 title: "Audit log",
102 about: "Every change people, tokens and g1t's own runs made: by whom, on whose behalf, to what, and whether it was allowed.",
103 },
104 guardrails: {
105 title: "Guardrails",
106 about: "What every project's sandboxes may reach, and how long their runs may take. Each project can override these under its settings.",
107 },
108 webhooks: {
109 title: "Webhooks",
110 about: "Every repository's events, sent to your own addresses as they happen. A repository can also have its own, under its settings.",
111 },
112 secrets: {
113 title: "Secrets and variables",
114 about: "Shared with every repository, or the ones you link: read by workflows, deployments, or both. A repository's own row of the same key wins.",
115 },
116 security: {
117 title: "Security",
118 about: "Open alerts in every project: secrets found in pushes and history, and vulnerable dependencies. Each project's Security page has the details and the security update g1t opened for each.",
119 },
120 integrations: {
121 title: "Integrations",
122 about:
123 "The tools your team works with, connected once for everyone in the workspace. Secrets are sealed when saved, and never shown again.",
124 },
125};
126
127/** A workspace page's heading: its title and what it is for. */
128function PageHeader({ title, about }: { title: string; about: string }) {
129 return (
130 <header className="mb-8 border-b border-line pb-6">
131 <h1 className="text-2xl font-semibold tracking-tight">{title}</h1>
132 <p className="mt-1.5 text-sm text-muted">{about}</p>
133 </header>
134 );
135}
136
137/** Artifacts' pages that are lists, not one artifact. */
138const ARTIFACT_LISTS = new Set(["new", "templates", "trash", "stale", "spaces"]);
139
140/** Whether the page (its path after `/-/`, in parts) is one artifact or a project's doc file. */
141function isArtifactPage(parts: string[]): boolean {
142 if (parts[0] !== "artifacts" || parts.length < 2) return false;
143 if (parts[1] === "repo") return true;
144 return !ARTIFACT_LISTS.has(parts[1]!) && parts.length === 2;
145}
146
147export default function WorkspaceLayout({ loaderData }: Route.ComponentProps) {
148 const { workspace, role, welcome } = loaderData;
149 const { pathname } = useLocation();
150 const going = useNavigation().location;
151 // The workspace's own page is its overview. Its other pages are found
152 // from the sidebar, which lights the one you are on, and the top bar's
153 // trail leads back here; each has a heading of its own.
154 const here = workspacePage(pathname, workspace.slug);
155 // On the way to another of its pages: that page's heading and shape
156 // until it arrives.
157 const next = going && going.pathname !== pathname ? workspacePage(going.pathname, workspace.slug) : null;
158 const shown = next ?? here;
159 const parts = (pathname.split("/-/")[1] ?? "").split("/").filter(Boolean);
160 // Chat fills the page edge to edge: its conversation, thread and details
161 // are columns of their own (components/chat/channel.tsx).
162 if (parts[0] === "chat" && !next) return <Outlet />;
163 // Code's Overview lays itself out, as Mission control did.
164 if (parts[0] === "overview" && parts.length === 1 && !next) return <Outlet />;
165 // An open artifact, or a project's doc, fills the panel: its header runs edge to edge right under
166 // the top bar (components/folios/shell.tsx), and its page sets its own width.
167 if (isArtifactPage(parts) && !next) {
168 return (
169 <div className="px-4 pb-10 sm:px-6 lg:px-8">
170 <Outlet />
171 </div>
172 );
173 }
174 if (shown !== "overview") {
175 // A page of its own under another's address (Invitations under Members) has its own heading.
176 const whole = parts.join("/");
177 const key = shown ?? (PAGES[whole] ? whole : (parts[0] ?? ""));
178 const heading = PAGES[key];
179 // A page within one (a single package or team) and a page that is
180 // coming (Insights) have headings of their own.
181 const titled = heading && (shown != null || parts.length === 1 || key === whole);
182 return (
183 <div className="mx-auto max-w-5xl px-4 py-10 sm:px-8">
184 {titled && (
185 <PageHeader title={heading.title} about={heading.about} />
186 )}
187 {next ? <WorkspacePageSkeleton page={next} /> : <Outlet />}
188 </div>
189 );
190 }
191 return (
192 <>
193 {/* The workspace's own header band, above its overview. */}
194 <div className="border-b border-line bg-surface/60">
195 <div className="mx-auto max-w-6xl px-4 py-8">
196 {welcome && (
197 <div className="mb-6">
198 <WelcomeBanner title={`You're in ${workspace.name}`}>
199 You joined as a {role}. Its projects, issues and people are all here.
200 </WelcomeBanner>
201 </div>
202 )}
203 <div className="flex flex-wrap items-center gap-4">
204 <Avatar name={workspace.slug} image={workspace.avatar} size={52} square />
205 <div className="min-w-0 grow">
206 <div className="flex flex-wrap items-center gap-2.5">
207 <h1 className="truncate text-2xl font-semibold tracking-tight">
208 {workspace.name}
209 </h1>
210 {role && <Badge size="md">{role}</Badge>}
211 </div>
212 <p className="font-mono text-sm text-muted">g1t.sh/{workspace.slug}</p>
213 </div>
214 {role ? (
215 <ButtonLink to={`/new?workspace=${workspace.slug}`}>
216 <Plus size={15} />
217 New project
218 </ButtonLink>
219 ) : (
220 // A visitor's sidebar is not this workspace's: its packages
221 // are a link here, as its projects are below.
222 <ButtonLink to={`/${workspace.slug}/-/packages`} variant="outline" prefetch="intent">
223 <Package size={15} />
224 Packages
225 </ButtonLink>
226 )}
227 </div>
228 {workspace.description && (
229 <p className="mt-4 max-w-2xl text-sm text-muted">{workspace.description}</p>
230 )}
231 </div>
232 </div>
233 <div className="mx-auto max-w-6xl px-4 py-8">
234 {next ? <WorkspacePageSkeleton page="overview" /> : <Outlet />}
235 </div>
236 </>
237 );
238}