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