Skip to content
2,168 linesCodeBlameRaw
1import { Activity, BarChart3, Building2, MessagesSquare, Bell, BookMarked, BookOpen, Bookmark, Blocks, Bot, Box, Check, ChevronDown, ChevronLeft, ChevronRight, CircleDot, GripVertical, CircleUserRound, Code2, Coins, Compass, CreditCard, Fingerprint, GanttChart, Gauge, GitBranch, GitPullRequest, Globe, History, KanbanSquare, Keyboard, KeyRound, Layers, LayoutDashboard, LayoutGrid, LifeBuoy, ListTree, Lock, LogOut, Mail, Network, Package, PanelLeft, PlayCircle, Plug, Plus, Rocket, Search, ServerCog, Settings, Shapes, ShieldCheck, Scale, Smile, Sparkles, Store, House, Ticket, TrendingUp, UserPlus, UserRoundKey, Users, UsersRound, Webhook, X, ArrowLeftRight } from "lucide-react";
2import { Fragment, type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from "react";
3import { Link, NavLink, useFetcher, useLocation, useNavigation, useRouteLoaderData, useSubmit } from "react-router";
4
5import { type Abilities, type ChatSidebarEntry, type InboxCounts, type WorkspaceAgent, type Membership, type Spike, type User, hasCodeAccess, mayCreateTeams, shownUsername } from "@g1t/contracts";
6
7import { InMain } from "./landmark";
8import { CommandPalette, type PaletteCommand, PaletteKey, usePaletteShortcut } from "./command-palette";
9import { NotificationsBell } from "./inbox";
10import { SpendPill } from "./spend";
11import { PinButton } from "./pin-button";
12import { Hint } from "./ui/hint";
13import { Sheet, SheetContent, SheetTitle } from "./ui/sheet";
14import { StatusDot, useSiteStatus } from "./footer";
15import { Logo, MarkGlyph } from "./logo";
16import { Avatar, SoonPill } from "./ui";
17import { Skeleton } from "./ui/skeleton";
18import { Button } from "./ui/button";
19import { Separator } from "./ui/separator";
20import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator } from "./ui/breadcrumb";
21import {
22 DropdownMenu,
23 DropdownMenuContent,
24 DropdownMenuGroup,
25 DropdownMenuItem,
26 DropdownMenuLabel,
27 DropdownMenuSeparator,
28 DropdownMenuTrigger,
29} from "./ui/dropdown-menu";
30import { type RoadmapItem, roadmapIn, roadmapItem } from "../lib/roadmap";
31import { type ModeKey, SETTINGS_PAGES, homePagePath, modeOf } from "../lib/workspace-nav";
32import { AgentsSidebar } from "./agents-mode";
33import { ChatSidebar } from "./chat/sidebar";
34import { FoliosSidebar } from "./folios/sidebar";
35import { Dock, ShortcutsDialog, WorkspaceSwitcher, sidebarKeyLabel } from "./dock";
36import { BottomBar, isConversation, useVisualViewport } from "./mobile";
37import { useChatSidebar } from "./chat/actions";
38import { unreadTotals } from "../lib/chat";
39import { SETTINGS_CAPABILITY, type ViewerAccess, seesSettings } from "../lib/access";
40import { projectPages } from "../lib/chrome";
41import { ACCOUNT_SETTINGS, type AccountSettingsPage, FIRST_SETTINGS_PAGE, accountSettingsPage } from "../lib/account-settings";
42import { type PinnableApp, sidebarCookie } from "../lib/apps";
43import { REASON_FILTERS, inboxReason, inboxView } from "../lib/inbox";
44import { GithubMark } from "./github";
45import { useInviteOnly } from "../lib/registration";
46import { STATUS_URL, statusTitle } from "../lib/status";
47import { type ShortcutProject, movedPin, recentWith } from "../lib/pins";
48import type { AccountMenuData } from "../routes/settings-menu-json";
49import { useLiveBadges } from "../lib/notify-client";
50import { OwnPresenceDot, OwnPresenceItems, StatusDialog } from "./presence";
51import { THEME_COMMANDS, ThemeMenuSwitch } from "./theme-switch";
52
53/**
54 * What the sidebar needs, worked out by the root loader. For a visitor who
55 * is not signed in there is no workspace, no projects and no usage: only
56 * the project being looked at, if they can see it.
57 */
58export type ShellData = {
59 /** The workspace the sidebar is about: the one being looked at, or their first. */
60 workspace: Membership | null;
61 /** All its projects, by name, for the palette: `name` is the slug in their address. */
62 repos: ShortcutProject[];
63 /** The person's pinned projects in it, in their order (lib/pins.ts). */
64 pinned?: ShortcutProject[];
65 /** What they opened there last, latest first, leaving out the pinned. */
66 recent?: ShortcutProject[];
67 /** Repositories shared with them in workspaces they do not belong to. */
68 shared?: { namespace: string; name: string; isPrivate: boolean }[];
69 /** The project being looked at, if any, whoever owns it. */
70 repo: {
71 namespace: string;
72 name: string;
73 member: boolean;
74 issues: number;
75 pulls: number;
76 } | null;
77 /** Where the workspace stands against its usage limit, if billing is on. */
78 limit: {
79 exposureMicros: number;
80 ceilingMicros: number | null;
81 state: "ok" | "warning" | "stopped";
82 comped: boolean;
83 } | null;
84 /** Whether g1t charges nothing for now, while it is being built out. */
85 free?: boolean;
86 /** What its agents have cost since the start of the month. */
87 /** This month's usage: charged, or at cost while g1t is free. */
88 monthUsageMicros: number | null;
89 /** Whether new compute is paused (a spend spike or a hold), and whether the viewer can answer it. */
90 compute?: { paused: string | null; spike: Spike | null; owner: boolean } | null;
91 /** What is unread in their notifications, for the dock and the bell. Absent for a visitor. */
92 inbox?: InboxCounts | null;
93 /**
94 * Chat, for the dock's badge: what is unread, and the
95 * starred and latest conversations. Null when chat did not answer in time.
96 */
97 chat?: { unread: number; mentions: number; starred?: ChatSidebarEntry[]; recent?: ChatSidebarEntry[] } | null;
98 /** The workspace's agents, g1t first, for the Agents sidebar; null when not known. */
99 agents?: ShellAgent[] | null;
100 /** The apps this person pinned to their dock in the workspace (lib/apps.ts). */
101 pins?: PinnableApp[];
102};
103
104/** An agent as the shell lists it. */
105export type ShellAgent = Pick<
106 WorkspaceAgent,
107 "id" | "handle" | "display_name" | "avatar" | "avatar_seed" | "role" | "status" | "title" | "builtin"
108> & {
109 scope?: WorkspaceAgent["scope"];
110 /** The visible teams it is on (team memberships); absent when they couldn't be read. */
111 teams?: { slug: string; name: string }[];
112};
113
114function SidebarLink({
115 to,
116 icon,
117 end,
118 count,
119 also,
120 drill,
121 current: lit,
122 children,
123}: {
124 to: string;
125 icon: ReactNode;
126 end?: boolean;
127 count?: number;
128 /** Other path prefixes under which this link is the current one. */
129 also?: string | string[];
130 /** It opens a list of its own: a chevron says so, always or on hover. */
131 drill?: boolean | "hover";
132 /** Whether it is the current row, when the list works that out itself. */
133 current?: boolean;
134 children: ReactNode;
135}) {
136 const { pathname } = useLocation();
137 const navigation = useNavigation();
138 // NavLink's own pending state compares paths only, so a list whose rows
139 // differ by query (Notifications' views and reasons) would light every
140 // row while one loads. Where the list says which row is current, a row
141 // is pending only when the page on its way is that row's, query and all.
142 const loading = navigation.location;
143 const pendingHere = loading != null && `${loading.pathname}${loading.search}` === to;
144 return (
145 <NavLink
146 to={to}
147 end={end}
148 prefetch="intent"
149 className={({ isActive, isPending }) => {
150 const current =
151 lit ??
152 (isActive || [also ?? []].flat().some((prefix) => pathname === prefix || pathname.startsWith(prefix + "/")));
153 const pending = lit === undefined ? isPending : pendingHere;
154 return `group flex h-8 items-center gap-2.5 rounded-md px-2 text-[0.8125rem] transition-colors ${
155 current
156 ? "bg-raised font-medium text-fg"
157 : pending
158 ? "bg-raised/60 text-fg"
159 : "text-muted hover:bg-raised/60 hover:text-fg"
160 }`;
161 }}
162 >
163 <span className="shrink-0 text-faint group-hover:text-muted">{icon}</span>
164 <span className="min-w-0 grow truncate">{children}</span>
165 {count != null && count > 0 && (
166 <span className="rounded bg-line px-1.5 text-[0.6875rem] tabular-nums text-muted">
167 {count}
168 </span>
169 )}
170 {drill && (
171 <ChevronRight
172 size={14}
173 aria-hidden="true"
174 className={`-mr-0.5 shrink-0 text-faint transition-opacity ${drill === "hover" ? "opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100" : ""}`}
175 />
176 )}
177 </NavLink>
178 );
179}
180
181/**
182 * Something a project will have, shown where it will live so people can
183 * see where g1t is going. Not a link: nothing is behind it yet.
184 */
185function SidebarSoon({ icon, children, about }: { icon: ReactNode; children: ReactNode; about: string }) {
186 return (
187 <Hint label={about} side="right">
188 <div aria-disabled="true" className="flex h-8 cursor-default items-center gap-2.5 rounded-md px-2 text-[0.8125rem] text-faint">
189 <span className="shrink-0 opacity-70">{icon}</span>
190 <span className="grow truncate">{children}</span>
191 <span className="sr-only">{about}</span>
192 <SoonPill />
193 </div>
194 </Hint>
195 );
196}
197
198/**
199 * A page that is coming, as a link to its roadmap page: faint, with Soon,
200 * and marked current on any of its section's Soon pages.
201 */
202function SidebarSoonLink({
203 to,
204 also,
205 icon,
206 about,
207 current: lit,
208 children,
209}: {
210 to: string;
211 also?: string[];
212 icon: ReactNode;
213 about: string;
214 /** Whether it is the current row, when the list works that out itself. */
215 current?: boolean;
216 children: ReactNode;
217}) {
218 const { pathname } = useLocation();
219 return (
220 // The hint wraps a plain box: Radix's asChild merges className as a
221 // string, which would break NavLink's className function.
222 <Hint label={about} side="right">
223 <div>
224 <NavLink
225 to={to}
226 prefetch="intent"
227 className={({ isActive }) => {
228 const current = lit ?? (isActive || (also ?? []).some((prefix) => pathname === prefix || pathname.startsWith(prefix + "/")));
229 return `group flex h-8 items-center gap-2.5 rounded-md px-2 text-[0.8125rem] transition-colors ${
230 current ? "bg-raised font-medium text-fg" : "text-faint hover:bg-raised/60 hover:text-muted"
231 }`;
232 }}
233 >
234 <span className="shrink-0 opacity-80">{icon}</span>
235 <span className="min-w-0 grow truncate">{children}</span>
236 <SoonPill />
237 </NavLink>
238 </div>
239 </Hint>
240 );
241}
242
243/** Icons for what spans projects. */
244const WORKSPACE_ICONS: Record<string, ReactNode> = {
245 board: <KanbanSquare size={15} />,
246 roadmap: <GanttChart size={15} />,
247 teams: <UsersRound size={15} />,
248 packages: <Package size={15} />,
249 fleet: <Bot size={15} />,
250};
251
252/** The Soon pages of a section, as paths, so its link is current on them. */
253function soonPaths(base: string, section: RoadmapItem["section"]): string[] {
254 return roadmapIn(section).map((item) => `${base}/soon/${item.key}`);
255}
256
257function SidebarGroup({
258 title,
259 action,
260 className = "",
261 children,
262}: {
263 title: string;
264 action?: ReactNode;
265 className?: string;
266 children: ReactNode;
267}) {
268 return (
269 <section className={className}>
270 <div className="mb-1 flex h-6 items-center justify-between px-2">
271 <h2 className="text-xs font-medium text-faint">{title}</h2>
272 {action}
273 </div>
274 <div className="space-y-px">{children}</div>
275 </section>
276 );
277}
278
279/** What a workspace is called where people read it: its display name, else its slug. */
280function displayName(membership: Membership): string {
281 return membership.name?.trim() || membership.slug;
282}
283
284/**
285 * The fine print, as one quiet row at the foot of the account menu and the
286 * visitor's panel: each link a full-height target, left-aligned. In the
287 * menu each is a menu item, so the arrow keys reach it.
288 */
289const LEGAL_LINKS: [string, string][] = [
290 ["Policies", "/policies"],
291 ["Privacy", "/policies/privacy"],
292 ["Security", "/security"],
293];
294const LEGAL_LINK = "flex h-7 items-center rounded px-1.5 text-xs text-faint outline-none transition-colors";
295
296function MenuLegalRow() {
297 return (
298 <div role="group" aria-label="Legal" className="flex items-center gap-0.5 px-0.5 pt-0.5">
299 {LEGAL_LINKS.map(([label, to], index) => (
300 <span key={to} className="flex items-center gap-0.5">
301 {index > 0 && (
302 <span aria-hidden="true" className="text-[0.625rem] text-line-strong">
303 ·
304 </span>
305 )}
306 <DropdownMenuItem asChild className={`${LEGAL_LINK} py-0 data-highlighted:bg-line data-highlighted:text-fg`}>
307 <Link to={to}>{label}</Link>
308 </DropdownMenuItem>
309 </span>
310 ))}
311 </div>
312 );
313}
314
315/** Status's row: the live dot and two or three words, fetched when the menu opens. */
316function StatusSummary({ open }: { open: boolean }) {
317 const status = useSiteStatus(open);
318 const words = statusTitle(status);
319 return (
320 <span className="ml-auto flex min-w-0 items-center gap-1.5 pl-2 text-xs text-faint">
321 {/* The words say it; the dot's own words for screen readers would repeat them. */}
322 <span aria-hidden="true" className="flex">
323 <StatusDot state={status?.overall.state ?? null} />
324 </span>
325 {words ? <span className="truncate">{words}</span> : <Skeleton className="h-3 w-20" />}
326 </span>
327 );
328}
329
330/** A menu row: an icon, words, and whatever sits at its end. */
331const MENU_ROW = "h-9 gap-2.5 px-2.5 text-[0.8125rem]";
332
333/**
334 * Your account, at the foot of the dock (or in the header, before you have
335 * a workspace): who you are and your status, your profile and settings,
336 * and help: the documentation, support, status and the keyboard's
337 * shortcuts; then signing out and the fine print.
338 */
339function AccountMenu({ user, side = "right" }: { user: User; side?: "right" | "bottom" }) {
340 const submit = useSubmit();
341 const [open, setOpen] = useState(false);
342 const [keys, setKeys] = useState(false);
343 // Your status's dialog: outside the menu, so the menu closes behind it.
344 const [editing, setEditing] = useState(false);
345 // Name, primary address and invites left: asked for once, as soon as the
346 // pointer or focus reaches the button, so they are there when it opens.
347 const details = useFetcher<AccountMenuData | null>({ key: "account-menu" });
348 const prefetch = () => {
349 if (details.state === "idle" && details.data === undefined) details.load("/settings/menu.json");
350 };
351 useEffect(() => {
352 if (open) prefetch();
353 // eslint-disable-next-line react-hooks/exhaustive-deps
354 }, [open]);
355 const me = details.data ?? null;
356 // Still on its way: shapes where the words will be, the same size.
357 const loading = details.data === undefined && details.state !== "idle";
358 // While anyone can sign up, listed once the data says there are invites to look back on.
359 const invitesListed = useInviteOnly() || me?.invites_page === true;
360 const profile = `/u/${user.username}`;
361 return (
362 <>
363 <DropdownMenu open={open} onOpenChange={setOpen}>
364 {/* The avatar alone, with a dot that says how others see you (components/presence.tsx). */}
365 <DropdownMenuTrigger
366 aria-label={`Account menu for ${shownUsername(user)}`}
367 onPointerEnter={prefetch}
368 onFocus={prefetch}
369 className="relative flex rounded-full outline-none transition-transform hover:scale-[1.04] focus-visible:ring-2 focus-visible:ring-accent data-[state=open]:ring-2 data-[state=open]:ring-line-strong"
370 >
371 <Avatar name={user.username} image={user.avatar} size={side === "right" ? 32 : 28} />
372 <OwnPresenceDot ring={side === "right" ? "var(--color-dock)" : "var(--color-bg)"} className="absolute -right-0.5 -bottom-0.5" />
373 </DropdownMenuTrigger>
374 <DropdownMenuContent align="end" side={side} sideOffset={side === "right" ? 14 : 6} collisionPadding={8} className="w-[17.5rem] p-1.5">
375 {/* Who is signed in, and a way to their profile. */}
376 <DropdownMenuItem asChild className="gap-3 px-2 py-2">
377 <Link to={profile} aria-label={`${me?.name ?? shownUsername(user)} (@${shownUsername(user)}), your profile`}>
378 <Avatar name={user.username} image={user.avatar} size={36} />
379 <span className="flex min-w-0 grow flex-col leading-tight" aria-busy={loading}>
380 {loading ? (
381 <Skeleton className="my-[0.1875rem] h-3.5 w-28" />
382 ) : (
383 <span className="truncate text-sm font-medium text-fg">{me?.name ?? shownUsername(user)}</span>
384 )}
385 <span className="truncate font-mono text-xs text-muted">@{shownUsername(user)}</span>
386 {loading ? (
387 <Skeleton className="mt-1 h-3 w-40" />
388 ) : (
389 me?.email && <span className="mt-0.5 truncate text-xs text-faint">{me.email}</span>
390 )}
391 </span>
392 </Link>
393 </DropdownMenuItem>
394 <DropdownMenuSeparator className="my-1.5" />
395 {/* Your status, away, and pausing notifications. */}
396 <DropdownMenuGroup>
397 <OwnPresenceItems className="min-h-9 py-1.5 text-[0.8125rem]" onEdit={() => setEditing(true)} />
398 </DropdownMenuGroup>
399 <DropdownMenuSeparator className="my-1.5" />
400 <DropdownMenuGroup>
401 <DropdownMenuItem asChild className={MENU_ROW}>
402 <Link to={profile}>
403 <CircleUserRound />
404 Your profile
405 </Link>
406 </DropdownMenuItem>
407 <DropdownMenuItem asChild className={MENU_ROW}>
408 <Link to={FIRST_SETTINGS_PAGE}>
409 <Settings />
410 Your settings
411 </Link>
412 </DropdownMenuItem>
413 {invitesListed && (
414 <DropdownMenuItem asChild className={MENU_ROW}>
415 <Link to="/settings/invites">
416 <Ticket />
417 {ACCOUNT_SETTINGS.invites.title}
418 {loading && <Skeleton className="ml-auto h-4 w-12 rounded-full" />}
419 {me?.invites_left != null && (
420 <span className="ml-auto rounded-full bg-line px-1.5 text-[0.6875rem] tabular-nums text-muted">
421 {me.invites_left} left
422 </span>
423 )}
424 </Link>
425 </DropdownMenuItem>
426 )}
427 </DropdownMenuGroup>
428 <DropdownMenuSeparator className="my-1.5" />
429 {/* Auto, Light or Dark, switched in place (lib/theme.ts). */}
430 <ThemeMenuSwitch />
431 <DropdownMenuSeparator className="my-1.5" />
432 <DropdownMenuGroup>
433 <DropdownMenuItem asChild className={MENU_ROW}>
434 <a href="https://docs.g1t.sh/">
435 <BookOpen />
436 Documentation
437 </a>
438 </DropdownMenuItem>
439 <DropdownMenuItem asChild className={MENU_ROW}>
440 <Link to="/support">
441 <LifeBuoy />
442 Support
443 </Link>
444 </DropdownMenuItem>
445 <DropdownMenuItem asChild className={MENU_ROW}>
446 <a href={STATUS_URL}>
447 <Activity />
448 Status
449 <StatusSummary open={open} />
450 </a>
451 </DropdownMenuItem>
452 <DropdownMenuItem className={MENU_ROW} onSelect={() => setKeys(true)}>
453 <Keyboard />
454 Keyboard shortcuts
455 <PaletteKey className="ml-auto font-sans text-xs text-faint" />
456 </DropdownMenuItem>
457 </DropdownMenuGroup>
458 <DropdownMenuSeparator className="my-1.5" />
459 {/* Submitted from here: the menu closes on select, and a button
460 that has left the page cannot submit a form. */}
461 <DropdownMenuItem className={MENU_ROW} onSelect={() => submit(null, { method: "post", action: "/logout" })}>
462 <LogOut />
463 Sign out
464 </DropdownMenuItem>
465 <DropdownMenuSeparator className="my-1.5" />
466 <MenuLegalRow />
467 </DropdownMenuContent>
468 </DropdownMenu>
469 <StatusDialog open={editing} onOpenChange={setEditing} />
470 <ShortcutsDialog open={keys} onOpenChange={setKeys} />
471 </>
472 );
473}
474
475/**
476 * A workspace's settings pages, which the sidebar drills into: how it is
477 * set up and connected (guardrails, secrets, integrations,
478 * webhooks), what it pays, its repositories, tokens and record. The main
479 * list keeps the places work happens and who belongs; every member can
480 * still open these.
481 */
482const SETTINGS_PAGE =
483 new RegExp(`^/([^/]+)/-/(${SETTINGS_PAGES.join("|")})(/|$)`);
484/** A project's settings pages, which the project's menu drills into. */
485const REPO_SETTINGS_PAGE = /^\/([^/]+)\/([^/-][^/]*)\/settings(\/|$)/;
486
487/**
488 * The sidebar's lists are a stack, the way a phone pushes a screen: one
489 * drilled into slides in from the right over the full width, while the one
490 * it covers drifts a quarter of the way left and fades, both on one long
491 * ease-out, the fade quicker than the move so the two never blur together.
492 * Going back reverses it.
493 */
494const LAYER =
495 "absolute inset-0 [transition:translate_380ms_cubic-bezier(0.32,0.72,0,1),opacity_220ms_ease-out] will-change-[translate,opacity] motion-reduce:transition-none";
496/** One list, filling its layer. */
497const PANEL = "h-full overflow-y-auto px-2 pb-4";
498
499/** One list in the stack: what it is, and its rows. */
500type Level = { key: string; node: ReactNode };
501
502/** True once the page has hydrated, so what the server drew never animates in. */
503function useHydrated(): boolean {
504 const [hydrated, setHydrated] = useState(false);
505 useEffect(() => setHydrated(true), []);
506 return hydrated;
507}
508
509/**
510 * Drilling in and out of the sidebar's lists. `trail` is the way from the
511 * main list to the one shown, worked out from the address, so a link
512 * straight to a settings page opens the sidebar already drilled in, and
513 * leaving it comes back out. Lists deeper than the one shown stay in
514 * place, off to the right, so going back slides them away rather than
515 * dropping them. Moving to a list at the same depth (a workspace's settings
516 * to a project) fades the new one in where it is.
517 */
518function Drill({ trail }: { trail: Level[] }) {
519 const depth = trail.length - 1;
520 const hydrated = useHydrated();
521 const stack = useRef<Level[]>(trail);
522 const before = stack.current;
523 const within = trail.every((level, index) => before[index]?.key === level.key);
524 stack.current = within ? [...trail, ...before.slice(trail.length)] : trail;
525 const levels = stack.current;
526 // What was showing last time, to tell drilling in from moving across.
527 const shown = useRef({ depth, keys: levels.map((level) => level.key) });
528 useEffect(() => {
529 shown.current = { depth, keys: levels.map((level) => level.key) };
530 });
531 return (
532 <div className="relative min-h-0 grow overflow-hidden">
533 {levels.map((level, index) => {
534 const current = index === depth;
535 const place =
536 index < depth
537 ? "pointer-events-none -translate-x-1/4 opacity-0"
538 : current
539 ? "translate-x-0 opacity-100"
540 : "pointer-events-none translate-x-full opacity-0";
541 // A list that was not there before arrives: from the right when
542 // drilling in, in place when moving across.
543 const arriving = hydrated && current && !shown.current.keys.includes(level.key);
544 const enter = arriving
545 ? depth > shown.current.depth
546 ? "starting:translate-x-full starting:opacity-0"
547 : "starting:opacity-0"
548 : "";
549 return (
550 <div key={level.key} className={`${LAYER} ${place} ${enter}`} inert={!current} aria-hidden={!current || undefined}>
551 {level.node}
552 </div>
553 );
554 })}
555 </div>
556 );
557}
558
559/**
560 * The row at the top of a list drilled into: the list's name, which goes
561 * back out, and what it belongs to, faint at the end.
562 */
563function BackRow({ to, label, context }: { to: string; label: ReactNode; context?: ReactNode }) {
564 return (
565 <Link
566 to={to}
567 prefetch="intent"
568 className="group mt-3 flex h-8 items-center gap-1.5 rounded-md pr-2 pl-1 text-[0.8125rem] font-medium text-fg transition-colors hover:bg-raised/60"
569 >
570 <ChevronLeft size={16} className="shrink-0 text-faint transition-transform group-hover:-translate-x-0.5 group-hover:text-muted" />
571 <span className="min-w-0 shrink-0 truncate">{label}</span>
572 {context && (
573 <span className="ml-auto min-w-0 truncate pl-2 font-mono text-[0.6875rem] font-normal text-faint">{context}</span>
574 )}
575 </Link>
576 );
577}
578
579/** A thin rule between groups of a list. */
580function Rule() {
581 return <div role="separator" className="mx-2 my-2.5 h-px bg-line" />;
582}
583
584/** A quiet heading inside a group: Pinned, Recent. */
585function SidebarSubhead({ children }: { children: ReactNode }) {
586 return <h3 className="px-2 pt-1.5 pb-0.5 text-[0.6875rem] font-medium tracking-wide text-faint">{children}</h3>;
587}
588
589/**
590 * The workspace's projects as the sidebar keeps them, however many there
591 * are: the person's pins in their order, what they opened last, and the
592 * way to all of them. Pins move by dragging, or with Alt and the arrow
593 * keys; the projects service keeps the order.
594 */
595function SidebarProjects({ slug, shell, current }: { slug: string; shell: ShellData; current: boolean }) {
596 const reorder = useFetcher({ key: `pins:${slug}` });
597 const saved = shell.pinned ?? [];
598 // While a new order is on its way, it shows as made.
599 const asked = reorder.formData?.get("intent") === "reorder" ? reorder.formData.getAll("slug").map(String) : null;
600 const pinned = asked
601 ? asked.map((name) => saved.find((project) => project.name === name)).filter((project): project is ShortcutProject => project != null)
602 : saved;
603 const active = shell.repo ? { namespace: shell.repo.namespace, name: shell.repo.name, isPrivate: false } : null;
604 const recent = recentWith(shell.recent ?? [], pinned, active, slug);
605 const [dragging, setDragging] = useState<number | null>(null);
606 const move = (from: number, by: number) => {
607 const next = movedPin(pinned, from, by);
608 if (!next) return;
609 const form = new FormData();
610 form.set("intent", "reorder");
611 for (const project of next) form.append("slug", project.name);
612 reorder.submit(form, { method: "post", action: `/${slug}/-/pins` });
613 };
614 // Each row pins or unpins in place: the pin shows on hover or focus, and
615 // stays shown on a pinned row's hover so it reads as "unpin".
616 const row = (project: ShortcutProject, isPinned: boolean) => (
617 <div className="group/row relative">
618 <SidebarLink to={`/${project.namespace}/${project.name}`} icon={project.isPrivate ? <Lock size={15} /> : <Box size={15} />} drill="hover">
619 <span className="block truncate pr-6">{project.title ?? project.name}</span>
620 </SidebarLink>
621 <PinButton
622 workspace={slug}
623 slug={project.name}
624 name={project.title ?? project.name}
625 pinned={isPinned}
626 small
627 className="absolute top-1/2 right-6 -translate-y-1/2 opacity-0 transition-opacity group-hover/row:opacity-100 focus-within:opacity-100 [@media(hover:none)]:opacity-100"
628 />
629 </div>
630 );
631 return (
632 <SidebarGroup
633 title="Projects"
634 action={
635 <Link to="/new" aria-label="New project" className="rounded p-0.5 text-faint hover:bg-raised hover:text-fg">
636 <Plus size={13} />
637 </Link>
638 }
639 >
640 {/* Only there once something is pinned: each row below has its own pin. */}
641 {pinned.length > 0 && (
642 <>
643 <SidebarSubhead>Pinned</SidebarSubhead>
644 <ul aria-label="Pinned projects" className="space-y-px">
645 {pinned.map((project, index) => (
646 <li
647 key={project.name}
648 draggable={pinned.length > 1}
649 onDragStart={(event) => {
650 setDragging(index);
651 event.dataTransfer.effectAllowed = "move";
652 }}
653 onDragOver={(event) => {
654 if (dragging != null) event.preventDefault();
655 }}
656 onDrop={(event) => {
657 event.preventDefault();
658 if (dragging != null && dragging !== index) move(dragging, index - dragging);
659 setDragging(null);
660 }}
661 onDragEnd={() => setDragging(null)}
662 onKeyDown={(event) => {
663 if (!event.altKey || (event.key !== "ArrowUp" && event.key !== "ArrowDown")) return;
664 event.preventDefault();
665 move(index, event.key === "ArrowUp" ? -1 : 1);
666 }}
667 className={`group/pin relative ${dragging === index ? "opacity-50" : ""}`}
668 >
669 {row(project, true)}
670 {pinned.length > 1 && (
671 <Hint label="Drag, or Alt and an arrow key, to reorder" side="right">
672 <span className="absolute top-1/2 -left-1.5 -translate-y-1/2 cursor-grab text-faint opacity-0 transition-opacity group-hover/pin:opacity-100">
673 <GripVertical size={12} aria-hidden="true" />
674 </span>
675 </Hint>
676 )}
677 </li>
678 ))}
679 </ul>
680 </>
681 )}
682 {recent.length > 0 && (
683 <>
684 <SidebarSubhead>Recent</SidebarSubhead>
685 {recent.map((project) => (
686 <div key={`${project.namespace}/${project.name}`}>{row(project, false)}</div>
687 ))}
688 </>
689 )}
690 <div className="pt-1">
691 <SidebarLink to={`/${slug}/-/projects`} icon={<LayoutGrid size={15} />} count={shell.repos.length} current={current}>
692 All projects
693 </SidebarLink>
694 </div>
695 </SidebarGroup>
696 );
697}
698
699/** Insights, coming: the workspace's own page says what it will be. */
700const INSIGHTS = roadmapItem("insights");
701
702/**
703 * What the repository menu needs. Known from the address before the page's
704 * data arrives, so the menu is right from the first frame; the counts fill
705 * in once it does.
706 */
707type MenuRepo = {
708 namespace: string;
709 name: string;
710 member: boolean;
711 /** Whether they see its settings; from the repository's page once it loads. */
712 settings?: boolean;
713 /** What they may do there, once the repository's page loads. */
714 can?: Abilities;
715 issues?: number;
716 pulls?: number;
717};
718
719function sameRepo(a: { namespace: string; name: string } | null, b: { namespace: string; name: string } | null) {
720 return (
721 a != null &&
722 b != null &&
723 a.namespace.toLowerCase() === b.namespace.toLowerCase() &&
724 a.name.toLowerCase() === b.name.toLowerCase()
725 );
726}
727
728/**
729 * A project's own list, drilled into while you are in it: everything about
730 * the project, running and its code, and nothing else, with the way back
731 * out to all of them.
732 */
733function RepoMenu({
734 repo,
735 isPrivate,
736 back,
737}: {
738 repo: MenuRepo;
739 isPrivate: boolean;
740 /** Where the way back leads: the workspace's projects, mission control, or Explore. */
741 back: { to: string; label: string };
742}) {
743 const base = `/${repo.namespace}/${repo.name}`;
744 // What a member sees, and what everyone who can see the project does.
745 const shows = new Set(projectPages(repo.member, repo.can));
746 return (
747 <nav aria-label={`${repo.namespace}/${repo.name}`} className={PANEL}>
748 <BackRow to={back.to} label={back.label} />
749 <Hint label="Overview" side="right">
750 <div>
751 <NavLink
752 to={base}
753 end
754 prefetch="intent"
755 className={({ isActive }) =>
756 `mt-2 flex items-center gap-2 rounded-md px-2 py-1.5 transition-colors ${isActive ? "bg-raised" : "hover:bg-raised/60"}`
757 }
758 >
759 <span className="flex size-6 shrink-0 items-center justify-center rounded-md bg-raised text-muted ring-1 ring-line">
760 {isPrivate ? <Lock size={13} /> : <Box size={13} />}
761 </span>
762 <span className="min-w-0 truncate font-mono text-[0.8125rem]">
763 <span className="text-faint">{repo.namespace}/</span>
764 <span className="font-semibold text-fg">{repo.name}</span>
765 </span>
766 </NavLink>
767 </div>
768 </Hint>
769 {/* A project's pages, in the order people use them. A page with more
770 than one view shows them as tabs across its top. */}
771 <Rule />
772 <div className="space-y-px">
773 <SidebarLink to={`${base}/code`} also={[`${base}/tree`, `${base}/blob`, `${base}/commits`, `${base}/commit`, `${base}/branches`, `${base}/tags`, `${base}/compare`, ...soonPaths(base, "Code")]} icon={<Code2 size={15} />}>
774 Code
775 </SidebarLink>
776 <SidebarLink to={`${base}/issues`} also={[`${base}/plans`, `${base}/milestones`, `${base}/labels`, ...soonPaths(base, "Issues")]} icon={<CircleDot size={15} />} count={repo.issues}>
777 Issues
778 </SidebarLink>
779 <SidebarLink to={`${base}/pulls`} also={[`${base}/pull`, `${base}/queue`]} icon={<GitPullRequest size={15} />} count={repo.pulls}>
780 Pull requests
781 </SidebarLink>
782 <SidebarLink to={`${base}/agents`} also={[`${base}/sessions`, `${base}/memory`, ...soonPaths(base, "Agents")]} icon={<Bot size={15} />}>
783 Agents
784 </SidebarLink>
785 <SidebarLink to={`${base}/actions`} icon={<PlayCircle size={15} />}>
786 Workflows
787 </SidebarLink>
788 </div>
789 <Rule />
790 <div className="space-y-px">
791 {shows.has("deployments") ? (
792 <SidebarLink to={`${base}/deployments`} also={soonPaths(base, "Deployments")} icon={<Rocket size={15} />}>
793 Deployments
794 </SidebarLink>
795 ) : null}
796 <SidebarSoonLink to={`${base}/soon/logs`} also={soonPaths(base, "Observability")} icon={<Activity size={15} />} about="Logs, errors, uptime and analytics of the project's deployed apps.">
797 Observability
798 </SidebarSoonLink>
799 {shows.has("security") ? (
800 <SidebarLink to={`${base}/security`} also={soonPaths(base, "Security")} icon={<ShieldCheck size={15} />}>
801 Security
802 </SidebarLink>
803 ) : null}
804 <SidebarLink
805 to={`${base}/contributors`}
806 also={[`${base}/activity`, `${base}/stargazers`, ...soonPaths(base, "Insights")]}
807 icon={<BarChart3 size={15} />}
808 >
809 Insights
810 </SidebarLink>
811 </div>
812 {(repo.settings ?? shows.has("settings")) && (
813 <>
814 <Rule />
815 <SidebarLink to={`${base}/settings`} icon={<Settings size={15} />} drill>
816 Settings
817 </SidebarLink>
818 </>
819 )}
820 </nav>
821 );
822}
823
824/**
825 * A project's settings, drilled into from its list: what is about running
826 * it, then its agents, then its code and who can reach it. The way back
827 * leads to the project.
828 */
829function RepoSettingsMenu({ repo }: { repo: MenuRepo }) {
830 const base = `/${repo.namespace}/${repo.name}`;
831 // Each page shows to the roles that can use it, once the role is known.
832 const shows = (page: string) => !repo.can || repo.can[SETTINGS_CAPABILITY[page] ?? "administer"];
833 const running = shows("deployments");
834 const agents = shows("agents") || shows("guardrails");
835 return (
836 <nav aria-label={`${repo.namespace}/${repo.name} settings`} className={PANEL}>
837 <BackRow to={base} label="Settings" context={`${repo.namespace}/${repo.name}`} />
838 {shows("") && (
839 <div className="mt-2 space-y-px">
840 <SidebarLink to={`${base}/settings`} end icon={<Settings size={15} />}>
841 General
842 </SidebarLink>
843 </div>
844 )}
845 {running && (
846 <>
847 {shows("") && <Rule />}
848 <div className={shows("") ? "space-y-px" : "mt-2 space-y-px"}>
849 <SidebarLink to={`${base}/settings/deployments`} icon={<Rocket size={15} />}>
850 Deployments
851 </SidebarLink>
852 <SidebarLink to={`${base}/settings/domains`} icon={<Globe size={15} />}>
853 Domains
854 </SidebarLink>
855 </div>
856 </>
857 )}
858 {agents && (
859 <>
860 <Rule />
861 <div className="space-y-px">
862 {shows("agents") && (
863 <SidebarLink to={`${base}/settings/agents`} icon={<Bot size={15} />}>
864 Agents
865 </SidebarLink>
866 )}
867 {shows("guardrails") && (
868 <SidebarLink to={`${base}/settings/guardrails`} icon={<ShieldCheck size={15} />}>
869 Guardrails
870 </SidebarLink>
871 )}
872 </div>
873 </>
874 )}
875 <Rule />
876 <div className="space-y-px">
877 {shows("repository") && (
878 <SidebarLink to={`${base}/settings/repository`} icon={<BookMarked size={15} />}>
879 Repository
880 </SidebarLink>
881 )}
882 {shows("mirroring") && (
883 <SidebarLink to={`${base}/settings/mirroring`} icon={<ArrowLeftRight size={15} />}>
884 Mirroring
885 </SidebarLink>
886 )}
887 {shows("access") && (
888 <SidebarLink to={`${base}/settings/access`} icon={<Users size={15} />}>
889 Access
890 </SidebarLink>
891 )}
892 {shows("keys") && (
893 <SidebarLink to={`${base}/settings/keys`} icon={<KeyRound size={15} />}>
894 Deploy keys
895 </SidebarLink>
896 )}
897 {shows("branches") && (
898 <SidebarLink to={`${base}/settings/branches`} icon={<GitBranch size={15} />}>
899 Branches and merging
900 </SidebarLink>
901 )}
902 {shows("rules") && (
903 <SidebarLink to={`${base}/settings/rules`} icon={<Scale size={15} />}>
904 Rules
905 </SidebarLink>
906 )}
907 {shows("secrets") && (
908 <SidebarLink to={`${base}/settings/secrets`} icon={<Lock size={15} />}>
909 Secrets and variables
910 </SidebarLink>
911 )}
912 {shows("actions") && (
913 <SidebarLink to={`${base}/settings/actions`} icon={<PlayCircle size={15} />}>
914 Actions
915 </SidebarLink>
916 )}
917 {shows("environments") && (
918 <SidebarLink to={`${base}/settings/environments`} icon={<Layers size={15} />}>
919 Environments
920 </SidebarLink>
921 )}
922 {shows("runners") && (
923 <SidebarLink to={`${base}/settings/runners`} icon={<ServerCog size={15} />}>
924 Runners
925 </SidebarLink>
926 )}
927 {shows("webhooks") && (
928 <SidebarLink to={`${base}/settings/webhooks`} icon={<Webhook size={15} />}>
929 Webhooks
930 </SidebarLink>
931 )}
932 </div>
933 </nav>
934 );
935}
936
937/**
938 * Whether the menus list Settings → Invites (invites to g1t): always while
939 * sign-up takes an invite; once anyone can sign up, only for someone with
940 * invites already made to look back on, which the account menu's data says.
941 */
942function useInvitesListed(): boolean {
943 const inviteOnly = useInviteOnly();
944 const details = useFetcher<AccountMenuData | null>({ key: "account-menu" });
945 useEffect(() => {
946 if (!inviteOnly && details.state === "idle" && details.data === undefined) details.load("/settings/menu.json");
947 // eslint-disable-next-line react-hooks/exhaustive-deps
948 }, [inviteOnly]);
949 return inviteOnly || details.data?.invites_page === true;
950}
951
952/** Your own settings, drilled into from Your settings: one page each. */
953function AccountSettingsMenu({ username }: { username: string }) {
954 const invites = useInvitesListed();
955 const link = (page: AccountSettingsPage, icon: ReactNode) => (
956 <SidebarLink to={`/settings/${page}`} icon={icon}>
957 {ACCOUNT_SETTINGS[page].title}
958 </SidebarLink>
959 );
960 return (
961 <nav aria-label="Your settings" className={PANEL}>
962 <BackRow to="/" label="Your settings" context={username} />
963 <div className="mt-2 space-y-px">
964 {link("profile", <CircleUserRound size={15} />)}
965 {link("emails", <Mail size={15} />)}
966 {invites && link("invites", <Ticket size={15} />)}
967 </div>
968 <Rule />
969 <div className="space-y-px">
970 {link("keys", <Fingerprint size={15} />)}
971 {link("tokens", <KeyRound size={15} />)}
972 </div>
973 <Rule />
974 <div className="space-y-px">
975 {link("integrations", <Blocks size={15} />)}
976 {link("github", <GithubMark className="size-[15px]" />)}
977 {link("applications", <Plug size={15} />)}
978 </div>
979 <Rule />
980 <div className="space-y-px">
981 {link("two-factor", <ShieldCheck size={15} />)}
982 {link("security-log", <History size={15} />)}
983 </div>
984 </nav>
985 );
986}
987
988/**
989 * Code's sidebar: its Overview, the projects, what spans them and what is
990 * coming; in a project, drilled into the project's own list, and its
991 * settings one level further in. The address says which, so a link
992 * straight to a project opens the sidebar already drilled in.
993 */
994function CodeSidebar({
995 user,
996 shell,
997 missing = false,
998}: {
999 user: User;
1000 shell: ShellData;
1001 /** The page is a 404: the address names nothing the viewer can see. */
1002 missing?: boolean;
1003}) {
1004 const ws = shell.workspace;
1005 const { pathname } = useLocation();
1006 const going = useNavigation().location?.pathname;
1007 // Where the sidebar is drilled to follows the page being gone to, so it
1008 // moves as the link is followed, not once the page arrives.
1009 const target = going ?? pathname;
1010 // On a 404, the address is not a place: no list is drilled into from it,
1011 // except the project's own when the project is real and visible and only
1012 // something inside it is missing (a file, a commit, an issue).
1013 const lost = missing && going == null;
1014 const active = shell.repo;
1015 // In a repository, or on the way into one, its own list.
1016 const repoPath = /^\/([^/]+)\/([^/-][^/]*)(\/|$)/.exec(target);
1017 const reserved = new Set(["settings", "explore", "search", "new", "u", "pricing", "avatars", "workspaces", "login", "logout", "register", "verify", "forgot", "reset", "device", "oauth", "policies", "security", "support", "status", "invite", "notifications", "inbox", ".well-known"]);
1018 // An invitation to a repository is answered before its menu means anything.
1019 const inRepo =
1020 repoPath != null &&
1021 !reserved.has(repoPath[1]) &&
1022 repoPath[2] !== "-" &&
1023 !/^\/[^/]+\/[^/]+\/invitations\/?$/.test(target) &&
1024 (!lost || sameRepo(active, { namespace: repoPath[1]!, name: repoPath[2]! }));
1025 // A project's settings, one level further in.
1026 const inRepoSettings = inRepo && REPO_SETTINGS_PAGE.test(target);
1027 // The repository the menu is for: the one loaded if it is the one being
1028 // gone to, else what the address says, at once.
1029 const targetRepo = inRepo && repoPath ? { namespace: repoPath[1], name: repoPath[2] } : null;
1030 const guessed: MenuRepo | null = targetRepo
1031 ? sameRepo(active, targetRepo)
1032 ? active
1033 : {
1034 ...targetRepo,
1035 member: (user.workspaces ?? []).some((m) => m.slug === targetRepo.namespace.toLowerCase()),
1036 }
1037 : null;
1038 // The viewer's role there, from the repository's page once it has loaded.
1039 const page = useRouteLoaderData("routes/repo/layout") as
1040 | { repo?: { namespace: string; name: string }; access?: ViewerAccess }
1041 | undefined;
1042 const menuRepo: MenuRepo | null =
1043 guessed && page?.access && page.repo && sameRepo(page.repo, guessed)
1044 ? { ...guessed, member: page.access.insider, settings: seesSettings(page.access), can: page.access.can }
1045 : guessed;
1046
1047 // The way from Code's list to the one shown.
1048 const trail: Level[] = [{ key: "main", node: ws ? <CodeMenu shell={shell} slug={ws.slug} /> : null }];
1049 if (menuRepo) {
1050 const key = `repo:${menuRepo.namespace}/${menuRepo.name}`.toLowerCase();
1051 // Out of a project: to its workspace's projects when they are yours.
1052 const home = (user.workspaces ?? []).find((m) => m.slug === menuRepo.namespace.toLowerCase());
1053 const back = home ? { to: `/${home.slug}/-/projects`, label: "All projects" } : { to: ws ? `/${ws.slug}/-/overview` : "/explore", label: "Code" };
1054 trail.push({
1055 key,
1056 node: (
1057 <RepoMenu
1058 repo={menuRepo}
1059 isPrivate={[...shell.repos, ...(shell.shared ?? [])].some((repo) => sameRepo(repo, menuRepo) && repo.isPrivate)}
1060 back={back}
1061 />
1062 ),
1063 });
1064 if (inRepoSettings) trail.push({ key: `${key}:settings`, node: <RepoSettingsMenu repo={menuRepo} /> });
1065 }
1066
1067 return (
1068 <div className="flex h-full flex-col">
1069 <ModeHeader title="Code" />
1070 <Drill trail={trail} />
1071 </div>
1072 );
1073}
1074
1075/**
1076 * A mode's sidebar heading: its name, quiet, under the workspace's
1077 * switcher, with what it makes at the end.
1078 */
1079export function ModeHeader({ title, action }: { title: ReactNode; action?: ReactNode }) {
1080 return (
1081 <div className="flex h-9 shrink-0 items-center gap-1 pr-1 pl-3">
1082 <h2 className="min-w-0 grow truncate text-xs font-medium text-faint">{title}</h2>
1083 {action}
1084 </div>
1085 );
1086}
1087
1088/**
1089 * Code's own list (beside the dock): only code. Its Overview (Mission
1090 * control's code panels), the projects, what spans them, and what is
1091 * coming. The workspace's people, money and settings are elsewhere;
1092 * agents, context and memory are Agents'.
1093 */
1094function CodeMenu({ shell, slug }: { shell: ShellData; slug: string }) {
1095 const { pathname } = useLocation();
1096 const going = useNavigation().location?.pathname;
1097 const path = going ?? pathname;
1098 const at = (page: string) => path === `/${slug}/-/${page}` || path.startsWith(`/${slug}/-/${page}/`);
1099 const shared = shell.shared ?? [];
1100 return (
1101 <nav aria-label="Code" className={PANEL}>
1102 <div className="space-y-px">
1103 <SidebarLink to={`/${slug}/-/overview`} icon={<LayoutDashboard size={15} />} current={at("overview")}>
1104 Overview
1105 </SidebarLink>
1106 </div>
1107 <div className="mt-3">
1108 <SidebarProjects slug={slug} shell={shell} current={at("projects")} />
1109 </div>
1110 <Rule />
1111 <div className="space-y-px">
1112 <SidebarLink to={`/${slug}/-/security`} icon={<ShieldCheck size={15} />} current={at("security") && !at("security/settings")}>
1113 Security
1114 </SidebarLink>
1115 <SidebarLink to={`/${slug}/-/packages`} icon={<Package size={15} />} current={at("packages")}>
1116 Packages
1117 </SidebarLink>
1118 {INSIGHTS && (
1119 <SidebarSoonLink to={`/${slug}/-/insights`} icon={<TrendingUp size={15} />} about={INSIGHTS.summary} current={at("insights")}>
1120 {INSIGHTS.title}
1121 </SidebarSoonLink>
1122 )}
1123 {roadmapIn("Workspace")
1124 .filter((item) => item.key !== "insights" && item.key !== "teams" && item.key !== "fleet")
1125 .map((item) => (
1126 <SidebarSoonLink key={item.key} to={`/${slug}/-/soon/${item.key}`} icon={WORKSPACE_ICONS[item.key] ?? <Sparkles size={15} />} about={item.summary}>
1127 {item.title === "Board" ? "Boards" : item.title}
1128 </SidebarSoonLink>
1129 ))}
1130 </div>
1131 {shared.length > 0 && (
1132 <>
1133 <Rule />
1134 <SidebarGroup title="Shared with you">
1135 {shared.map((repo) => (
1136 <SidebarLink
1137 key={`${repo.namespace}/${repo.name}`}
1138 to={`/${repo.namespace}/${repo.name}`}
1139 icon={repo.isPrivate ? <Lock size={15} /> : <Box size={15} />}
1140 drill="hover"
1141 >
1142 <span className="font-mono text-faint">{repo.namespace}/</span>
1143 {repo.name}
1144 </SidebarLink>
1145 ))}
1146 </SidebarGroup>
1147 </>
1148 )}
1149 </nav>
1150 );
1151}
1152
1153/** Workspace pages that sit in its Settings list, drilled into from the Workspace sidebar. */
1154const WORKSPACE_SETTINGS = ["settings", "repositories", "tokens", "personal-access-tokens", "secrets", "actions", "webhooks", "emoji"];
1155
1156/**
1157 * The Workspace mode's sidebar: the workspace itself, for every member.
1158 * Its overview, money, machines, connections, policies and record, then its
1159 * settings as a list of their own. Owner-only pages stay owner-only.
1160 */
1161export function WorkspaceSidebar({ slug, owner }: { slug: string; owner: boolean }) {
1162 const { pathname } = useLocation();
1163 const going = useNavigation().location?.pathname;
1164 const path = going ?? pathname;
1165 const page = path.startsWith(`/${slug}/-/`) ? path.slice(`/${slug}/-/`.length) : "";
1166 const top = page.split("/")[0] ?? "";
1167 const at = (...pages: string[]) => pages.some((p) => page === p || page.startsWith(`${p}/`));
1168 const inSettings = WORKSPACE_SETTINGS.includes(top);
1169 const main = (
1170 <nav aria-label="Workspace" className={PANEL}>
1171 <div className="space-y-px">
1172 <SidebarLink to={`/${slug}/-/workspace`} icon={<LayoutGrid size={15} />} current={at("workspace")}>
1173 Overview
1174 </SidebarLink>
1175 </div>
1176 <SidebarGroup title="Money" className="mt-3">
1177 <SidebarLink to={`/${slug}/-/spend`} icon={<Coins size={15} />} current={at("spend")}>
1178 Spend
1179 </SidebarLink>
1180 <SidebarLink to={`/${slug}/-/usage`} icon={<BarChart3 size={15} />} current={at("usage")}>
1181 Usage
1182 </SidebarLink>
1183 <SidebarLink to={`/${slug}/-/gateway`} icon={<Network size={15} />} current={at("gateway")}>
1184 AI Gateway
1185 </SidebarLink>
1186 <SidebarLink to={`/${slug}/-/billing`} icon={<CreditCard size={15} />} current={at("billing")}>
1187 Billing and plans
1188 </SidebarLink>
1189 </SidebarGroup>
1190 {owner && (
1191 <SidebarGroup title="Compute" className="mt-3">
1192 <SidebarLink to={`/${slug}/-/runners`} icon={<ServerCog size={15} />} current={at("runners")}>
1193 Runners
1194 </SidebarLink>
1195 </SidebarGroup>
1196 )}
1197 <SidebarGroup title="Connections" className="mt-3">
1198 <SidebarLink to={`/${slug}/-/integrations`} icon={<Plug size={15} />} current={at("integrations")}>
1199 Integrations
1200 </SidebarLink>
1201 </SidebarGroup>
1202 <SidebarGroup title="Security policies" className="mt-3">
1203 <SidebarLink to={`/${slug}/-/security/settings`} icon={<ShieldCheck size={15} />} current={at("security/settings")}>
1204 Security settings
1205 </SidebarLink>
1206 <SidebarLink to={`/${slug}/-/guardrails`} icon={<Gauge size={15} />} current={at("guardrails")}>
1207 Guardrails
1208 </SidebarLink>
1209 <SidebarLink to={`/${slug}/-/rules`} icon={<Scale size={15} />} current={at("rules")}>
1210 Rules
1211 </SidebarLink>
1212 </SidebarGroup>
1213 <Rule />
1214 <div className="space-y-px">
1215 <SidebarLink to={`/${slug}/-/audit`} icon={<History size={15} />} current={at("audit")}>
1216 Audit log
1217 </SidebarLink>
1218 <SidebarLink to={owner ? `/${slug}/-/settings` : `/${slug}/-/repositories`} icon={<Settings size={15} />} drill current={inSettings}>
1219 Settings
1220 </SidebarLink>
1221 </div>
1222 </nav>
1223 );
1224 const settings = (
1225 <nav aria-label="Workspace settings" className={PANEL}>
1226 <BackRow to={`/${slug}/-/workspace`} label="Settings" context={slug} />
1227 <div className="mt-2 space-y-px">
1228 {owner && (
1229 <SidebarLink to={`/${slug}/-/settings`} icon={<Settings size={15} />} end>
1230 General
1231 </SidebarLink>
1232 )}
1233 <SidebarLink to={`/${slug}/-/settings/chat`} icon={<MessagesSquare size={15} />}>
1234 Chat
1235 </SidebarLink>
1236 <SidebarLink to={`/${slug}/-/repositories`} icon={<BookMarked size={15} />}>
1237 Repositories
1238 </SidebarLink>
1239 <SidebarLink to={`/${slug}/-/tokens`} icon={<KeyRound size={15} />}>
1240 Access tokens
1241 </SidebarLink>
1242 {owner && (
1243 <SidebarLink to={`/${slug}/-/personal-access-tokens`} icon={<UserRoundKey size={15} />}>
1244 Personal access tokens
1245 </SidebarLink>
1246 )}
1247 <SidebarLink to={`/${slug}/-/webhooks`} icon={<Webhook size={15} />}>
1248 Webhooks
1249 </SidebarLink>
1250 <SidebarLink to={`/${slug}/-/emoji`} icon={<Smile size={15} />}>
1251 Emoji
1252 </SidebarLink>
1253 </div>
1254 <SidebarGroup title="Runs" className="mt-3">
1255 <SidebarLink to={`/${slug}/-/secrets`} icon={<Lock size={15} />}>
1256 Secrets and variables
1257 </SidebarLink>
1258 <SidebarLink to={`/${slug}/-/actions`} icon={<PlayCircle size={15} />}>
1259 Actions
1260 </SidebarLink>
1261 </SidebarGroup>
1262 </nav>
1263 );
1264 const trail: Level[] = [{ key: "workspace", node: main }];
1265 if (inSettings) trail.push({ key: "workspace:settings", node: settings });
1266 return (
1267 <div className="flex h-full flex-col">
1268 <ModeHeader title="Workspace" />
1269 <Drill trail={trail} />
1270 </div>
1271 );
1272}
1273
1274/**
1275 * People's sidebar: everyone in the workspace, people and agents; its
1276 * teams; the org chart; and, to manage who belongs, members and invites.
1277 */
1278function PeopleSidebar({ slug }: { slug: string }) {
1279 const { pathname } = useLocation();
1280 const going = useNavigation().location?.pathname;
1281 const path = going ?? pathname;
1282 const at = (page: string) => path === `/${slug}/-/${page}` || path.startsWith(`/${slug}/-/${page}/`);
1283 return (
1284 <div className="flex h-full flex-col">
1285 <ModeHeader title="People" />
1286 <nav aria-label="People" className={PANEL}>
1287 <div className="space-y-px">
1288 <SidebarLink to={`/${slug}/-/people`} icon={<Users size={15} />} current={at("people")}>
1289 Everyone
1290 </SidebarLink>
1291 <SidebarLink to={`/${slug}/-/teams`} icon={<UsersRound size={15} />} current={at("teams")}>
1292 Teams
1293 </SidebarLink>
1294 <SidebarLink to={`/${slug}/-/org-chart`} icon={<Network size={15} />} current={at("org-chart")}>
1295 Org chart
1296 </SidebarLink>
1297 </div>
1298 <SidebarGroup title="Membership" className="mt-3">
1299 <SidebarLink to={`/${slug}/-/members`} icon={<UserPlus size={15} />} current={at("members")}>
1300 Members and invites
1301 </SidebarLink>
1302 </SidebarGroup>
1303 </nav>
1304 </div>
1305 );
1306}
1307
1308/**
1309 * Notifications' sidebar: what you have not finished with, what you saved
1310 * and what is done; then why you were told, which narrows any of them.
1311 */
1312function NotificationsSidebar({ counts }: { counts: InboxCounts | null }) {
1313 const { search } = useLocation();
1314 const params = new URLSearchParams(search);
1315 const view = inboxView(params.get("view"));
1316 const reason = inboxReason(params.get("reason"));
1317 const tab = params.get("tab");
1318 const address = (changes: Record<string, string | null>) => {
1319 const merged: Record<string, string | null> = { tab, view: view === "inbox" ? null : view, reason, ...changes };
1320 const next = new URLSearchParams();
1321 for (const [name, value] of Object.entries(merged)) if (value) next.set(name, value);
1322 const query = next.toString();
1323 return query ? `/notifications?${query}` : "/notifications";
1324 };
1325 const views = [
1326 { view: "inbox", label: "Everything", icon: <Bell size={15} />, count: counts?.unread },
1327 { view: "saved", label: "Saved", icon: <Bookmark size={15} /> },
1328 { view: "done", label: "Done", icon: <Check size={15} /> },
1329 ] as const;
1330 return (
1331 <div className="flex h-full flex-col">
1332 <ModeHeader title="Notifications" />
1333 <nav aria-label="Notifications" className={PANEL}>
1334 <div className="space-y-px">
1335 {views.map((entry) => (
1336 <SidebarLink
1337 key={entry.view}
1338 to={address({ view: entry.view === "inbox" ? null : entry.view, before: null })}
1339 icon={entry.icon}
1340 count={"count" in entry ? (entry.count ?? undefined) : undefined}
1341 current={view === entry.view}
1342 >
1343 {entry.label}
1344 </SidebarLink>
1345 ))}
1346 </div>
1347 <SidebarGroup title="Why you were told" className="mt-4">
1348 {REASON_FILTERS.map((entry) => (
1349 <SidebarLink
1350 key={entry.reason ?? "any"}
1351 to={address({ reason: entry.reason, before: null })}
1352 icon={<span className="block size-[15px]" />}
1353 current={reason === entry.reason}
1354 >
1355 {entry.reason == null ? "Any reason" : entry.label}
1356 </SidebarLink>
1357 ))}
1358 </SidebarGroup>
1359 </nav>
1360 </div>
1361 );
1362}
1363
1364/** Your own settings, beside the page: under the account menu, not any workspace's. */
1365export function AccountSidebar({ username }: { username: string }) {
1366 return (
1367 <div className="flex h-full flex-col">
1368 <ModeHeader title="Your account" />
1369 <div className="min-h-0 grow">
1370 <AccountSettingsMenu username={username} />
1371 </div>
1372 </div>
1373 );
1374}
1375
1376/** Words for the sections a path can end in. */
1377const SECTIONS: Record<string, string> = {
1378 issues: "Issues",
1379 milestones: "Milestones",
1380 labels: "Labels",
1381 pulls: "Pull requests",
1382 queue: "Merge queue",
1383 commits: "Commits",
1384 plans: "Outcomes",
1385 actions: "Workflows",
1386 soon: "Soon",
1387 deployments: "Deployments",
1388 repository: "Repository",
1389 access: "Access",
1390 invitations: "Invitation",
1391 repositories: "Repositories",
1392 branches: "Branches",
1393 tags: "Tags",
1394 compare: "Compare",
1395 code: "Files",
1396 secrets: "Secrets and variables",
1397 settings: "Settings",
1398 people: "People",
1399 "org-chart": "Org chart",
1400 members: "Members and invites",
1401 projects: "Projects",
1402 teams: "Teams",
1403 tokens: "Access tokens",
1404 "personal-access-tokens": "Personal access tokens",
1405 spend: "Spend",
1406 receipts: "Receipts",
1407 usage: "Usage",
1408 gateway: "AI Gateway",
1409 billing: "Billing and plans",
1410 integrations: "Integrations",
1411 webhooks: "Webhooks",
1412 emoji: "Emoji",
1413 domains: "Domains",
1414 guardrails: "Guardrails",
1415 rules: "Rules",
1416 audit: "Audit log",
1417 tree: "Files",
1418 blob: "Files",
1419 agents: "Agents",
1420 context: "Context",
1421 memory: "Memory",
1422 security: "Security",
1423 packages: "Packages",
1424 runners: "Runners",
1425 environments: "Environments",
1426 workflows: "Workflows",
1427 observability: "Observability",
1428 insights: "Insights",
1429 sessions: "Sessions",
1430 chat: "Chat",
1431 artifacts: "Artifacts",
1432 home: "Home",
1433 apps: "Apps",
1434 marketplace: "Marketplace",
1435 "code-access": "Code access",
1436 overview: "Overview",
1437 workspace: "Workspace",
1438};
1439
1440/** Settings pages whose name differs from the section's of the same word. */
1441const SETTINGS_SECTIONS: Record<string, string> = { branches: "Branches and merging", actions: "Actions" };
1442
1443/** Where the page is, as a trail of links: workspace / repository / section. */
1444function Breadcrumbs({
1445 pathname,
1446 missing,
1447 repo,
1448 workspace,
1449}: {
1450 pathname: string;
1451 missing?: boolean;
1452 repo?: ShellData["repo"];
1453 /** The workspace you are in: the switcher names it, so the trail starts after it. */
1454 workspace: string | null;
1455}) {
1456 // A 404 names nothing from the address, unless the project is real and
1457 // visible and only something inside it is missing.
1458 const visibleRepo = /^\/([^/]+)\/([^/-][^/]*)(\/|$)/.exec(pathname);
1459 if (missing && !(visibleRepo && sameRepo(repo ?? null, { namespace: visibleRepo[1]!, name: visibleRepo[2]! }))) {
1460 return <Here>Not found</Here>;
1461 }
1462 const parts = pathname.split("/").filter(Boolean);
1463 const reserved = ["settings", "explore", "new", "search", "workspaces", "policies", "security", "support", "status", "invite", "notifications"];
1464 if (parts.length === 0) return <Here>Home</Here>;
1465 // Your settings: Settings / Emails.
1466 if (parts[0] === "settings") {
1467 const page = accountSettingsPage(pathname);
1468 return <Trail trail={[{ label: "Settings", to: FIRST_SETTINGS_PAGE }, ...(page ? [{ label: ACCOUNT_SETTINGS[page].title, to: `/settings/${page}` }] : [])]} />;
1469 }
1470 if (reserved.includes(parts[0]!)) {
1471 const words: Record<string, string> = {
1472 settings: "Account",
1473 explore: "Explore",
1474 new: "New project",
1475 search: "Search",
1476 workspaces: "New workspace",
1477 policies: "Policies",
1478 security: "Security",
1479 support: "Support",
1480 status: "Status",
1481 invite: "Invite",
1482 notifications: "Notifications",
1483 };
1484 return <Here>{words[parts[0]!]}</Here>;
1485 }
1486 // A person's profile, by their handle.
1487 if (parts[0] === "u" && parts[1]) return <ProfileCrumb username={parts[1]} />;
1488 const [owner, second, third, fourth] = parts;
1489 const ours = workspace != null && owner!.toLowerCase() === workspace.toLowerCase();
1490 const trail: Crumb[] = ours ? [] : [{ label: owner!, to: `/${owner}`, mono: true }];
1491 if (second === "-") {
1492 const page = `/${owner}/-/${third}`;
1493 if (third && SETTINGS_PAGE.test(page)) {
1494 trail.push({ label: "Settings", to: `/${owner}/-/settings` });
1495 trail.push({ label: third === "settings" ? "General" : (SECTIONS[third] ?? third), to: page });
1496 } else if (third) {
1497 trail.push({ label: SECTIONS[third] ?? third, to: page });
1498 // The Marketplace names its tab (Marketplace / Extensions), and Agents its templates.
1499 const tabs: Record<string, string> =
1500 third === "marketplace" ? { integrations: "Integrations", extensions: "Extensions", requests: "Requests" } : third === "agents" ? { templates: "Templates" } : {};
1501 const tab = fourth ? tabs[fourth] : undefined;
1502 if (tab) trail.push({ label: tab, to: `${page}/${fourth}` });
1503 }
1504 } else if (second) {
1505 const repo = `/${owner}/${second}`;
1506 trail.push({ label: second, to: repo, mono: true });
1507 if (third === "pull" && fourth) trail.push({ label: `Pull request #${fourth}`, short: `#${fourth}`, to: `${repo}/pull/${fourth}` });
1508 else if (third === "issues" && fourth && fourth !== "new") trail.push({ label: `Issue #${fourth}`, short: `#${fourth}`, to: `${repo}/issues/${fourth}` });
1509 else if (third === "commit" && fourth) trail.push({ label: fourth.slice(0, 7), to: `${repo}/commit/${fourth}`, mono: true });
1510 else if (third && SECTIONS[third]) {
1511 trail.push({ label: SECTIONS[third]!, to: `${repo}/${third}` });
1512 // A settings page names which one: Settings / Secrets and variables.
1513 if (third === "settings" && fourth && SECTIONS[fourth]) {
1514 trail.push({ label: SETTINGS_SECTIONS[fourth] ?? SECTIONS[fourth]!, to: `${repo}/settings/${fourth}` });
1515 }
1516 }
1517 }
1518 if (trail.length === 0) trail.push({ label: "Overview", to: `/${owner}` });
1519 return <Trail trail={trail} />;
1520}
1521
1522/** A profile's place in the top bar: the person's avatar and @handle, from the page once it has loaded. */
1523function ProfileCrumb({ username }: { username: string }) {
1524 const page = useRouteLoaderData("routes/user") as { profile?: { username: string; displayUsername?: string | null; avatar: string | null } } | undefined;
1525 const profile = page?.profile?.username.toLowerCase() === username.toLowerCase() ? page.profile : null;
1526 return (
1527 <Breadcrumb className="min-w-0">
1528 <BreadcrumbList>
1529 <BreadcrumbItem>
1530 <BreadcrumbPage asChild className="flex items-center gap-2 hover:bg-raised">
1531 <Link to={`/u/${profile?.username ?? username}`}>
1532 <Avatar name={profile?.username ?? username} image={profile?.avatar ?? null} size={20} />
1533 <span className="truncate font-mono text-[0.8125rem]">@{profile ? shownUsername(profile) : username}</span>
1534 </Link>
1535 </BreadcrumbPage>
1536 </BreadcrumbItem>
1537 </BreadcrumbList>
1538 </Breadcrumb>
1539 );
1540}
1541
1542/** A page with no trail to it, such as Today or Search: its name alone. */
1543function Here({ children }: { children: ReactNode }) {
1544 return (
1545 <Breadcrumb className="min-w-0">
1546 <BreadcrumbList>
1547 <BreadcrumbItem>
1548 <BreadcrumbPage>{children}</BreadcrumbPage>
1549 </BreadcrumbItem>
1550 </BreadcrumbList>
1551 </Breadcrumb>
1552 );
1553}
1554
1555/** One link of the trail; `short` is what a phone shows when it is the page itself. */
1556type Crumb = { label: string; to: string; mono?: boolean; short?: string };
1557
1558/**
1559 * The trail of links. On a phone there is room for one: the page itself,
1560 * with a way back to where it sits; the whole trail from a wider screen up.
1561 */
1562function Trail({ trail }: { trail: Crumb[] }) {
1563 // Up on a phone, unless up is the workspace itself: its pages are the tabs.
1564 const up = trail.length > 1 && !/^\/[^/]+$/.test(trail[trail.length - 2]!.to) ? trail[trail.length - 2]! : null;
1565 return (
1566 <Breadcrumb className="flex min-w-0 items-center">
1567 {up && (
1568 <Button asChild variant="ghost" size="icon-bar" className="-ml-1 sm:hidden">
1569 <Link to={up.to} prefetch="intent" aria-label={`Back to ${up.label}`}>
1570 <ChevronLeft size={16} />
1571 </Link>
1572 </Button>
1573 )}
1574 <BreadcrumbList>
1575 {trail.map((crumb, index) => {
1576 const last = index === trail.length - 1;
1577 const label =
1578 last && crumb.short ? (
1579 <>
1580 <span className="sm:hidden">{crumb.short}</span>
1581 <span className="hidden sm:inline">{crumb.label}</span>
1582 </>
1583 ) : (
1584 crumb.label
1585 );
1586 const mono = crumb.mono ? "font-mono text-[0.8125rem]" : "";
1587 return (
1588 <Fragment key={index}>
1589 {index > 0 && <BreadcrumbSeparator className="max-sm:hidden" />}
1590 <BreadcrumbItem className={last ? "" : "max-sm:hidden"}>
1591 {last ? (
1592 // The page you are on is still a link: to its own top, as the trail always was.
1593 <BreadcrumbPage asChild className={`hover:bg-raised ${mono}`}>
1594 <Link to={crumb.to} prefetch="intent">
1595 {label}
1596 </Link>
1597 </BreadcrumbPage>
1598 ) : (
1599 <BreadcrumbLink asChild className={mono}>
1600 <Link to={crumb.to} prefetch="intent">
1601 {label}
1602 </Link>
1603 </BreadcrumbLink>
1604 )}
1605 </BreadcrumbItem>
1606 </Fragment>
1607 );
1608 })}
1609 </BreadcrumbList>
1610 </Breadcrumb>
1611 );
1612}
1613
1614type Command = PaletteCommand;
1615
1616/** Everything the palette can jump to, from what the sidebar already knows. */
1617function commandsFor(user: User, shell: ShellData): Command[] {
1618 const ws = shell.workspace;
1619 const commands: Command[] = [
1620 ...(ws
1621 ? [
1622 { label: "Home", to: homePagePath(ws.slug), icon: <House size={15} /> },
1623 { label: "Chat", to: `/${ws.slug}/-/chat`, icon: <MessagesSquare size={15} /> },
1624 { label: "Agents", to: `/${ws.slug}/-/agents`, icon: <Sparkles size={15} /> },
1625 ...(hasCodeAccess(ws) ? [{ label: "Code overview", to: `/${ws.slug}/-/overview`, icon: <Code2 size={15} /> }] : []),
1626 { label: "Artifacts", to: `/${ws.slug}/-/artifacts`, icon: <Shapes size={15} /> },
1627 { label: "Apps", hint: "Everything installed that you can use", to: `/${ws.slug}/-/apps`, icon: <LayoutGrid size={15} /> },
1628 { label: "Marketplace", hint: "Extensions and integrations to add", to: `/${ws.slug}/-/marketplace`, icon: <Store size={15} /> },
1629 { label: "Agent templates", hint: "Starting points for a new agent", to: `/${ws.slug}/-/agents/templates`, icon: <Bot size={15} /> },
1630 { label: "Workspace", hint: "Billing, policies, settings", to: `/${ws.slug}/-/workspace`, icon: <Building2 size={15} /> },
1631 ]
1632 : []),
1633 ...(shell.repos.length > 0
1634 ? [{ label: "Put an agent on it", hint: "Open an issue and assign g1t", to: "/?agent=new", icon: <Sparkles size={15} /> }]
1635 : []),
1636 { label: "Explore repositories", to: "/explore", icon: <Compass size={15} /> },
1637 { label: "Search g1t", hint: "Repositories, code, issues, people", to: "/search", icon: <Search size={15} /> },
1638 { label: "Notifications", hint: "What needs you", to: "/notifications", icon: <Bell size={15} /> },
1639 { label: "New project", to: "/new", icon: <Plus size={15} /> },
1640 { label: "New workspace", to: "/workspaces/new", icon: <Plus size={15} /> },
1641 { label: "Your settings", to: FIRST_SETTINGS_PAGE, icon: <Settings size={15} /> },
1642 ...(Object.keys(ACCOUNT_SETTINGS) as AccountSettingsPage[])
1643 .filter((page) => page !== "profile")
1644 .map((page) => ({ label: ACCOUNT_SETTINGS[page].title, hint: "Your settings", to: `/settings/${page}`, icon: <Settings size={15} /> })),
1645 ...THEME_COMMANDS,
1646 ];
1647 const repo = shell.repo;
1648 if (repo) {
1649 const base = `/${repo.namespace}/${repo.name}`;
1650 const name = `${repo.namespace}/${repo.name}`;
1651 commands.unshift(
1652 { label: "Overview", hint: name, to: base, icon: <LayoutGrid size={15} /> },
1653 { label: "Code", hint: name, to: `${base}/code`, icon: <Code2 size={15} /> },
1654 { label: "Issues", hint: name, to: `${base}/issues`, icon: <CircleDot size={15} /> },
1655 { label: "New issue", hint: name, to: `${base}/issues/new`, icon: <Plus size={15} /> },
1656 ...(repo.member
1657 ? [{ label: `Put an agent on ${repo.name}`, hint: name, to: `${base}/issues/new?agent=1`, icon: <Sparkles size={15} /> }]
1658 : []),
1659 { label: "Pull requests", hint: name, to: `${base}/pulls`, icon: <GitPullRequest size={15} /> },
1660 { label: "Commits", hint: name, to: `${base}/commits`, icon: <History size={15} /> },
1661 ...(repo.member
1662 ? [
1663 { label: "Plan work", hint: name, to: `${base}/plans`, icon: <ListTree size={15} /> },
1664 { label: "Deployments", hint: name, to: `${base}/deployments`, icon: <Rocket size={15} /> },
1665 { label: "Secrets and variables", hint: name, to: `${base}/settings/secrets`, icon: <Lock size={15} /> },
1666 { label: "Project settings", hint: name, to: `${base}/settings`, icon: <Settings size={15} /> },
1667 { label: "Repository settings", hint: name, to: `${base}/settings/repository`, icon: <Settings size={15} /> },
1668 ]
1669 : []),
1670 );
1671 }
1672 for (const membership of user.workspaces ?? []) {
1673 commands.push(
1674 { label: displayName(membership), hint: `Workspace · ${membership.slug}`, to: `/${membership.slug}`, icon: <Avatar name={membership.slug} image={membership.avatar} size={15} square /> },
1675 { label: "All projects", hint: membership.slug, to: `/${membership.slug}/-/projects`, icon: <LayoutGrid size={15} /> },
1676 { label: "People", hint: membership.slug, to: `/${membership.slug}/-/people`, icon: <Users size={15} /> },
1677 { label: "Spend", hint: `${membership.slug} · Budgets and receipts`, to: `/${membership.slug}/-/spend`, icon: <Coins size={15} /> },
1678 { label: "Usage", hint: membership.slug, to: `/${membership.slug}/-/usage`, icon: <BarChart3 size={15} /> },
1679 { label: "AI Gateway", hint: `${membership.slug} · Usage`, to: `/${membership.slug}/-/gateway`, icon: <Network size={15} /> },
1680 { label: "Billing and plans", hint: `${membership.slug} · Settings`, to: `/${membership.slug}/-/billing`, icon: <CreditCard size={15} /> },
1681 { label: "Access tokens", hint: `${membership.slug} · Settings`, to: `/${membership.slug}/-/tokens`, icon: <KeyRound size={15} /> },
1682 { label: "Integrations", hint: membership.slug, to: `/${membership.slug}/-/integrations`, icon: <Plug size={15} /> },
1683 );
1684 }
1685 for (const listed of shell.repos) {
1686 commands.push({
1687 label: listed.title ?? listed.name,
1688 hint: `${listed.namespace} · Project`,
1689 to: `/${listed.namespace}/${listed.name}`,
1690 icon: <Box size={15} />,
1691 });
1692 }
1693 // "Put an agent on …": one per project, after the projects themselves.
1694 for (const listed of shell.repos) {
1695 if (repo && listed.namespace === repo.namespace && listed.name === repo.name) continue;
1696 commands.push({
1697 label: `Put an agent on ${listed.title ?? listed.name}`,
1698 hint: `${listed.namespace}/${listed.name}`,
1699 to: `/${listed.namespace}/${listed.name}/issues/new?agent=1`,
1700 icon: <Sparkles size={15} />,
1701 });
1702 }
1703 return commands;
1704}
1705
1706/**
1707 * The page while the next one loads: after a moment it dims, under the
1708 * bar below, so it is plainly on its way out rather than frozen, and the
1709 * next page fades up from there. Sending a form does not dim it: the
1710 * form's button says it is working. Spread on the element holding the page.
1711 */
1712export function useLeaving() {
1713 const navigation = useNavigation();
1714 const method = navigation.formMethod?.toUpperCase();
1715 const leaving = navigation.state === "loading" && (method == null || method === "GET");
1716 return {
1717 "aria-busy": leaving || undefined,
1718 className: `transition-opacity motion-reduce:transition-none ${leaving ? "opacity-60 delay-200 duration-300" : "duration-150"}`,
1719 };
1720}
1721
1722/**
1723 * A bar across the top of the page while the next one loads, as GitHub
1724 * has: it appears at once, creeps towards the end while waiting, then fills
1725 * and fades when the page arrives.
1726 */
1727export function Progress() {
1728 const navigation = useNavigation();
1729 const busy = navigation.state !== "idle";
1730 const [width, setWidth] = useState(0);
1731 const [visible, setVisible] = useState(false);
1732 useEffect(() => {
1733 if (busy) {
1734 setVisible(true);
1735 setWidth(12);
1736 // Slows as it goes, never quite arriving until the page does.
1737 const timer = setInterval(() => setWidth((now) => now + (90 - now) * 0.12), 200);
1738 return () => clearInterval(timer);
1739 }
1740 setWidth((now) => (now > 0 ? 100 : 0));
1741 const fade = setTimeout(() => setVisible(false), 250);
1742 const reset = setTimeout(() => setWidth(0), 550);
1743 return () => {
1744 clearTimeout(fade);
1745 clearTimeout(reset);
1746 };
1747 }, [busy]);
1748 return (
1749 <div
1750 aria-hidden="true"
1751 className={`pointer-events-none fixed inset-x-0 top-0 z-[60] h-[3px] transition-opacity duration-300 ${
1752 visible ? "opacity-100" : "opacity-0"
1753 }`}
1754 >
1755 <div
1756 className="h-full bg-accent shadow-[0_0_10px_var(--color-accent)] transition-[width] duration-200 ease-out"
1757 style={{ width: `${width}%` }}
1758 />
1759 </div>
1760 );
1761}
1762
1763/**
1764 * The top bar's way to g1t: the direct message with the workspace's
1765 * orchestrator, opened or made. The one tinted control in the bar: the
1766 * lavender pixel 1 bare beside its words, on a wash of the accent.
1767 */
1768function AskG1tButton({ slug }: { slug: string }) {
1769 return (
1770 <Hint label="Ask g1t">
1771 <Button asChild variant="soft" size="bar" className="gap-2 lg:px-3">
1772 <Link to={`/${slug}/-/chat?agent=g1t`} aria-label="Ask g1t">
1773 <MarkGlyph className="h-3.5" />
1774 <span className="max-lg:hidden">Ask g1t</span>
1775 </Link>
1776 </Button>
1777 </Hint>
1778 );
1779}
1780
1781/**
1782 * Which sidebar sits beside the page: each mode's own, or none. Home and
1783 * Apps are pages at full width, and so are g1t's public pages, such as a
1784 * profile, which are no workspace's. Without a workspace, only your own
1785 * settings and Notifications have one.
1786 */
1787function sidebarFor(mode: ModeKey, workspace: boolean): Panel | null {
1788 if (!workspace) return mode === "account" || mode === "notifications" ? mode : null;
1789 if (mode === "home" || mode === "apps" || mode === "site") return null;
1790 return mode;
1791}
1792
1793/** The sidebars that sit beside the page, one per mode that has one. */
1794type Panel = "chat" | "artifacts" | "agents" | "code" | "notifications" | "people" | "workspace" | "account";
1795
1796/** Each sidebar's name, for the button that opens it on a phone. */
1797const MODE_MENU: Record<Panel, string> = {
1798 chat: "Chat",
1799 artifacts: "Artifacts",
1800 agents: "Agents",
1801 code: "Code",
1802 notifications: "Notifications",
1803 people: "People",
1804 workspace: "Workspace",
1805 account: "Your account",
1806};
1807
1808/** Whether a key press happened in something you type into, where Ctrl B is the editor's. */
1809function typing(target: EventTarget | null): boolean {
1810 if (!(target instanceof HTMLElement)) return false;
1811 return target.isContentEditable || target.closest("input, textarea, select, [contenteditable=''], [contenteditable='true'], [role='textbox']") != null;
1812}
1813
1814/** Ctrl B (⌘B on a Mac) shows or hides the sidebar, except while typing. */
1815function useSidebarShortcut(toggle: () => void) {
1816 useEffect(() => {
1817 const onKey = (event: KeyboardEvent) => {
1818 if (event.key.toLowerCase() !== "b" || event.altKey || event.shiftKey || !(event.ctrlKey || event.metaKey)) return;
1819 if (event.defaultPrevented || typing(event.target)) return;
1820 event.preventDefault();
1821 toggle();
1822 };
1823 window.addEventListener("keydown", onKey);
1824 return () => window.removeEventListener("keydown", onKey);
1825 }, [toggle]);
1826}
1827
1828/**
1829 * Search or jump to: the command palette. On a computer it looks like the
1830 * field it opens, with its shortcut; on a phone, a magnifier.
1831 */
1832function SearchButton({ onClick }: { onClick: () => void }) {
1833 return (
1834 <>
1835 <Button variant="ghost" size="icon-bar" aria-label="Search or jump to" onClick={onClick} className="md:hidden">
1836 <Search size={18} />
1837 </Button>
1838 <Button
1839 variant="outline"
1840 size="sm"
1841 aria-label="Search or jump to"
1842 onClick={onClick}
1843 className="mr-1 w-[min(18rem,26vw)] justify-start bg-surface font-normal text-faint hover:bg-surface hover:text-muted max-md:hidden"
1844 >
1845 <Search size={15} />
1846 <span className="grow truncate text-left">Search or jump to</span>
1847 <PaletteKey className="rounded border border-line bg-bg px-1.5 font-mono text-[0.625rem] leading-4 text-muted" />
1848 </Button>
1849 </>
1850 );
1851}
1852
1853/** The button that shows or hides the sidebar. */
1854function SidebarToggle({ onClick, open, className = "" }: { onClick: () => void; open: boolean; className?: string }) {
1855 const key = sidebarKeyLabel(typeof navigator === "undefined" ? null : navigator.platform);
1856 return (
1857 <Hint label={`Toggle sidebar (${key})`}>
1858 <Button variant="ghost" size="icon-sm" aria-label={open ? "Hide the sidebar" : "Show the sidebar"} aria-expanded={open} onClick={onClick} className={className}>
1859 <PanelLeft size={17} />
1860 </Button>
1861 </Hint>
1862 );
1863}
1864
1865/**
1866 * The app: three surfaces that never blur
1867 * together. The dock, a floating bar of apps down the left; the mode's
1868 * sidebar, flat on the background beside it, which folds away with Ctrl B
1869 * and is a drawer below 1024px; and the page, a rounded panel inset from
1870 * the window, with its header across the top: the sidebar's toggle, where
1871 * you are, search, Ask g1t and Create new. On a phone the dock is a bar
1872 * along the bottom. Only for someone signed in; without a workspace yet,
1873 * there is no dock.
1874 */
1875export function AppShell({
1876 user,
1877 shell,
1878 missing = false,
1879 banner,
1880 sidebarClosed = false,
1881 children,
1882}: {
1883 user: User;
1884 shell: ShellData;
1885 /** The page is a 404 (see CodeSidebar). */
1886 missing?: boolean;
1887 banner?: ReactNode;
1888 /** Whether the person folded the sidebar away, as their cookie says. */
1889 sidebarClosed?: boolean;
1890 children: ReactNode;
1891}) {
1892 const { pathname } = useLocation();
1893 const [drawer, setDrawer] = useState(false);
1894 const [closed, setClosed] = useState(sidebarClosed);
1895 const [palette, setPalette] = useState(false);
1896 const commands = useMemo(() => commandsFor(user, shell), [user, shell]);
1897
1898 // A new page closes the drawer.
1899 useEffect(() => setDrawer(false), [pathname]);
1900 usePaletteShortcut(() => setPalette((open) => !open));
1901 const leaving = useLeaving();
1902 useVisualViewport();
1903 // Whether the page has scrolled under the top bar, which then draws its line (see data-page-head).
1904 const [scrolled, setScrolled] = useState(false);
1905 useEffect(() => {
1906 const onScroll = () => setScrolled(window.scrollY > 2);
1907 onScroll();
1908 window.addEventListener("scroll", onScroll, { passive: true });
1909 return () => window.removeEventListener("scroll", onScroll);
1910 }, []);
1911
1912 const going = useNavigation().location?.pathname;
1913 const ws = shell.workspace;
1914 const mode = modeOf(going ?? pathname, ws?.slug ?? null);
1915 const panel = sidebarFor(mode, ws != null);
1916 const code = ws ? hasCodeAccess(ws) : false;
1917 const { sidebar: chatSidebar } = useChatSidebar();
1918 // Notify: the feed socket's live counts (lib/notify-client.ts) once it has them; the page's until then.
1919 const live = useLiveBadges(ws?.slug);
1920 const chatUnread = chatSidebar
1921 ? unreadTotals(chatSidebar.entries)
1922 : live?.chat != null
1923 ? { unread: live.chat, mentions: live.mentions ?? 0 }
1924 : (shell.chat ?? { unread: 0, mentions: 0 });
1925 const notificationsUnread = live?.inbox ?? shell.inbox?.unread ?? 0;
1926 const unread = { notifications: notificationsUnread, chat: chatUnread.unread, mentions: chatUnread.mentions };
1927
1928 // Folding the sidebar away on a computer is remembered, so the next page is drawn the same from the server.
1929 const toggleSidebar = useCallback(() => {
1930 if (!window.matchMedia("(min-width: 1024px)").matches) {
1931 setDrawer((open) => !open);
1932 return;
1933 }
1934 setClosed((was) => {
1935 document.cookie = sidebarCookie(!was, window.location.protocol === "https:");
1936 return !was;
1937 });
1938 }, []);
1939 useSidebarShortcut(useCallback(() => {
1940 if (panel) toggleSidebar();
1941 }, [panel, toggleSidebar]));
1942
1943 const inline = panel != null && !closed;
1944 const sidebarNode = () => {
1945 if (!panel) return null;
1946 if (!ws) return panel === "notifications" ? <NotificationsSidebar counts={shell.inbox ?? null} /> : <AccountSidebar username={user.username} />;
1947 switch (panel) {
1948 case "code":
1949 return <CodeSidebar user={user} shell={shell} missing={missing} />;
1950 case "chat":
1951 return <ChatSidebar slug={ws.slug} />;
1952 case "artifacts":
1953 return <FoliosSidebar slug={ws.slug} />;
1954 case "agents":
1955 return <AgentsSidebar slug={ws.slug} shellAgents={shell.agents ?? null} code={code} owner={ws.role === "owner"} />;
1956 case "notifications":
1957 return <NotificationsSidebar counts={shell.inbox ?? null} />;
1958 case "people":
1959 return <PeopleSidebar slug={ws.slug} />;
1960 case "workspace":
1961 return <WorkspaceSidebar slug={ws.slug} owner={ws.role === "owner"} />;
1962 case "account":
1963 return <AccountSidebar username={user.username} />;
1964 }
1965 };
1966 // The sidebar's top row: the workspace and its switcher, and the way to fold the sidebar or close the drawer.
1967 const sidebarTop = (inDrawer: boolean) => (
1968 <div className="flex h-14 shrink-0 items-center gap-1 pr-1 pl-1">
1969 {ws ? (
1970 <WorkspaceSwitcher user={user} workspace={ws} />
1971 ) : (
1972 <Link to="/" aria-label="g1t" className="mr-auto flex h-9 items-center rounded-md px-2">
1973 <Logo className="text-[1.125rem]" />
1974 </Link>
1975 )}
1976 {inDrawer ? (
1977 <button type="button" aria-label="Close menu" onClick={() => setDrawer(false)} className="flex size-8 shrink-0 items-center justify-center rounded-md text-faint hover:bg-raised hover:text-fg">
1978 <X size={16} />
1979 </button>
1980 ) : (
1981 <SidebarToggle open onClick={toggleSidebar} />
1982 )}
1983 </div>
1984 );
1985
1986 // On a phone (below 768px): the bottom bar, and a conversation full screen.
1987 const conversation = isConversation(going ?? pathname);
1988 // Where the page panel starts: 8px past the dock (88px), or right after the sidebar (260px) when it is open.
1989 const left = ws ? (inline ? "md:left-24 lg:left-[21.75rem]" : "md:left-24") : inline ? "md:left-2 lg:left-[16.75rem]" : "md:left-2";
1990 const pad = ws ? (inline ? "md:pl-24 lg:pl-[21.75rem]" : "md:pl-24") : inline ? "md:pl-2 lg:pl-[16.75rem]" : "md:pl-2";
1991
1992 return (
1993 // The drawer is a sheet: a dialog that holds focus, closes on Escape or
1994 // a tap outside, and gives focus back to the button that opened it.
1995 <Sheet open={drawer} onOpenChange={setDrawer}>
1996 <Progress />
1997 {ws && (
1998 <div className="fixed top-2 bottom-2 left-2 z-40 hidden w-20 md:block">
1999 <Dock
2000 workspace={ws}
2001 pins={shell.pins ?? []}
2002 unread={unread}
2003 account={<AccountMenu user={user} />}
2004 />
2005 </div>
2006 )}
2007 {panel && (
2008 <aside
2009 aria-label={`${MODE_MENU[panel]} sidebar`}
2010 className={`fixed inset-y-0 z-40 hidden w-[16.25rem] flex-col pr-0.5 pl-1.5 ${ws ? "left-[5.5rem]" : "left-0"} ${inline ? "lg:flex" : ""}`}
2011 >
2012 {sidebarTop(false)}
2013 <div className="min-h-0 grow">{sidebarNode()}</div>
2014 </aside>
2015 )}
2016 <SheetContent
2017 side="left"
2018 showClose={false}
2019 aria-describedby={undefined}
2020 // Focus would land on the workspace's switcher and open its menu's hint; the sheet itself takes it instead.
2021 onOpenAutoFocus={(event) => {
2022 event.preventDefault();
2023 (event.currentTarget as HTMLElement | null)?.focus();
2024 }}
2025 className="flex w-[min(18.5rem,86vw)] flex-col border-line bg-shell px-1.5 pb-[env(safe-area-inset-bottom)] max-md:[&_nav_a]:min-h-10"
2026 >
2027 <SheetTitle className="sr-only">{panel ? `${MODE_MENU[panel]} menu` : "Menu"}</SheetTitle>
2028 {sidebarTop(true)}
2029 <div className="min-h-0 grow">{sidebarNode()}</div>
2030 </SheetContent>
2031
2032 <div className={`min-h-dvh px-1.5 pt-(--frame-top) pb-(--tabbar-h) md:pr-2 ${pad}`}>
2033 {/* A page whose own header sits right under this bar (data-page-head: a conversation's, a project's) reads as one
2034 block with it: no line between them until the page scrolls under the bar. A sticky one (data-page-head="sticky",
2035 an open artifact's) stays under the bar, so the line is always its. */}
2036 <div className="flex min-h-[calc(100dvh-var(--frame-top)-var(--tabbar-h))] min-w-0 flex-col rounded-[14px] bg-bg [&:has([data-page-head])>header:not([data-scrolled])]:border-b-transparent [&:has([data-page-head=sticky])>header]:border-b-transparent">
2037 <header
2038 data-scrolled={scrolled || undefined}
2039 className={`sticky top-(--frame-top) z-30 flex h-14 items-center gap-1 rounded-t-[14px] border-b border-line bg-bg pr-2 pl-2 transition-[border-color] duration-150 sm:pr-3 ${inline ? "lg:pl-3.5" : ""} ${conversation ? "max-md:hidden" : ""}`}
2040 >
2041 {panel && (
2042 <SidebarToggle open={drawer} onClick={toggleSidebar} className={`max-md:size-11 ${inline ? "lg:hidden" : ""}`} />
2043 )}
2044 {ws && (
2045 <span className={`flex min-w-0 shrink items-center gap-1.5 ${inline ? "lg:hidden" : ""}`}>
2046 <WorkspaceSwitcher user={user} workspace={ws} compact />
2047 <span aria-hidden="true" className="text-line-strong">
2048 /
2049 </span>
2050 </span>
2051 )}
2052 <Breadcrumbs pathname={pathname} missing={missing} repo={shell.repo} workspace={ws?.slug ?? null} />
2053 {/* Search, then what's yours (spend, Ask g1t), then the bell and Create new: one height, one rhythm. */}
2054 <div className="ml-auto flex shrink-0 items-center gap-1 md:gap-1.5">
2055 <SearchButton onClick={() => setPalette(true)} />
2056 {/* Your spend this month, or the workspace's for owners and billing managers; on a phone it is on Spend. */}
2057 {ws && (
2058 <span className="flex max-md:hidden">
2059 <SpendPill slug={ws.slug} mayWorkspace={ws.role === "owner" || !!ws.org_roles?.includes("billing_manager")} />
2060 </span>
2061 )}
2062 {ws && <AskG1tButton slug={ws.slug} />}
2063 <Separator orientation="vertical" className="mx-1 data-[orientation=vertical]:h-5 max-md:hidden" />
2064 {/* On a phone, Notifications is in the bottom bar. */}
2065 <span className="flex max-md:hidden">
2066 <NotificationsBell counts={shell.inbox ? { ...shell.inbox, unread: notificationsUnread } : null} />
2067 </span>
2068 <CreateMenu shell={shell} />
2069 {/* Without a workspace there is no dock: the account is here. */}
2070 {!ws && <AccountMenu user={user} side="bottom" />}
2071 </div>
2072 </header>
2073 {banner}
2074 <main id="content" tabIndex={-1} {...leaving} className={`min-w-0 grow outline-none ${leaving.className}`}>
2075 <InMain.Provider value={true}>{children}</InMain.Provider>
2076 </main>
2077 </div>
2078 </div>
2079 {/* The panel's edge: a rounded frame over the page, with the background beyond it, so what scrolls stays inside.
2080 Every page has it, a conversation too; only a phone's conversation, full screen over everything, goes without. */}
2081 <div
2082 aria-hidden="true"
2083 className={`pointer-events-none fixed top-(--frame-top) right-1.5 bottom-(--tabbar-h) left-1.5 z-[35] rounded-[14px] shadow-[0_0_0_1px_var(--color-line),0_0_0_100vmax_var(--color-shell)] md:right-2 ${left} ${conversation ? "max-md:hidden" : ""}`}
2084 />
2085 {ws && <BottomBar user={user} workspace={ws} pins={shell.pins ?? []} unread={unread} onReselect={panel ? () => setDrawer(true) : undefined} />}
2086 <CommandPalette open={palette} onOpenChange={setPalette} commands={commands} repo={shell.repo ? `${shell.repo.namespace}/${shell.repo.name}` : null} />
2087 </Sheet>
2088 );
2089}
2090
2091/** Create new: a project, an issue in the one you are in, a workspace or a team. */
2092function CreateMenu({ shell }: { shell: ShellData }) {
2093 return (
2094 <DropdownMenu>
2095 <Hint label="Create new">
2096 <DropdownMenuTrigger asChild>
2097 <Button variant="ghost" size="bar" aria-label="Create new" className="gap-0.5 px-1.5 text-fg/90">
2098 <Plus size={17} className="max-md:size-5" />
2099 <ChevronDown size={12} className="text-faint max-md:hidden" />
2100 </Button>
2101 </DropdownMenuTrigger>
2102 </Hint>
2103 <DropdownMenuContent align="end" className="min-w-52">
2104 {shell.repo && (
2105 <>
2106 <DropdownMenuLabel className="truncate">In {shell.repo.name}</DropdownMenuLabel>
2107 <DropdownMenuItem asChild>
2108 <Link to={`/${shell.repo.namespace}/${shell.repo.name}/issues/new`}>
2109 <CircleDot />
2110 New issue
2111 </Link>
2112 </DropdownMenuItem>
2113 {shell.repo.member && (
2114 <DropdownMenuItem asChild>
2115 <Link to={`/${shell.repo.namespace}/${shell.repo.name}/plans`}>
2116 <ListTree />
2117 Plan work
2118 </Link>
2119 </DropdownMenuItem>
2120 )}
2121 <DropdownMenuSeparator />
2122 </>
2123 )}
2124 <DropdownMenuItem asChild>
2125 <Link to="/?agent=new">
2126 <Sparkles />
2127 Put an agent on it
2128 </Link>
2129 </DropdownMenuItem>
2130 <DropdownMenuItem asChild>
2131 <Link to="/new">
2132 <Box />
2133 New project
2134 </Link>
2135 </DropdownMenuItem>
2136 <DropdownMenuItem asChild>
2137 <Link to="/new/github">
2138 <GitBranch />
2139 Import from GitHub
2140 </Link>
2141 </DropdownMenuItem>
2142 <DropdownMenuSeparator />
2143 <DropdownMenuItem asChild>
2144 <Link to="/workspaces/new">
2145 <Users />
2146 New workspace
2147 </Link>
2148 </DropdownMenuItem>
2149 {/* A team in the workspace you are in, for whoever it lets create one. */}
2150 {shell.workspace &&
2151 (mayCreateTeams(shell.workspace.team_creation, shell.workspace.role) ? (
2152 <DropdownMenuItem asChild>
2153 <Link to={`/${shell.workspace.slug}/-/teams/new`}>
2154 <UsersRound />
2155 New team
2156 </Link>
2157 </DropdownMenuItem>
2158 ) : (
2159 <DropdownMenuItem disabled>
2160 <UsersRound />
2161 New team
2162 <span className="ml-auto pl-3 text-xs text-faint">Owners only</span>
2163 </DropdownMenuItem>
2164 ))}
2165 </DropdownMenuContent>
2166 </DropdownMenu>
2167 );
2168}