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.

407 linesCodeBlameRaw
1import { ArrowRight, Bot, Box, ShieldCheck, Users } from "lucide-react";
2import { type ReactNode, Suspense } from "react";
3import { Await, Link, data } from "react-router";
4
5import { COST_PROVIDERS, type CostProvider, type User, hasCodeAccess, isCostProvider } from "@g1t/contracts";
6
7import type { Route } from "./+types/workspace-overview";
8
9import { UsageCard } from "../../components/usage-card";
10import { billing, identity } from "../../lib/services.server";
11import { loadOnboarding } from "../../lib/onboarding.server";
12import { OnboardingOnPage } from "../../components/onboarding";
13import { getViewer, roleIn } from "../../lib/session.server";
14import { usageFor } from "../../lib/workspace-usage.server";
15import { workspaceProjects } from "../../lib/workspace-projects.server";
16import { page } from "../../lib/meta";
17import { Avatar } from "../../components/ui/avatar";
18import { Badge } from "../../components/ui/badge";
19import { Card } from "../../components/ui/card";
20import { Skeleton } from "../../components/ui/skeleton";
21import { Boundary, Unavailable } from "../../components/boundary";
22import { Rhythm } from "../../components/rhythm";
23import { PulseSkeleton, PulseStrip } from "../../components/signals";
24import { SpendFlow } from "../../components/spend-flow";
25import { isFailed, part } from "../../lib/partial";
26import { loadRepos } from "../../lib/home.server";
27import { dailySignal, dayList, dollars, harnessWords, namesWords, newGround, newHabits, providerQuarter, quarterSpend, signalsRange, rhythm, silos, spendFlow, spoken, spreading, waitingRows } from "../../lib/signals";
28import { type SignalData, loadGroups, loadSignalData } from "../../lib/signals.server";
29
30export function meta({ params, ...args }: Route.MetaArgs) {
31 return page(args, { title: `Workspace · ${params.owner} · g1t` });
32}
33
34/** Most members listed before "and N more". */
35const MAX_FACES = 10;
36/** Entries each quiet change lists. */
37const QUIET_ROWS = 4;
38
39/**
40 * The workspace's ground truth, from what its work says (lib/signals.ts),
41 * for members who see Code: the past week, the quarter's agent spend
42 * threaded to the work it produced, what is moving and what is waiting
43 * team by team, and quiet changes in who works where. Streamed, each part
44 * on its own. Then the workspace at a glance, for every member: who is in
45 * it, its projects, and the month's usage against its plan. Each part is
46 * left out when its service does not answer.
47 */
48export async function loader({ params, context, request }: Route.LoaderArgs) {
49 const viewer = getViewer(context);
50 const slug = params.owner.toLowerCase();
51 const role = roleIn(viewer, slug);
52 if (!role) throw data(null, { status: 404 });
53 // Getting started, for an owner, as on Home: streamed beside the rest.
54 const setupAsked = new URL(request.url).searchParams.has("setup");
55 const onboarding = loadOnboarding(viewer, slug, !setupAsked).catch(() => null);
56 const membership = viewer?.workspaces?.find((m) => m.slug === slug) ?? null;
57 const ground = viewer && hasCodeAccess(membership) ? loadGround(viewer, slug, Date.now()).catch(() => null) : null;
58 const [members, usage, projects] = await Promise.all([
59 part(identity.listMembers(slug, viewer), "The member list"),
60 usageFor(slug, viewer),
61 workspaceProjects(slug, viewer).catch(() => null),
62 ]);
63 return {
64 slug,
65 role,
66 onboarding,
67 setupAsked,
68 members: isFailed(members) ? members : members.ok ? members.value : null,
69 usage,
70 projects: projects?.ok ? projects.value.length : null,
71 ground,
72 };
73}
74
75/** Everything the work says, shaped for the page; null when the work service did not answer. */
76async function loadGround(viewer: User, slug: string, now: number) {
77 const owned = await loadRepos(viewer, slug).catch(() => null);
78 if (!owned) return null;
79 const [found, groups, providers] = await Promise.all([
80 loadSignalData(viewer, slug, now, owned).catch(() => null),
81 loadGroups(viewer, slug, owned).catch(() => null),
82 // What the connected providers say was spent: beside the rest, never in the way of it.
83 billing
84 .providerCosts(slug, viewer, signalsRange(now).quarter)
85 .then((result) => (result.ok ? result.value : null))
86 .catch(() => null),
87 ]);
88 return found ? { ...shapeGround(found, groups, now), providers: providerQuarter(providers, found.range.quarter) } : null;
89}
90
91function shapeGround(found: SignalData, groups: Awaited<ReturnType<typeof loadGroups>>, now: number) {
92 const name = (id: string) => found.repos[id]?.name ?? "a project";
93 const path = (id: string) => (found.repos[id] ? `/${found.repos[id]!.namespace}/${found.repos[id]!.name}` : null);
94 const quarter = quarterSpend({ repos: found.repos, signals: found.signals, quarterUsage: found.quarterUsage, quarter: found.range.quarter });
95 // Practices catching on in each team (else across the workspace), the newest first.
96 const scopes = groups?.by === "team" ? groups.groups.map((group) => ({ key: group.key, label: group.label, only: new Set(group.repoIds) as ReadonlySet<string> | undefined })) : [{ key: "all", label: "the workspace", only: undefined }];
97 const spreads = scopes.flatMap((scope) => spreading(found.signals.harnesses, now, { only: scope.only }).map((spread) => ({ scope, spread })));
98 return {
99 tiles: dailySignal(found).tiles,
100 complete: found.complete,
101 capped: found.signals.pullsCapped,
102 flow: spendFlow({ slug: found.slug, repos: found.repos, signals: found.signals, quarterUsage: found.quarterUsage, quarter: found.range.quarter }),
103 sized: (quarter?.total ?? 0) > 0 ? ("spend" as const) : ("pulls" as const),
104 quarterSpend: quarter?.total ?? null,
105 sessionSpend: quarter?.sessions ?? 0,
106 rhythm: groups ? { by: groups.by, rows: rhythm(found.signals.days, dayList(found.range.until, found.range.days), groups.groups) } : null,
107 waiting: waitingRows(found.signals.waiting, found.repos).map((pull) => ({ ...pull, age: spoken(Math.max(0, (now - Date.parse(pull.createdAt)) / 1000)) })),
108 silos: silos(found.signals.authors, now)
109 .slice(0, QUIET_ROWS)
110 .map((silo) => ({
111 key: silo.repoId,
112 to: path(silo.repoId),
113 where: name(silo.repoId),
114 line: `${silo.name} merged ${silo.theirs} of its ${silo.recent} changes in 90 days`,
115 more: silo.joining.length > 0 ? `${silo.joining.map((who) => who.name).join(", ")} started this month` : "No one else has started there",
116 })),
117 newGround: newGround(found.signals.authors, now)
118 .slice(0, QUIET_ROWS)
119 .map((row) => ({ key: `${row.ownerId}:${row.repoId}`, to: path(row.repoId), where: name(row.repoId), line: `${row.name} merged a first change here`, more: `${row.elsewhere} merges elsewhere first` })),
120 spreading: spreads.slice(0, QUIET_ROWS).map(({ scope, spread }) => ({
121 key: `${scope.key}:${spread.harness}`,
122 to: null,
123 where: `${harnessWords(spread.harness)} in ${scope.label}`,
124 line: `${namesWords(spread.recent.map((person) => person.name))} started using it this month, after ${spread.first.name}`,
125 more: `${spread.people} people use it now`,
126 })),
127 habits: newHabits(found.signals.pulls, now)
128 .slice(0, QUIET_ROWS)
129 .map((row) => ({ key: row.ownerId, to: path(row.repoId), where: name(row.repoId), line: `${row.name} merged a first agent-made change`, more: `after ${row.byHand} by hand` })),
130 };
131}
132
133type Ground = ReturnType<typeof shapeGround> & { providers: ReturnType<typeof providerQuarter> };
134
135function Tile({ icon, label, value, to, action }: { icon: ReactNode; label: string; value: string; to: string; action: string }) {
136 return (
137 <Link to={to} className="group rounded-xl border border-line bg-surface p-4 transition-colors hover:border-line-strong">
138 <p className="flex items-center gap-1.5 text-xs text-muted">
139 {icon}
140 {label}
141 </p>
142 <p className="mt-1.5 text-2xl font-semibold tracking-tight tabular-nums">{value}</p>
143 <p className="mt-0.5 flex items-center gap-1 text-xs text-faint group-hover:text-muted">
144 {action} <ArrowRight size={11} />
145 </p>
146 </Link>
147 );
148}
149
150export default function WorkspaceOverview({ loaderData }: Route.ComponentProps) {
151 const { slug, role, members, usage, projects } = loaderData;
152 return (
153 <div className="space-y-8">
154 <OnboardingOnPage slug={slug} view={loaderData.onboarding} asked={loaderData.setupAsked} />
155 {loaderData.ground && (
156 <Suspense fallback={<GroundSkeleton />}>
157 <Await resolve={loaderData.ground}>{(ground) => (ground ? <GroundTruth slug={slug} ground={ground} /> : <Unavailable what="What the work says" />)}</Await>
158 </Suspense>
159 )}
160 <div className="grid grid-cols-1 gap-3 sm:grid-cols-2">
161 <Tile icon={<Users size={12} />} label="Members" value={members && !isFailed(members) ? String(members.length) : "—"} to={role === "owner" ? `/${slug}/-/members` : `/${slug}/-/people`} action={role === "owner" ? "Manage people" : "See everyone"} />
162 <Tile icon={<Box size={12} />} label="Projects" value={projects == null ? "—" : String(projects)} to={`/${slug}/-/projects`} action="Open Code" />
163 </div>
164 <div className="grid gap-6 lg:grid-cols-[minmax(0,1fr)_22rem]">
165 <div className="space-y-6">
166 {usage ? (
167 <UsageCard slug={slug} glance={usage} owner={role === "owner"} />
168 ) : (
169 <Card asChild className="p-5">
170 <section>
171 <h2 className="font-medium">Usage</h2>
172 <p className="mt-1.5 text-sm text-muted">This month&apos;s usage isn&apos;t available right now.</p>
173 <Link to={`/${slug}/-/usage`} className="mt-3 inline-flex items-center gap-1 text-sm text-accent hover:underline">
174 Open Usage <ArrowRight size={13} />
175 </Link>
176 </section>
177 </Card>
178 )}
179 <Card asChild className="p-5">
180 <section>
181 <h2 className="flex items-center gap-2 font-medium">
182 <ShieldCheck size={15} className="text-faint" />
183 Policies
184 </h2>
185 <p className="mt-1.5 text-sm text-muted">
186 How long runs may take, the rules every repository follows, and how the workspace&apos;s security is set up.
187 </p>
188 <div className="mt-3 flex flex-wrap gap-x-4 gap-y-1 text-sm">
189 <Link to={`/${slug}/-/guardrails`} className="text-accent hover:underline">
190 Guardrails
191 </Link>
192 <Link to={`/${slug}/-/rules`} className="text-accent hover:underline">
193 Rules
194 </Link>
195 <Link to={`/${slug}/-/security/settings`} className="text-accent hover:underline">
196 Security settings
197 </Link>
198 <Link to={`/${slug}/-/audit`} className="text-accent hover:underline">
199 Audit log
200 </Link>
201 </div>
202 </section>
203 </Card>
204 </div>
205 <Card asChild className="self-start p-5">
206 <section>
207 <div className="flex items-center justify-between">
208 <h2 className="font-medium">Members</h2>
209 <Link to={role === "owner" ? `/${slug}/-/members` : `/${slug}/-/people`} className="text-xs text-muted hover:text-fg">
210 {role === "owner" ? "Manage" : "See all"}
211 </Link>
212 </div>
213 {isFailed(members) ? (
214 <div className="mt-3">
215 <Unavailable what={members.what} compact />
216 </div>
217 ) : members ? (
218 <>
219 <ul className="mt-3 space-y-2">
220 {members.slice(0, MAX_FACES).map((member) => (
221 <li key={member.username} className="flex items-center gap-2.5 text-sm">
222 <Avatar name={member.username} image={member.avatar} size={24} />
223 <Link to={`/u/${member.username}`} className="min-w-0 grow truncate hover:text-accent">
224 {member.name?.trim() || member.username}
225 {member.name?.trim() && <span className="ml-1.5 font-mono text-xs text-faint">{member.username}</span>}
226 </Link>
227 {member.role === "owner" && <Badge size="md">owner</Badge>}
228 </li>
229 ))}
230 </ul>
231 {members.length > MAX_FACES && <p className="mt-2 text-xs text-faint">and {members.length - MAX_FACES} more</p>}
232 </>
233 ) : (
234 <p className="mt-3 text-sm text-muted">The member list isn&apos;t available right now.</p>
235 )}
236 </section>
237 </Card>
238 </div>
239 </div>
240 );
241}
242
243function GroundSkeleton() {
244 return (
245 <div className="space-y-6">
246 <PulseSkeleton />
247 <Skeleton className="h-112 w-full rounded-2xl" />
248 </div>
249 );
250}
251
252/** A part of the ground truth: a mono eyebrow, a sentence for a heading, and what it shows. */
253function Section({ id, eyebrow, title, hint, children }: { id: string; eyebrow: string; title: string; hint?: ReactNode; children: ReactNode }) {
254 return (
255 <section id={id} aria-labelledby={`${id}-title`} className="scroll-mt-6 rounded-2xl border border-line bg-surface px-5 py-6 md:px-8 md:py-7">
256 <p className="font-mono text-[0.6875rem] tracking-[0.16em] text-accent uppercase">{eyebrow}</p>
257 <h2 id={`${id}-title`} className="mt-2 font-display text-2xl leading-tight tracking-tight text-fg">
258 {title}
259 </h2>
260 {hint && <p className="mt-1.5 max-w-3xl text-sm text-muted">{hint}</p>}
261 <div className="mt-6">{children}</div>
262 </section>
263 );
264}
265
266type QuietRow = Ground["silos"][number];
267
268function QuietList({ title, hint, rows, empty }: { title: string; hint: string; rows: QuietRow[]; empty: string }) {
269 return (
270 <div className="min-w-0">
271 <h3 className="text-sm font-semibold text-fg">{title}</h3>
272 <p className="mt-0.5 text-xs text-muted">{hint}</p>
273 {rows.length === 0 ? (
274 <p className="mt-3 text-sm text-faint">{empty}</p>
275 ) : (
276 <ul className="mt-3 space-y-3">
277 {rows.map((row) => (
278 <li key={row.key} className="text-sm">
279 {row.to ? (
280 <Link to={row.to} className="font-medium text-fg hover:text-accent">
281 {row.where}
282 </Link>
283 ) : (
284 <span className="font-medium text-fg">{row.where}</span>
285 )}
286 <p className="text-fg-soft">{row.line}</p>
287 <p className="font-mono text-[0.6875rem] text-faint">{row.more}</p>
288 </li>
289 ))}
290 </ul>
291 )}
292 </div>
293 );
294}
295
296function GroundTruth({ slug, ground }: { slug: string; ground: Ground }) {
297 return (
298 <div className="space-y-6">
299 <Boundary what="The past week">
300 <PulseStrip tiles={ground.tiles} />
301 </Boundary>
302 {!ground.complete && <p className="text-xs text-faint">Some projects didn&apos;t answer, so what follows leaves them out.</p>}
303 <Section
304 id="spend"
305 eyebrow="Spend, threaded to the work"
306 title={ground.quarterSpend ? `${dollars(ground.quarterSpend)} of agent spend this quarter, and what it went into` : "This quarter's work, and how much of it agents did"}
307 hint={
308 ground.sized === "spend"
309 ? `Each milestone, its work items, their change set in each project and its pull requests, sized by what agents cost on them${ground.sessionSpend > 0 ? ` (g1t's metered usage, and ${dollars(ground.sessionSpend)} of harness sessions estimated at list price)` : ""} and shaded by how much was an agent's. Choose a box to open what is under it.`
310 : "Usage isn't known for this quarter, so each box is sized by its pull requests and shaded by how many were an agent's. Choose a box to open what is under it."
311 }
312 >
313 <ProvidersLine slug={slug} providers={ground.providers} threaded={ground.quarterSpend} />
314 <Boundary what="Spend, threaded to the work">
315 <SpendFlow flow={ground.flow} sized={ground.sized} />
316 </Boundary>
317 {ground.capped && <p className="mt-3 text-xs text-faint">There were more pull requests this quarter than this reads, so the newest are shown.</p>}
318 </Section>
319 <Section
320 id="rhythm"
321 eyebrow="What's moving and what's waiting"
322 title={ground.rhythm?.by === "project" ? "Each project's last two weeks" : "Each team's last two weeks"}
323 hint="Pull requests and agent sessions above the line; reviews, comments and requests for changes below it. Each row is drawn to its own scale: point at a day for its numbers."
324 >
325 <div className="grid gap-8 xl:grid-cols-[minmax(0,1fr)_18rem]">
326 <Boundary what="What's moving">{ground.rhythm ? <Rhythm rows={ground.rhythm.rows} by={ground.rhythm.by} /> : <Unavailable what="The teams" />}</Boundary>
327 <div className="min-w-0">
328 <h3 className="text-sm font-semibold text-fg">Waiting on a first review</h3>
329 <p className="mt-0.5 text-xs text-muted">Open, and no one has reviewed them yet: the oldest first.</p>
330 {ground.waiting.length === 0 ? (
331 <p className="mt-3 text-sm text-faint">Nothing is waiting for a first review.</p>
332 ) : (
333 <ul className="mt-3 divide-y divide-line">
334 {ground.waiting.map((pull) => (
335 <li key={`${pull.repoId}#${pull.number}`} className="py-2.5 text-sm">
336 <Link to={pull.to} className="flex items-start gap-2 hover:text-accent">
337 <span className="shrink-0 pt-px font-mono text-xs text-muted">#{pull.number}</span>
338 <span className="min-w-0 grow">
339 <span className="line-clamp-2 font-medium text-fg">{pull.title}</span>
340 <span className="font-mono text-[0.6875rem] text-faint">
341 {pull.repo.name} · open {pull.age}
342 {pull.blocks.length > 0 && ` · holds up ${pull.blocks.length}`}
343 </span>
344 </span>
345 {pull.agent && <Bot size={13} className="mt-0.5 shrink-0 text-accent" aria-label="An agent's" />}
346 </Link>
347 </li>
348 ))}
349 </ul>
350 )}
351 <Link to={`/${slug}/-/overview?tab=needs#work`} className="mt-3 inline-flex items-center gap-1 text-xs text-muted hover:text-fg">
352 The review queue <ArrowRight size={11} />
353 </Link>
354 </div>
355 </div>
356 </Section>
357 <Section
358 id="quiet"
359 eyebrow="Quiet changes"
360 title="Who works where, and what is spreading"
361 hint="What no roll-up shows: knowledge resting with one person, people moving into new ground, and new ways of working taking hold. Each is a place to look, not a verdict."
362 >
363 <div className="grid gap-8 md:grid-cols-2 xl:grid-cols-4">
364 <QuietList title="Knowledge silos" hint="Projects where one person has done most of the last 90 days' work" rows={ground.silos} empty="No project rests on one person right now." />
365 <QuietList title="New ground" hint="People who merged to a project for the first time in the last two weeks" rows={ground.newGround} empty="No one has moved into a new project in the last two weeks." />
366 <QuietList title="Spreading" hint="A harness more people took up this month, after someone started with it" rows={ground.spreading} empty="No harness has caught on in a team this month." />
367 <QuietList title="New habits" hint="People whose first agent-made change merged in the last two weeks" rows={ground.habits} empty="No one new started merging agents' work in the last two weeks." />
368 </div>
369 </Section>
370 </div>
371 );
372}
373
374const providerName = (provider: string) => (isCostProvider(provider) ? COST_PROVIDERS[provider as CostProvider].label : provider);
375
376/**
377 * What the connected providers reported for the quarter, beside what g1t
378 * threads to the work: their bill holds everything the organization ran,
379 * so it is the larger figure, never added to the other.
380 */
381function ProvidersLine({ slug, providers, threaded }: { slug: string; providers: Ground["providers"]; threaded: number | null }) {
382 if (!providers) {
383 return (
384 <p className="-mt-2 mb-5 text-sm text-muted">
385 <Link to={`/${slug}/-/provider-costs`} className="text-accent hover:underline">
386 Connect a provider&apos;s cost report
387 </Link>{" "}
388 to see everything your organization spent with Anthropic or OpenAI, not only what g1t can tie to the work.
389 </p>
390 );
391 }
392 return (
393 <div className="-mt-2 mb-5 flex flex-wrap items-baseline gap-x-5 gap-y-1 rounded-xl border border-line bg-bg px-4 py-3 text-sm">
394 <span className="text-fg">
395 <span className="font-semibold">{dollars(providers.total)}</span> reported by your providers this quarter
396 </span>
397 <span className="font-mono text-xs text-muted">{providers.providers.map((row) => `${providerName(row.provider)} ${dollars(row.micros)}`).join(" · ")}</span>
398 {threaded != null && threaded > 0 && providers.total > 0 && (
399 <span className="text-xs text-muted">{Math.min(100, Math.round((threaded / providers.total) * 100))}% of it is threaded to the work below</span>
400 )}
401 {!providers.complete && <span className="text-xs text-faint">Some of the quarter isn&apos;t read yet</span>}
402 <Link to={`/${slug}/-/provider-costs`} className="ml-auto text-xs text-muted hover:text-fg">
403 Provider costs
404 </Link>
405 </div>
406 );
407}