Skip to content
2,247 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 RepoMirror, 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 /** The remote it mirrors, once the repository's page loads: a mirror lists only what it offers. */
786 mirror?: RepoMirror | null;
787 issues?: number;
788 pulls?: number;
789};
790
791function sameRepo(a: { namespace: string; name: string } | null, b: { namespace: string; name: string } | null) {
792 return (
793 a != null &&
794 b != null &&
795 a.namespace.toLowerCase() === b.namespace.toLowerCase() &&
796 a.name.toLowerCase() === b.name.toLowerCase()
797 );
798}
799
800/**
801 * A project's own list, drilled into while you are in it: everything about
802 * the project, running and its code, and nothing else, with the way back
803 * out to all of them.
804 */
805function RepoMenu({
806 repo,
807 isPrivate,
808 back,
809}: {
810 repo: MenuRepo;
811 isPrivate: boolean;
812 /** Where the way back leads: the workspace's projects, mission control, or Explore. */
813 back: { to: string; label: string };
814}) {
815 const base = `/${repo.namespace}/${repo.name}`;
816 // What a member sees, what everyone who can see the project does, and
817 // what a mirror offers now (lib/chrome.ts).
818 const shows = new Set(projectPages(repo.member, repo.can, repo.mirror));
819 const { current: atOverview, pending: toOverview } = useRowState(base, { end: true });
820 return (
821 <nav aria-label={`${repo.namespace}/${repo.name}`} className={PANEL}>
822 <BackRow to={back.to} label={back.label} />
823 <NavRows className="mt-1">
824 <SidebarMenuItem>
825 <Hint label="Overview" side="right">
826 <SidebarMenuButton asChild size="lg" isActive={atOverview} isPending={toOverview} className="gap-2 font-normal">
827 <Link to={base} prefetch="intent" aria-current={atOverview ? "page" : undefined}>
828 <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">
829 {isPrivate ? <Lock /> : <Box />}
830 </span>
831 <span className="min-w-0 truncate font-mono text-[0.8125rem]">
832 <span className="text-faint">{repo.namespace}/</span>
833 <span className="font-semibold text-fg">{repo.name}</span>
834 </span>
835 </Link>
836 </SidebarMenuButton>
837 </Hint>
838 </SidebarMenuItem>
839 </NavRows>
840 {/* A project's pages, in the order people use them. A page with more
841 than one view shows them as tabs across its top. */}
842 <Rule />
843 <NavRows>
844 <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} />}>
845 Code
846 </SidebarLink>
847 {/* A mirror that is not taken over lists none of these: its work happens on the remote. */}
848 {shows.has("issues") && (
849 <SidebarLink to={`${base}/issues`} also={[`${base}/plans`, `${base}/milestones`, `${base}/labels`, ...soonPaths(base, "Issues")]} icon={<CircleDot size={15} />} count={repo.issues}>
850 Issues
851 </SidebarLink>
852 )}
853 {shows.has("pulls") && (
854 <SidebarLink to={`${base}/pulls`} also={[`${base}/pull`, `${base}/queue`]} icon={<GitPullRequest size={15} />} count={repo.pulls}>
855 Pull requests
856 </SidebarLink>
857 )}
858 {shows.has("agents") && (
859 <SidebarLink to={`${base}/agents`} also={[`${base}/sessions`, `${base}/memory`, ...soonPaths(base, "Agents")]} icon={<Bot size={15} />}>
860 Agents
861 </SidebarLink>
862 )}
863 {shows.has("actions") && (
864 <SidebarLink to={`${base}/actions`} icon={<PlayCircle size={15} />}>
865 Workflows
866 </SidebarLink>
867 )}
868 </NavRows>
869 <Rule />
870 <NavRows>
871 {shows.has("deployments") ? (
872 <SidebarLink to={`${base}/deployments`} also={soonPaths(base, "Deployments")} icon={<Rocket size={15} />}>
873 Deployments
874 </SidebarLink>
875 ) : null}
876 {shows.has("observability") && (
877 <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.">
878 Observability
879 </SidebarSoonLink>
880 )}
881 {shows.has("security") ? (
882 <SidebarLink to={`${base}/security`} also={soonPaths(base, "Security")} icon={<ShieldCheck size={15} />}>
883 Security
884 </SidebarLink>
885 ) : null}
886 <SidebarLink
887 to={`${base}/contributors`}
888 also={[`${base}/activity`, `${base}/stargazers`, ...soonPaths(base, "Insights")]}
889 icon={<BarChart3 size={15} />}
890 >
891 Insights
892 </SidebarLink>
893 </NavRows>
894 {(repo.settings ?? shows.has("settings")) && (
895 <>
896 <Rule />
897 <NavRows>
898 <SidebarLink to={`${base}/settings`} icon={<Settings size={15} />} drill>
899 Settings
900 </SidebarLink>
901 </NavRows>
902 </>
903 )}
904 </nav>
905 );
906}
907
908/**
909 * A project's settings, drilled into from its list: what is about running
910 * it, then its agents, then its code and who can reach it. The way back
911 * leads to the project.
912 */
913function RepoSettingsMenu({ repo }: { repo: MenuRepo }) {
914 const base = `/${repo.namespace}/${repo.name}`;
915 // Each page shows to the roles that can use it, once the role is known.
916 const shows = (page: string) => !repo.can || repo.can[SETTINGS_CAPABILITY[page] ?? "administer"];
917 const running = shows("deployments");
918 const agents = shows("agents") || shows("guardrails");
919 return (
920 <nav aria-label={`${repo.namespace}/${repo.name} settings`} className={PANEL}>
921 <BackRow to={base} label="Settings" context={`${repo.namespace}/${repo.name}`} />
922 {shows("") && (
923 <NavRows className="mt-2">
924 <SidebarLink to={`${base}/settings`} end icon={<Settings size={15} />}>
925 General
926 </SidebarLink>
927 </NavRows>
928 )}
929 {running && (
930 <>
931 {shows("") && <Rule />}
932 <NavRows className={shows("") ? undefined : "mt-2"}>
933 <SidebarLink to={`${base}/settings/deployments`} icon={<Rocket size={15} />}>
934 Deployments
935 </SidebarLink>
936 <SidebarLink to={`${base}/settings/domains`} icon={<Globe size={15} />}>
937 Domains
938 </SidebarLink>
939 </NavRows>
940 </>
941 )}
942 {agents && (
943 <>
944 <Rule />
945 <NavRows>
946 {shows("agents") && (
947 <SidebarLink to={`${base}/settings/agents`} icon={<Bot size={15} />}>
948 Agents
949 </SidebarLink>
950 )}
951 {shows("guardrails") && (
952 <SidebarLink to={`${base}/settings/guardrails`} icon={<ShieldCheck size={15} />}>
953 Guardrails
954 </SidebarLink>
955 )}
956 </NavRows>
957 </>
958 )}
959 <Rule />
960 <NavRows>
961 {shows("repository") && (
962 <SidebarLink to={`${base}/settings/repository`} icon={<BookMarked size={15} />}>
963 Repository
964 </SidebarLink>
965 )}
966 {shows("mirroring") && (
967 <SidebarLink to={`${base}/settings/mirroring`} icon={<ArrowLeftRight size={15} />}>
968 Mirroring
969 </SidebarLink>
970 )}
971 {shows("access") && (
972 <SidebarLink to={`${base}/settings/access`} icon={<Users size={15} />}>
973 Access
974 </SidebarLink>
975 )}
976 {shows("keys") && (
977 <SidebarLink to={`${base}/settings/keys`} icon={<KeyRound size={15} />}>
978 Deploy keys
979 </SidebarLink>
980 )}
981 {shows("branches") && (
982 <SidebarLink to={`${base}/settings/branches`} icon={<GitBranch size={15} />}>
983 Branches and merging
984 </SidebarLink>
985 )}
986 {shows("rules") && (
987 <SidebarLink to={`${base}/settings/rules`} icon={<Scale size={15} />}>
988 Rules
989 </SidebarLink>
990 )}
991 {shows("secrets") && (
992 <SidebarLink to={`${base}/settings/secrets`} icon={<Lock size={15} />}>
993 Secrets and variables
994 </SidebarLink>
995 )}
996 {shows("actions") && (
997 <SidebarLink to={`${base}/settings/actions`} icon={<PlayCircle size={15} />}>
998 Actions
999 </SidebarLink>
1000 )}
1001 {shows("environments") && (
1002 <SidebarLink to={`${base}/settings/environments`} icon={<Layers size={15} />}>
1003 Environments
1004 </SidebarLink>
1005 )}
1006 {shows("runners") && (
1007 <SidebarLink to={`${base}/settings/runners`} icon={<ServerCog size={15} />}>
1008 Runners
1009 </SidebarLink>
1010 )}
1011 {shows("webhooks") && (
1012 <SidebarLink to={`${base}/settings/webhooks`} icon={<Webhook size={15} />}>
1013 Webhooks
1014 </SidebarLink>
1015 )}
1016 </NavRows>
1017 </nav>
1018 );
1019}
1020
1021/**
1022 * Whether the menus list Settings → Invites (invites to g1t): always while
1023 * sign-up takes an invite; once anyone can sign up, only for someone with
1024 * invites already made to look back on, which the account menu's data says.
1025 */
1026function useInvitesListed(): boolean {
1027 const inviteOnly = useInviteOnly();
1028 const details = useFetcher<AccountMenuData | null>({ key: "account-menu" });
1029 useEffect(() => {
1030 if (!inviteOnly && details.state === "idle" && details.data === undefined) details.load("/settings/menu.json");
1031 // eslint-disable-next-line react-hooks/exhaustive-deps
1032 }, [inviteOnly]);
1033 return inviteOnly || details.data?.invites_page === true;
1034}
1035
1036/** Your own settings, drilled into from Your settings: one page each. */
1037function AccountSettingsMenu({ username }: { username: string }) {
1038 const invites = useInvitesListed();
1039 const link = (page: AccountSettingsPage, icon: ReactNode) => (
1040 <SidebarLink to={`/settings/${page}`} icon={icon}>
1041 {ACCOUNT_SETTINGS[page].title}
1042 </SidebarLink>
1043 );
1044 return (
1045 <nav aria-label="Your settings" className={PANEL}>
1046 <BackRow to="/" label="Your settings" context={username} />
1047 <NavRows className="mt-2">
1048 {link("profile", <CircleUserRound size={15} />)}
1049 {link("emails", <Mail size={15} />)}
1050 {invites && link("invites", <Ticket size={15} />)}
1051 </NavRows>
1052 <Rule />
1053 <NavRows>
1054 {link("keys", <Fingerprint size={15} />)}
1055 {link("tokens", <KeyRound size={15} />)}
1056 </NavRows>
1057 <Rule />
1058 <NavRows>
1059 {link("integrations", <Blocks size={15} />)}
1060 {link("github", <GithubMark className="size-[15px]" />)}
1061 {link("applications", <Plug size={15} />)}
1062 </NavRows>
1063 <Rule />
1064 <NavRows>
1065 {link("two-factor", <ShieldCheck size={15} />)}
1066 {link("security-log", <History size={15} />)}
1067 </NavRows>
1068 </nav>
1069 );
1070}
1071
1072/**
1073 * Code's sidebar: its Overview, the projects, what spans them and what is
1074 * coming; in a project, drilled into the project's own list, and its
1075 * settings one level further in. The address says which, so a link
1076 * straight to a project opens the sidebar already drilled in.
1077 */
1078function CodeSidebar({
1079 user,
1080 shell,
1081 missing = false,
1082}: {
1083 user: User;
1084 shell: ShellData;
1085 /** The page is a 404: the address names nothing the viewer can see. */
1086 missing?: boolean;
1087}) {
1088 const ws = shell.workspace;
1089 const { pathname } = useLocation();
1090 const going = useNavigation().location?.pathname;
1091 // Where the sidebar is drilled to follows the page being gone to, so it
1092 // moves as the link is followed, not once the page arrives.
1093 const target = going ?? pathname;
1094 // On a 404, the address is not a place: no list is drilled into from it,
1095 // except the project's own when the project is real and visible and only
1096 // something inside it is missing (a file, a commit, an issue).
1097 const lost = missing && going == null;
1098 const active = shell.repo;
1099 // In a repository, or on the way into one, its own list.
1100 const repoPath = /^\/([^/]+)\/([^/-][^/]*)(\/|$)/.exec(target);
1101 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"]);
1102 // An invitation to a repository is answered before its menu means anything.
1103 const inRepo =
1104 repoPath != null &&
1105 !reserved.has(repoPath[1]) &&
1106 repoPath[2] !== "-" &&
1107 !/^\/[^/]+\/[^/]+\/invitations\/?$/.test(target) &&
1108 (!lost || sameRepo(active, { namespace: repoPath[1]!, name: repoPath[2]! }));
1109 // A project's settings, one level further in.
1110 const inRepoSettings = inRepo && REPO_SETTINGS_PAGE.test(target);
1111 // The repository the menu is for: the one loaded if it is the one being
1112 // gone to, else what the address says, at once.
1113 const targetRepo = inRepo && repoPath ? { namespace: repoPath[1], name: repoPath[2] } : null;
1114 const guessed: MenuRepo | null = targetRepo
1115 ? sameRepo(active, targetRepo)
1116 ? active
1117 : {
1118 ...targetRepo,
1119 member: (user.workspaces ?? []).some((m) => m.slug === targetRepo.namespace.toLowerCase()),
1120 }
1121 : null;
1122 // The viewer's role there, from the repository's page once it has loaded.
1123 const page = useRouteLoaderData("routes/repo/layout") as
1124 | { repo?: { namespace: string; name: string; mirror?: RepoMirror | null }; access?: ViewerAccess }
1125 | undefined;
1126 const menuRepo: MenuRepo | null =
1127 guessed && page?.access && page.repo && sameRepo(page.repo, guessed)
1128 ? { ...guessed, member: page.access.insider, settings: seesSettings(page.access), can: page.access.can, mirror: page.repo.mirror }
1129 : guessed;
1130
1131 // The way from Code's list to the one shown.
1132 const trail: Level[] = [{ key: "main", node: ws ? <CodeMenu shell={shell} slug={ws.slug} /> : null }];
1133 if (menuRepo) {
1134 const key = `repo:${menuRepo.namespace}/${menuRepo.name}`.toLowerCase();
1135 // Out of a project: to its workspace's projects when they are yours.
1136 const home = (user.workspaces ?? []).find((m) => m.slug === menuRepo.namespace.toLowerCase());
1137 const back = home ? { to: `/${home.slug}/-/projects`, label: "All projects" } : { to: ws ? `/${ws.slug}/-/overview` : "/explore", label: "Code" };
1138 trail.push({
1139 key,
1140 node: (
1141 <RepoMenu
1142 repo={menuRepo}
1143 isPrivate={[...shell.repos, ...(shell.shared ?? [])].some((repo) => sameRepo(repo, menuRepo) && repo.isPrivate)}
1144 back={back}
1145 />
1146 ),
1147 });
1148 if (inRepoSettings) trail.push({ key: `${key}:settings`, node: <RepoSettingsMenu repo={menuRepo} /> });
1149 }
1150
1151 return (
1152 <div className="flex h-full flex-col">
1153 <ModeHeader title="Code" />
1154 <Drill trail={trail} />
1155 </div>
1156 );
1157}
1158
1159/**
1160 * A mode's sidebar heading: its name, quiet, under the workspace's
1161 * switcher, with what it makes at the end.
1162 */
1163export function ModeHeader({ title, action }: { title: ReactNode; action?: ReactNode }) {
1164 return (
1165 <div className="flex h-8 shrink-0 items-center gap-1 pr-2 pl-3">
1166 <SidebarGroupLabel asChild className="min-w-0 grow truncate px-1">
1167 <h2>{title}</h2>
1168 </SidebarGroupLabel>
1169 {action}
1170 </div>
1171 );
1172}
1173
1174/**
1175 * Code's own list (beside the rail): only code. Its Overview (Mission
1176 * control's code panels), the projects, what spans them, and what is
1177 * coming. The workspace's people, money and settings are elsewhere;
1178 * agents, context and memory are Agents'.
1179 */
1180function CodeMenu({ shell, slug }: { shell: ShellData; slug: string }) {
1181 const { pathname } = useLocation();
1182 const going = useNavigation().location?.pathname;
1183 const path = going ?? pathname;
1184 const at = (page: string) => path === `/${slug}/-/${page}` || path.startsWith(`/${slug}/-/${page}/`);
1185 const shared = shell.shared ?? [];
1186 return (
1187 <nav aria-label="Code" className={PANEL}>
1188 <NavRows>
1189 <SidebarLink to={`/${slug}/-/overview`} icon={<LayoutDashboard size={15} />} current={at("overview")}>
1190 Overview
1191 </SidebarLink>
1192 </NavRows>
1193 <Rule />
1194 <SidebarProjects slug={slug} shell={shell} current={at("projects")} />
1195 <Rule />
1196 <NavRows>
1197 <SidebarLink to={`/${slug}/-/security`} icon={<ShieldCheck size={15} />} current={at("security") && !at("security/settings")}>
1198 Security
1199 </SidebarLink>
1200 <SidebarLink to={`/${slug}/-/packages`} icon={<Package size={15} />} current={at("packages")}>
1201 Packages
1202 </SidebarLink>
1203 {INSIGHTS && (
1204 <SidebarSoonLink to={`/${slug}/-/insights`} icon={<TrendingUp size={15} />} about={INSIGHTS.summary} current={at("insights")}>
1205 {INSIGHTS.title}
1206 </SidebarSoonLink>
1207 )}
1208 {roadmapIn("Workspace")
1209 .filter((item) => item.key !== "insights" && item.key !== "teams" && item.key !== "fleet")
1210 .map((item) => (
1211 <SidebarSoonLink key={item.key} to={`/${slug}/-/soon/${item.key}`} icon={WORKSPACE_ICONS[item.key] ?? <Sparkles size={15} />} about={item.summary}>
1212 {item.title === "Board" ? "Boards" : item.title}
1213 </SidebarSoonLink>
1214 ))}
1215 </NavRows>
1216 {shared.length > 0 && (
1217 <>
1218 <Rule />
1219 <NavGroup title="Shared with you">
1220 {shared.map((repo) => (
1221 <SidebarLink
1222 key={`${repo.namespace}/${repo.name}`}
1223 to={`/${repo.namespace}/${repo.name}`}
1224 icon={repo.isPrivate ? <Lock size={15} /> : <Box size={15} />}
1225 drill="hover"
1226 >
1227 <span className="font-mono text-faint">{repo.namespace}/</span>
1228 {repo.name}
1229 </SidebarLink>
1230 ))}
1231 </NavGroup>
1232 </>
1233 )}
1234 </nav>
1235 );
1236}
1237
1238/** The icon of each of Workspace mode's pages, by its key (lib/workspace-nav.ts). */
1239const WORKSPACE_PAGE_ICONS: Record<string, ReactNode> = {
1240 settings: <Settings size={15} />,
1241 members: <Users size={15} />,
1242 invitations: <Mail size={15} />,
1243 permissions: <ShieldCheck size={15} />,
1244 tokens: <KeyRound size={15} />,
1245 "personal-access-tokens": <UserRoundKey size={15} />,
1246 spend: <Coins size={15} />,
1247 usage: <BarChart3 size={15} />,
1248 gateway: <Network size={15} />,
1249 billing: <CreditCard size={15} />,
1250 runners: <ServerCog size={15} />,
1251 repositories: <BookMarked size={15} />,
1252 actions: <PlayCircle size={15} />,
1253 secrets: <Lock size={15} />,
1254 webhooks: <Webhook size={15} />,
1255 deployments: <Rocket size={15} />,
1256 projects: <Layers size={15} />,
1257 "agent-settings": <Bot size={15} />,
1258 "chat-settings": <MessagesSquare size={15} />,
1259 emoji: <Smile size={15} />,
1260 "artifact-settings": <Shapes size={15} />,
1261 "security-settings": <Shield size={15} />,
1262 guardrails: <Gauge size={15} />,
1263 rules: <Scale size={15} />,
1264 audit: <History size={15} />,
1265 integrations: <Plug size={15} />,
1266 applications: <Blocks size={15} />,
1267};
1268
1269/**
1270 * A group of Workspace mode's rows that folds: its name is the button, with
1271 * a chevron that turns when it is open. The group holding the current page
1272 * is always open, and its button does nothing. Every group starts open, so
1273 * the server and the browser draw the same list.
1274 */
1275function FoldingGroup({ title, current, children }: { title: string; current: boolean; children: ReactNode }) {
1276 const [open, setOpen] = useState(true);
1277 return (
1278 <Collapsible open={open || current} onOpenChange={setOpen}>
1279 <SidebarGroup>
1280 <CollapsibleTrigger
1281 disabled={current}
1282 aria-label={`${title}: ${open || current ? "fold" : "unfold"}`}
1283 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"
1284 >
1285 <span>{title}</span>
1286 {!current && <ChevronRight size={12} aria-hidden="true" className="text-faint/70" />}
1287 </CollapsibleTrigger>
1288 <CollapsibleContent>
1289 <SidebarGroupContent>
1290 <SidebarMenu>{children}</SidebarMenu>
1291 </SidebarGroupContent>
1292 </CollapsibleContent>
1293 </SidebarGroup>
1294 </Collapsible>
1295 );
1296}
1297
1298/**
1299 * The Workspace mode's sidebar: the workspace's settings area, every page
1300 * one click away. Its overview, then the groups in lib/workspace-nav.ts
1301 * (General, Access, Money, Compute, Code, Agents, Chat, Artifacts,
1302 * Security, Integrations), each folding, the one you are in held open.
1303 * Pages only owners open are left out for members, and a group with none
1304 * left goes with them; a page that is coming is a Soon row, not a link.
1305 */
1306export function WorkspaceSidebar({ slug, owner }: { slug: string; owner: boolean }) {
1307 const { pathname } = useLocation();
1308 const going = useNavigation().location?.pathname;
1309 const path = going ?? pathname;
1310 const here = workspaceSettingsPage(path, slug);
1311 const overview = path === `/${slug}/-/workspace` || path.startsWith(`/${slug}/-/workspace/`);
1312 const shown = (page: WorkspaceSettingsPage) => owner || !page.owner;
1313 return (
1314 <div className="flex h-full flex-col">
1315 <ModeHeader title="Workspace" />
1316 <nav aria-label="Workspace" className={PANEL}>
1317 <NavRows>
1318 <SidebarLink to={`/${slug}/-/workspace`} icon={<LayoutGrid size={15} />} current={overview}>
1319 Overview
1320 </SidebarLink>
1321 </NavRows>
1322 {WORKSPACE_SETTINGS_GROUPS.filter((group) => group.pages.some(shown)).map((group) => (
1323 <Fragment key={group.key}>
1324 <Rule />
1325 <FoldingGroup title={group.title} current={here?.group === group.key}>
1326 {group.pages.filter(shown).map((page) =>
1327 page.soon ? (
1328 <SidebarSoon key={page.key} icon={WORKSPACE_PAGE_ICONS[page.key] ?? <Sparkles size={15} />} about={page.soon}>
1329 {page.label}
1330 </SidebarSoon>
1331 ) : (
1332 <SidebarLink
1333 key={page.key}
1334 to={`/${slug}/-/${page.path}`}
1335 icon={WORKSPACE_PAGE_ICONS[page.key] ?? <Settings size={15} />}
1336 current={here?.page === page.key}
1337 >
1338 {page.label}
1339 </SidebarLink>
1340 ),
1341 )}
1342 </FoldingGroup>
1343 </Fragment>
1344 ))}
1345 </nav>
1346 </div>
1347 );
1348}
1349
1350/**
1351 * People's sidebar: everyone in the workspace (its people; agents are
1352 * under Agents); its teams, which agents can be on; and the org chart. Who
1353 * belongs, and inviting people, is the workspace's: Workspace mode's
1354 * Access group.
1355 */
1356function PeopleSidebar({ slug }: { slug: string }) {
1357 const { pathname } = useLocation();
1358 const going = useNavigation().location?.pathname;
1359 const path = going ?? pathname;
1360 const at = (page: string) => path === `/${slug}/-/${page}` || path.startsWith(`/${slug}/-/${page}/`);
1361 return (
1362 <div className="flex h-full flex-col">
1363 <ModeHeader title="People" />
1364 <nav aria-label="People" className={PANEL}>
1365 <NavRows>
1366 <SidebarLink to={`/${slug}/-/people`} icon={<Users size={15} />} current={at("people")}>
1367 Everyone
1368 </SidebarLink>
1369 <SidebarLink to={`/${slug}/-/teams`} icon={<UsersRound size={15} />} current={at("teams")}>
1370 Teams
1371 </SidebarLink>
1372 <SidebarLink to={`/${slug}/-/org-chart`} icon={<Network size={15} />} current={at("org-chart")}>
1373 Org chart
1374 </SidebarLink>
1375 </NavRows>
1376 </nav>
1377 </div>
1378 );
1379}
1380
1381/**
1382 * Notifications' sidebar: what you have not finished with, what you saved
1383 * and what is done; then why you were told, which narrows any of them.
1384 */
1385function NotificationsSidebar({ counts }: { counts: InboxCounts | null }) {
1386 const { search } = useLocation();
1387 const params = new URLSearchParams(search);
1388 const view = inboxView(params.get("view"));
1389 const reason = inboxReason(params.get("reason"));
1390 const tab = params.get("tab");
1391 const address = (changes: Record<string, string | null>) => {
1392 const merged: Record<string, string | null> = { tab, view: view === "inbox" ? null : view, reason, ...changes };
1393 const next = new URLSearchParams();
1394 for (const [name, value] of Object.entries(merged)) if (value) next.set(name, value);
1395 const query = next.toString();
1396 return query ? `/notifications?${query}` : "/notifications";
1397 };
1398 const views = [
1399 { view: "inbox", label: "Everything", icon: <Bell size={15} />, count: counts?.unread },
1400 { view: "saved", label: "Saved", icon: <Bookmark size={15} /> },
1401 { view: "done", label: "Done", icon: <Check size={15} /> },
1402 ] as const;
1403 return (
1404 <div className="flex h-full flex-col">
1405 <ModeHeader title="Notifications" />
1406 <nav aria-label="Notifications" className={PANEL}>
1407 <NavRows>
1408 {views.map((entry) => (
1409 <SidebarLink
1410 key={entry.view}
1411 to={address({ view: entry.view === "inbox" ? null : entry.view, before: null })}
1412 icon={entry.icon}
1413 count={"count" in entry ? (entry.count ?? undefined) : undefined}
1414 current={view === entry.view}
1415 >
1416 {entry.label}
1417 </SidebarLink>
1418 ))}
1419 </NavRows>
1420 <Rule />
1421 <NavGroup title="Why you were told">
1422 {REASON_FILTERS.map((entry) => (
1423 <SidebarLink
1424 key={entry.reason ?? "any"}
1425 to={address({ reason: entry.reason, before: null })}
1426 icon={<span className="block size-[15px]" />}
1427 current={reason === entry.reason}
1428 >
1429 {entry.reason == null ? "Any reason" : entry.label}
1430 </SidebarLink>
1431 ))}
1432 </NavGroup>
1433 </nav>
1434 </div>
1435 );
1436}
1437
1438/** Your own settings, beside the page: under the account menu, not any workspace's. */
1439export function AccountSidebar({ username }: { username: string }) {
1440 return (
1441 <div className="flex h-full flex-col">
1442 <ModeHeader title="Your account" />
1443 <div className="min-h-0 grow">
1444 <AccountSettingsMenu username={username} />
1445 </div>
1446 </div>
1447 );
1448}
1449
1450/** Words for the sections a path can end in. */
1451const SECTIONS: Record<string, string> = {
1452 issues: "Issues",
1453 milestones: "Milestones",
1454 labels: "Labels",
1455 pulls: "Pull requests",
1456 queue: "Merge queue",
1457 commits: "Commits",
1458 plans: "Outcomes",
1459 actions: "Workflows",
1460 soon: "Soon",
1461 deployments: "Deployments",
1462 repository: "Repository",
1463 access: "Access",
1464 invitations: "Invitation",
1465 repositories: "Repositories",
1466 branches: "Branches",
1467 tags: "Tags",
1468 compare: "Compare",
1469 code: "Files",
1470 secrets: "Secrets and variables",
1471 settings: "Settings",
1472 people: "People",
1473 "org-chart": "Org chart",
1474 members: "Members",
1475 permissions: "Permissions",
1476 projects: "Projects",
1477 teams: "Teams",
1478 tokens: "Access tokens",
1479 "personal-access-tokens": "Personal access tokens",
1480 spend: "Spend",
1481 receipts: "Receipts",
1482 usage: "Usage",
1483 gateway: "AI Gateway",
1484 billing: "Billing and plans",
1485 integrations: "Integrations",
1486 webhooks: "Webhooks",
1487 emoji: "Emoji",
1488 domains: "Domains",
1489 guardrails: "Guardrails",
1490 rules: "Rules",
1491 audit: "Audit log",
1492 tree: "Files",
1493 blob: "Files",
1494 agents: "Agents",
1495 context: "Context",
1496 memory: "Memory",
1497 security: "Security",
1498 packages: "Packages",
1499 runners: "Runners",
1500 environments: "Environments",
1501 workflows: "Workflows",
1502 observability: "Observability",
1503 insights: "Insights",
1504 sessions: "Sessions",
1505 chat: "Chat",
1506 artifacts: "Artifacts",
1507 home: "Home",
1508 apps: "Apps",
1509 marketplace: "Marketplace",
1510 "code-access": "Code access",
1511 overview: "Overview",
1512 workspace: "Workspace",
1513};
1514
1515/** Settings pages whose name differs from the section's of the same word. */
1516const SETTINGS_SECTIONS: Record<string, string> = { branches: "Branches and merging", actions: "Actions" };
1517
1518/** Where the page is, as a trail of links: workspace / repository / section. */
1519function Breadcrumbs({
1520 pathname,
1521 missing,
1522 repo,
1523 workspace,
1524}: {
1525 pathname: string;
1526 missing?: boolean;
1527 repo?: ShellData["repo"];
1528 /** The workspace you are in: the switcher names it, so the trail starts after it. */
1529 workspace: string | null;
1530}) {
1531 // A 404 names nothing from the address, unless the project is real and
1532 // visible and only something inside it is missing.
1533 const visibleRepo = /^\/([^/]+)\/([^/-][^/]*)(\/|$)/.exec(pathname);
1534 if (missing && !(visibleRepo && sameRepo(repo ?? null, { namespace: visibleRepo[1]!, name: visibleRepo[2]! }))) {
1535 return <Here>Not found</Here>;
1536 }
1537 const parts = pathname.split("/").filter(Boolean);
1538 const reserved = ["settings", "explore", "new", "search", "workspaces", "policies", "security", "support", "status", "invite", "notifications"];
1539 if (parts.length === 0) return <Here>Home</Here>;
1540 // Your settings: Settings / Emails.
1541 if (parts[0] === "settings") {
1542 const page = accountSettingsPage(pathname);
1543 return <Trail trail={[{ label: "Settings", to: FIRST_SETTINGS_PAGE }, ...(page ? [{ label: ACCOUNT_SETTINGS[page].title, to: `/settings/${page}` }] : [])]} />;
1544 }
1545 if (reserved.includes(parts[0]!)) {
1546 const words: Record<string, string> = {
1547 settings: "Account",
1548 explore: "Explore",
1549 new: "New project",
1550 search: "Search",
1551 workspaces: "New workspace",
1552 policies: "Policies",
1553 security: "Security",
1554 support: "Support",
1555 status: "Status",
1556 invite: "Invite",
1557 notifications: "Notifications",
1558 };
1559 return <Here>{words[parts[0]!]}</Here>;
1560 }
1561 // A person's profile, by their handle.
1562 if (parts[0] === "u" && parts[1]) return <ProfileCrumb username={parts[1]} />;
1563 const [owner, second, third, fourth] = parts;
1564 const ours = workspace != null && owner!.toLowerCase() === workspace.toLowerCase();
1565 const trail: Crumb[] = ours ? [] : [{ label: owner!, to: `/${owner}`, mono: true }];
1566 if (second === "-") {
1567 const page = `/${owner}/-/${third}`;
1568 if (third === "settings" && fourth === "chat") {
1569 // Chat settings is a page of its own, not one of General's.
1570 trail.push({ label: "Chat settings", to: `${page}/chat` });
1571 } else if (third) {
1572 // The workspace's settings pages each stand alone: General, Members, Permissions.
1573 trail.push({ label: third === "settings" ? "General" : (SECTIONS[third] ?? third), to: page });
1574 // The Marketplace names its tab (Marketplace / Extensions), Agents its templates, and Members its invitations.
1575 const tabs: Record<string, string> =
1576 third === "marketplace"
1577 ? { integrations: "Integrations", extensions: "Extensions", requests: "Requests" }
1578 : third === "agents"
1579 ? { templates: "Templates" }
1580 : third === "members"
1581 ? { invitations: "Invitations" }
1582 : {};
1583 const tab = fourth ? tabs[fourth] : undefined;
1584 if (tab) trail.push({ label: tab, to: `${page}/${fourth}` });
1585 }
1586 } else if (second) {
1587 const repo = `/${owner}/${second}`;
1588 trail.push({ label: second, to: repo, mono: true });
1589 if (third === "pull" && fourth) trail.push({ label: `Pull request #${fourth}`, short: `#${fourth}`, to: `${repo}/pull/${fourth}` });
1590 else if (third === "issues" && fourth && fourth !== "new") trail.push({ label: `Issue #${fourth}`, short: `#${fourth}`, to: `${repo}/issues/${fourth}` });
1591 else if (third === "commit" && fourth) trail.push({ label: fourth.slice(0, 7), to: `${repo}/commit/${fourth}`, mono: true });
1592 else if (third && SECTIONS[third]) {
1593 trail.push({ label: SECTIONS[third]!, to: `${repo}/${third}` });
1594 // A settings page names which one: Settings / Secrets and variables.
1595 if (third === "settings" && fourth && SECTIONS[fourth]) {
1596 trail.push({ label: SETTINGS_SECTIONS[fourth] ?? SECTIONS[fourth]!, to: `${repo}/settings/${fourth}` });
1597 }
1598 }
1599 }
1600 if (trail.length === 0) trail.push({ label: "Overview", to: `/${owner}` });
1601 return <Trail trail={trail} />;
1602}
1603
1604/** A profile's place in the top bar: the person's avatar and @handle, from the page once it has loaded. */
1605function ProfileCrumb({ username }: { username: string }) {
1606 const page = useRouteLoaderData("routes/user") as { profile?: { username: string; displayUsername?: string | null; avatar: string | null } } | undefined;
1607 const profile = page?.profile?.username.toLowerCase() === username.toLowerCase() ? page.profile : null;
1608 return (
1609 <Breadcrumb className="min-w-0">
1610 <BreadcrumbList>
1611 <BreadcrumbItem>
1612 <BreadcrumbPage asChild className="flex items-center gap-2 hover:bg-raised">
1613 <Link to={`/u/${profile?.username ?? username}`}>
1614 <Avatar name={profile?.username ?? username} image={profile?.avatar ?? null} size={20} />
1615 <span className="truncate font-mono text-[0.8125rem]">@{profile ? shownUsername(profile) : username}</span>
1616 </Link>
1617 </BreadcrumbPage>
1618 </BreadcrumbItem>
1619 </BreadcrumbList>
1620 </Breadcrumb>
1621 );
1622}
1623
1624/** A page with no trail to it, such as Today or Search: its name alone. */
1625function Here({ children }: { children: ReactNode }) {
1626 return (
1627 <Breadcrumb className="min-w-0">
1628 <BreadcrumbList>
1629 <BreadcrumbItem>
1630 <BreadcrumbPage>{children}</BreadcrumbPage>
1631 </BreadcrumbItem>
1632 </BreadcrumbList>
1633 </Breadcrumb>
1634 );
1635}
1636
1637/** One link of the trail; `short` is what a phone shows when it is the page itself. */
1638type Crumb = { label: string; to: string; mono?: boolean; short?: string };
1639
1640/**
1641 * The trail of links. On a phone there is room for one: the page itself,
1642 * with a way back to where it sits; the whole trail from a wider screen up.
1643 */
1644function Trail({ trail }: { trail: Crumb[] }) {
1645 // Up on a phone, unless up is the workspace itself: its pages are the tabs.
1646 const up = trail.length > 1 && !/^\/[^/]+$/.test(trail[trail.length - 2]!.to) ? trail[trail.length - 2]! : null;
1647 return (
1648 <Breadcrumb className="flex min-w-0 items-center">
1649 {up && (
1650 <Button asChild variant="ghost" size="icon-bar" className="-ml-1 sm:hidden">
1651 <Link to={up.to} prefetch="intent" aria-label={`Back to ${up.label}`}>
1652 <ChevronLeft size={16} />
1653 </Link>
1654 </Button>
1655 )}
1656 <BreadcrumbList>
1657 {trail.map((crumb, index) => {
1658 const last = index === trail.length - 1;
1659 const label =
1660 last && crumb.short ? (
1661 <>
1662 <span className="sm:hidden">{crumb.short}</span>
1663 <span className="hidden sm:inline">{crumb.label}</span>
1664 </>
1665 ) : (
1666 crumb.label
1667 );
1668 const mono = crumb.mono ? "font-mono text-[0.8125rem]" : "";
1669 return (
1670 <Fragment key={index}>
1671 {index > 0 && <BreadcrumbSeparator className="max-sm:hidden" />}
1672 <BreadcrumbItem className={last ? "" : "max-sm:hidden"}>
1673 {last ? (
1674 // The page you are on is still a link: to its own top, as the trail always was.
1675 <BreadcrumbPage asChild className={`hover:bg-raised ${mono}`}>
1676 <Link to={crumb.to} prefetch="intent">
1677 {label}
1678 </Link>
1679 </BreadcrumbPage>
1680 ) : (
1681 <BreadcrumbLink asChild className={mono}>
1682 <Link to={crumb.to} prefetch="intent">
1683 {label}
1684 </Link>
1685 </BreadcrumbLink>
1686 )}
1687 </BreadcrumbItem>
1688 </Fragment>
1689 );
1690 })}
1691 </BreadcrumbList>
1692 </Breadcrumb>
1693 );
1694}
1695
1696type Command = PaletteCommand;
1697
1698/** Everything the palette can jump to, from what the sidebar already knows. */
1699function commandsFor(user: User, shell: ShellData): Command[] {
1700 const ws = shell.workspace;
1701 const commands: Command[] = [
1702 ...(ws
1703 ? [
1704 { label: "Home", to: homePagePath(ws.slug), icon: <House size={15} /> },
1705 { label: "Chat", to: `/${ws.slug}/-/chat`, icon: <MessagesSquare size={15} /> },
1706 { label: "Agents", to: `/${ws.slug}/-/agents`, icon: <Sparkles size={15} /> },
1707 ...(hasCodeAccess(ws) ? [{ label: "Code overview", to: `/${ws.slug}/-/overview`, icon: <Code2 size={15} /> }] : []),
1708 { label: "Artifacts", to: `/${ws.slug}/-/artifacts`, icon: <Shapes size={15} /> },
1709 { label: "Apps", hint: "Everything installed that you can use", to: `/${ws.slug}/-/apps`, icon: <LayoutGrid size={15} /> },
1710 { label: "Marketplace", hint: "Extensions and integrations to add", to: `/${ws.slug}/-/marketplace`, icon: <Store size={15} /> },
1711 { label: "Agent templates", hint: "Starting points for a new agent", to: `/${ws.slug}/-/agents/templates`, icon: <Bot size={15} /> },
1712 { label: "Workspace", hint: "Billing, policies, settings", to: `/${ws.slug}/-/workspace`, icon: <Building2 size={15} /> },
1713 ]
1714 : []),
1715 ...(shell.repos.length > 0
1716 ? [{ label: "Put an agent on it", hint: "Open an issue and assign g1t", to: "/?agent=new", icon: <Sparkles size={15} /> }]
1717 : []),
1718 { label: "Explore repositories", to: "/explore", icon: <Compass size={15} /> },
1719 { label: "Search g1t", hint: "Repositories, code, issues, people", to: "/search", icon: <Search size={15} /> },
1720 { label: "Notifications", hint: "What needs you", to: "/notifications", icon: <Bell size={15} /> },
1721 { label: "New project", to: "/new", icon: <Plus size={15} /> },
1722 { label: "New workspace", to: "/workspaces/new", icon: <Plus size={15} /> },
1723 { label: "Your settings", to: FIRST_SETTINGS_PAGE, icon: <Settings size={15} /> },
1724 ...(Object.keys(ACCOUNT_SETTINGS) as AccountSettingsPage[])
1725 .filter((page) => page !== "profile")
1726 .map((page) => ({ label: ACCOUNT_SETTINGS[page].title, hint: "Your settings", to: `/settings/${page}`, icon: <Settings size={15} /> })),
1727 ...THEME_COMMANDS,
1728 ];
1729 const repo = shell.repo;
1730 if (repo) {
1731 const base = `/${repo.namespace}/${repo.name}`;
1732 const name = `${repo.namespace}/${repo.name}`;
1733 commands.unshift(
1734 { label: "Overview", hint: name, to: base, icon: <LayoutGrid size={15} /> },
1735 { label: "Code", hint: name, to: `${base}/code`, icon: <Code2 size={15} /> },
1736 { label: "Issues", hint: name, to: `${base}/issues`, icon: <CircleDot size={15} /> },
1737 { label: "New issue", hint: name, to: `${base}/issues/new`, icon: <Plus size={15} /> },
1738 ...(repo.member
1739 ? [{ label: `Put an agent on ${repo.name}`, hint: name, to: `${base}/issues/new?agent=1`, icon: <Sparkles size={15} /> }]
1740 : []),
1741 { label: "Pull requests", hint: name, to: `${base}/pulls`, icon: <GitPullRequest size={15} /> },
1742 { label: "Commits", hint: name, to: `${base}/commits`, icon: <History size={15} /> },
1743 ...(repo.member
1744 ? [
1745 { label: "Plan work", hint: name, to: `${base}/plans`, icon: <ListTree size={15} /> },
1746 { label: "Deployments", hint: name, to: `${base}/deployments`, icon: <Rocket size={15} /> },
1747 { label: "Secrets and variables", hint: name, to: `${base}/settings/secrets`, icon: <Lock size={15} /> },
1748 { label: "Project settings", hint: name, to: `${base}/settings`, icon: <Settings size={15} /> },
1749 { label: "Repository settings", hint: name, to: `${base}/settings/repository`, icon: <Settings size={15} /> },
1750 ]
1751 : []),
1752 );
1753 }
1754 for (const membership of user.workspaces ?? []) {
1755 commands.push(
1756 { label: displayName(membership), hint: `Workspace · ${membership.slug}`, to: `/${membership.slug}`, icon: <Avatar name={membership.slug} image={membership.avatar} size={15} square /> },
1757 { label: "All projects", hint: membership.slug, to: `/${membership.slug}/-/projects`, icon: <LayoutGrid size={15} /> },
1758 { label: "People", hint: membership.slug, to: `/${membership.slug}/-/people`, icon: <Users size={15} /> },
1759 { label: "Spend", hint: `${membership.slug} · Budgets and receipts`, to: `/${membership.slug}/-/spend`, icon: <Coins size={15} /> },
1760 { label: "Usage", hint: membership.slug, to: `/${membership.slug}/-/usage`, icon: <BarChart3 size={15} /> },
1761 { label: "AI Gateway", hint: `${membership.slug} · Usage`, to: `/${membership.slug}/-/gateway`, icon: <Network size={15} /> },
1762 { label: "Billing and plans", hint: `${membership.slug} · Settings`, to: `/${membership.slug}/-/billing`, icon: <CreditCard size={15} /> },
1763 { label: "Access tokens", hint: `${membership.slug} · Settings`, to: `/${membership.slug}/-/tokens`, icon: <KeyRound size={15} /> },
1764 { label: "Integrations", hint: membership.slug, to: `/${membership.slug}/-/integrations`, icon: <Plug size={15} /> },
1765 { label: "Members", hint: `${membership.slug} · Access`, to: `/${membership.slug}/-/members`, icon: <Users size={15} /> },
1766 ...(membership.role === "owner"
1767 ? [
1768 { label: "Invitations", hint: `${membership.slug} · Access`, to: `/${membership.slug}/-/members/invitations`, icon: <Mail size={15} /> },
1769 { label: "Permissions", hint: `${membership.slug} · Access`, to: `/${membership.slug}/-/permissions`, icon: <ShieldCheck size={15} /> },
1770 ]
1771 : []),
1772 );
1773 }
1774 for (const listed of shell.repos) {
1775 commands.push({
1776 label: listed.title ?? listed.name,
1777 hint: `${listed.namespace} · Project`,
1778 to: `/${listed.namespace}/${listed.name}`,
1779 icon: <Box size={15} />,
1780 });
1781 }
1782 // "Put an agent on …": one per project, after the projects themselves.
1783 for (const listed of shell.repos) {
1784 if (repo && listed.namespace === repo.namespace && listed.name === repo.name) continue;
1785 commands.push({
1786 label: `Put an agent on ${listed.title ?? listed.name}`,
1787 hint: `${listed.namespace}/${listed.name}`,
1788 to: `/${listed.namespace}/${listed.name}/issues/new?agent=1`,
1789 icon: <Sparkles size={15} />,
1790 });
1791 }
1792 return commands;
1793}
1794
1795/**
1796 * The page while the next one loads: after a moment it dims, under the
1797 * bar below, so it is plainly on its way out rather than frozen, and the
1798 * next page fades up from there. Sending a form does not dim it: the
1799 * form's button says it is working. Spread on the element holding the page.
1800 */
1801export function useLeaving() {
1802 const navigation = useNavigation();
1803 const method = navigation.formMethod?.toUpperCase();
1804 const leaving = navigation.state === "loading" && (method == null || method === "GET");
1805 return {
1806 "aria-busy": leaving || undefined,
1807 className: `transition-opacity motion-reduce:transition-none ${leaving ? "opacity-60 delay-200 duration-300" : "duration-150"}`,
1808 };
1809}
1810
1811/**
1812 * A bar across the top of the page while the next one loads, as GitHub
1813 * has: it appears at once, creeps towards the end while waiting, then fills
1814 * and fades when the page arrives.
1815 */
1816export function Progress() {
1817 const navigation = useNavigation();
1818 const busy = navigation.state !== "idle";
1819 const [width, setWidth] = useState(0);
1820 const [visible, setVisible] = useState(false);
1821 useEffect(() => {
1822 if (busy) {
1823 setVisible(true);
1824 setWidth(12);
1825 // Slows as it goes, never quite arriving until the page does.
1826 const timer = setInterval(() => setWidth((now) => now + (90 - now) * 0.12), 200);
1827 return () => clearInterval(timer);
1828 }
1829 setWidth((now) => (now > 0 ? 100 : 0));
1830 const fade = setTimeout(() => setVisible(false), 250);
1831 const reset = setTimeout(() => setWidth(0), 550);
1832 return () => {
1833 clearTimeout(fade);
1834 clearTimeout(reset);
1835 };
1836 }, [busy]);
1837 return (
1838 <div
1839 aria-hidden="true"
1840 className={`pointer-events-none fixed inset-x-0 top-0 z-[60] h-[3px] transition-opacity duration-300 ${
1841 visible ? "opacity-100" : "opacity-0"
1842 }`}
1843 >
1844 <div
1845 className="h-full bg-accent shadow-[0_0_10px_var(--color-accent)] transition-[width] duration-200 ease-out"
1846 style={{ width: `${width}%` }}
1847 />
1848 </div>
1849 );
1850}
1851
1852/**
1853 * The top bar's way to g1t: the direct message with the workspace's
1854 * orchestrator, opened or made. The one tinted control in the bar: the
1855 * lavender pixel 1 bare beside its words, on a wash of the accent.
1856 */
1857function AskG1tButton({ slug }: { slug: string }) {
1858 return (
1859 <Hint label="Ask g1t">
1860 <Button asChild variant="soft" size="bar" className="gap-2 max-md:ring-0 lg:px-3">
1861 <Link to={`/${slug}/-/chat?agent=g1t`} aria-label="Ask g1t">
1862 <MarkGlyph className="h-3.5" />
1863 <span className="max-lg:hidden">Ask g1t</span>
1864 </Link>
1865 </Button>
1866 </Hint>
1867 );
1868}
1869
1870/**
1871 * Which sidebar sits beside the page: each mode's own, or none. Home and
1872 * Apps are pages at full width, and so are g1t's public pages, such as a
1873 * profile, which are no workspace's. Without a workspace, only your own
1874 * settings and Notifications have one.
1875 */
1876function sidebarFor(mode: ModeKey, workspace: boolean): Panel | null {
1877 if (!workspace) return mode === "account" || mode === "notifications" ? mode : null;
1878 if (mode === "home" || mode === "apps" || mode === "site") return null;
1879 return mode;
1880}
1881
1882/** The sidebars that sit beside the page, one per mode that has one. */
1883type Panel = "chat" | "artifacts" | "agents" | "code" | "notifications" | "people" | "workspace" | "account";
1884
1885/** Each sidebar's name, for the button that opens it on a phone. */
1886const MODE_MENU: Record<Panel, string> = {
1887 chat: "Chat",
1888 artifacts: "Artifacts",
1889 agents: "Agents",
1890 code: "Code",
1891 notifications: "Notifications",
1892 people: "People",
1893 workspace: "Workspace",
1894 account: "Your account",
1895};
1896
1897/** Whether a key press happened in something you type into, where Ctrl B is the editor's. */
1898function typing(target: EventTarget | null): boolean {
1899 if (!(target instanceof HTMLElement)) return false;
1900 return target.isContentEditable || target.closest("input, textarea, select, [contenteditable=''], [contenteditable='true'], [role='textbox']") != null;
1901}
1902
1903/** Ctrl B (⌘B on a Mac) shows or hides the sidebar, except while typing. */
1904function useSidebarShortcut(toggle: () => void) {
1905 useEffect(() => {
1906 const onKey = (event: KeyboardEvent) => {
1907 if (event.key.toLowerCase() !== "b" || event.altKey || event.shiftKey || !(event.ctrlKey || event.metaKey)) return;
1908 if (event.defaultPrevented || typing(event.target)) return;
1909 event.preventDefault();
1910 toggle();
1911 };
1912 window.addEventListener("keydown", onKey);
1913 return () => window.removeEventListener("keydown", onKey);
1914 }, [toggle]);
1915}
1916
1917/**
1918 * Search or jump to: the command palette. On a computer it looks like the
1919 * field it opens, with its shortcut; on a phone, a magnifier.
1920 */
1921function SearchButton({ onClick, place }: { onClick: () => void; place: "bar" | "sidebar" }) {
1922 const field = (
1923 <Button
1924 variant="outline"
1925 size="sm"
1926 aria-label="Search or jump to"
1927 onClick={onClick}
1928 className={
1929 place === "sidebar"
1930 ? "w-full justify-start bg-bg font-normal text-faint hover:bg-bg hover:text-muted"
1931 : "mr-1 w-[min(18rem,26vw)] justify-start bg-surface font-normal text-faint hover:bg-surface hover:text-muted max-md:hidden"
1932 }
1933 >
1934 <Search size={15} />
1935 <span className="grow truncate text-left">Search or jump to</span>
1936 <PaletteKey className="px-1.5 text-[0.625rem] leading-4 text-muted" />
1937 </Button>
1938 );
1939 if (place === "sidebar") return field;
1940 return (
1941 <>
1942 <Button variant="ghost" size="icon-bar" aria-label="Search or jump to" onClick={onClick} className="md:hidden">
1943 <Search size={18} />
1944 </Button>
1945 {field}
1946 </>
1947 );
1948}
1949
1950/** The sidebar's shortcut, for the hint on its toggle. */
1951function useSidebarKey(): string {
1952 return sidebarKeyLabel(typeof navigator === "undefined" ? null : navigator.platform);
1953}
1954
1955/**
1956 * The app: three surfaces that never blur together. The rail, a narrow
1957 * column of icons down the window's left edge; the mode's sidebar, flat
1958 * against it with a hairline between, which folds away with Ctrl B and is
1959 * a drawer below 1024px; and the page, flat against the sidebar and
1960 * filling the rest of the window, with its top bar across the top and a
1961 * line under it: the sidebar's toggle, where you are, search, Ask g1t and
1962 * Create new. On a phone the rail is a bar along the bottom and the page
1963 * fills the window above it, flat as well. Only for someone signed in; without a workspace yet, there
1964 * is no rail. The rail and the sidebar are drawn from the sidebar kit
1965 * (components/ui/sidebar.tsx): one provider holds whether the sidebar is
1966 * open on a computer and whether the drawer is.
1967 */
1968export function AppShell({
1969 user,
1970 shell,
1971 missing = false,
1972 banner,
1973 sidebarClosed = false,
1974 children,
1975}: {
1976 user: User;
1977 shell: ShellData;
1978 /** The page is a 404 (see CodeSidebar). */
1979 missing?: boolean;
1980 banner?: ReactNode;
1981 /** Whether the person folded the sidebar away, as their cookie says. */
1982 sidebarClosed?: boolean;
1983 children: ReactNode;
1984}) {
1985 const { pathname } = useLocation();
1986 const [drawer, setDrawer] = useState(false);
1987 const [closed, setClosed] = useState(sidebarClosed);
1988 const [palette, setPalette] = useState(false);
1989 const commands = useMemo(() => commandsFor(user, shell), [user, shell]);
1990
1991 // A new page closes the drawer.
1992 useEffect(() => setDrawer(false), [pathname]);
1993 usePaletteShortcut(() => setPalette((open) => !open));
1994 const leaving = useLeaving();
1995 useVisualViewport();
1996 const going = useNavigation().location?.pathname;
1997 const ws = shell.workspace;
1998 const mode = modeOf(going ?? pathname, ws?.slug ?? null);
1999 const panel = sidebarFor(mode, ws != null);
2000 const code = ws ? hasCodeAccess(ws) : false;
2001 const { sidebar: chatSidebar } = useChatSidebar();
2002 // Notify: the feed socket's live counts (lib/notify-client.ts) once it has them; the page's until then.
2003 const live = useLiveBadges(ws?.slug);
2004 const chatUnread = chatSidebar
2005 ? unreadTotals(chatSidebar.entries)
2006 : live?.chat != null
2007 ? { unread: live.chat, mentions: live.mentions ?? 0 }
2008 : (shell.chat ?? { unread: 0, mentions: 0 });
2009 const notificationsUnread = live?.inbox ?? shell.inbox?.unread ?? 0;
2010 const unread = { notifications: notificationsUnread, chat: chatUnread.unread, mentions: chatUnread.mentions };
2011
2012 // Folding the sidebar away on a computer is remembered, so the next page is drawn the same from the server.
2013 const toggleSidebar = useCallback(() => {
2014 if (!window.matchMedia("(min-width: 1024px)").matches) {
2015 setDrawer((open) => !open);
2016 return;
2017 }
2018 setClosed((was) => {
2019 document.cookie = sidebarCookie(!was, window.location.protocol === "https:");
2020 return !was;
2021 });
2022 }, []);
2023 useSidebarShortcut(useCallback(() => {
2024 if (panel) toggleSidebar();
2025 }, [panel, toggleSidebar]));
2026
2027 const inline = panel != null && !closed;
2028 const sidebarNode = () => {
2029 if (!panel) return null;
2030 if (!ws) return panel === "notifications" ? <NotificationsSidebar counts={shell.inbox ?? null} /> : <AccountSidebar username={user.username} />;
2031 switch (panel) {
2032 case "code":
2033 return <CodeSidebar user={user} shell={shell} missing={missing} />;
2034 case "chat":
2035 return <ChatSidebar slug={ws.slug} />;
2036 case "artifacts":
2037 return <FoliosSidebar slug={ws.slug} />;
2038 case "agents":
2039 return <AgentsSidebar slug={ws.slug} shellAgents={shell.agents ?? null} code={code} owner={ws.role === "owner"} />;
2040 case "notifications":
2041 return <NotificationsSidebar counts={shell.inbox ?? null} />;
2042 case "people":
2043 return <PeopleSidebar slug={ws.slug} />;
2044 case "workspace":
2045 return <WorkspaceSidebar slug={ws.slug} owner={ws.role === "owner"} />;
2046 case "account":
2047 return <AccountSidebar username={user.username} />;
2048 }
2049 };
2050 const sidebarKey = useSidebarKey();
2051 // Search or jump to sits at the top of the sidebar, except in Chat and
2052 // Artifacts, whose sidebars search their own lists: there it stays in the bar.
2053 const sidebarSearch = panel != null && panel !== "chat" && panel !== "artifacts";
2054 // The sidebar's head: the workspace and its switcher, the way to fold the
2055 // sidebar or close the drawer, and search, which opens the palette.
2056 const sidebarTop = (inDrawer: boolean) => (
2057 <SidebarHeader className="gap-1 px-2 pt-0 pb-2">
2058 <div className="flex h-14 shrink-0 items-center gap-1">
2059 {ws ? (
2060 <WorkspaceSwitcher user={user} workspace={ws} />
2061 ) : (
2062 <Link to="/" aria-label="g1t" className="mr-auto flex h-9 items-center rounded-md px-2">
2063 <Logo className="text-[1.125rem]" />
2064 </Link>
2065 )}
2066 {inDrawer ? (
2067 <Button type="button" aria-label="Close menu" onClick={() => setDrawer(false)} variant="ghost" size="icon-sm" className="text-faint">
2068 <X size={16} />
2069 </Button>
2070 ) : (
2071 <SidebarTrigger hint={`Hide the sidebar (${sidebarKey})`} className="text-faint" />
2072 )}
2073 </div>
2074 {sidebarSearch && <SearchButton place="sidebar" onClick={() => setPalette(true)} />}
2075 </SidebarHeader>
2076 );
2077
2078 // On a phone (below 768px): the bottom bar, and a conversation full screen.
2079 const conversation = isConversation(going ?? pathname);
2080 // Where the page panel starts: 8px past the rail (56px), or 8px past the sidebar (56 + 240px) when it is open.
2081 // The page starts where the rail (3.5rem) and, open, the sidebar (15rem) end.
2082 const pad = ws ? (inline ? "md:pl-14 lg:pl-[18.5rem]" : "md:pl-14") : inline ? "lg:pl-[15rem]" : "";
2083
2084 return (
2085 <SidebarProvider open={!closed} onOpenChange={(open) => setClosed(!open)} openMobile={drawer} onOpenMobileChange={setDrawer} toggleSidebar={toggleSidebar}>
2086 <Progress />
2087 {ws && (
2088 <div className="fixed inset-y-0 left-0 z-40 hidden md:block">
2089 <Rail workspace={ws} pins={shell.pins ?? []} unread={unread} account={<AccountMenu user={user} />} />
2090 </div>
2091 )}
2092 {panel && (
2093 <Sidebar
2094 role="complementary"
2095 aria-label={`${MODE_MENU[panel]} sidebar`}
2096 className={`fixed inset-y-0 z-40 max-lg:hidden ${ws ? "left-14" : "left-0"}`}
2097 >
2098 {sidebarTop(false)}
2099 <div className="min-h-0 grow">{sidebarNode()}</div>
2100 </Sidebar>
2101 )}
2102 {/* The drawer is a sheet: a dialog that holds focus, closes on Escape or
2103 a tap outside, and gives focus back to the button that opened it. */}
2104 {panel && (
2105 <SidebarMobile title={`${MODE_MENU[panel]} menu`} className="pb-[env(safe-area-inset-bottom)] max-md:[&_nav_a]:min-h-10">
2106 {sidebarTop(true)}
2107 <div className="min-h-0 grow">{sidebarNode()}</div>
2108 </SidebarMobile>
2109 )}
2110
2111 <div className={`min-h-dvh pt-(--frame-top) pb-(--tabbar-h) ${pad}`}>
2112 {/* The top bar always has its line, so a page's own header (data-page-head: a conversation's, a project's,
2113 a sticky one under an open artifact) sits under it as its own band. */}
2114 <div className="flex min-h-[calc(100dvh-var(--frame-top)-var(--tabbar-h))] min-w-0 flex-col bg-bg">
2115 <header
2116 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" : ""}`}
2117 >
2118 {panel && (
2119 <SidebarTrigger
2120 hint={`Show the sidebar (${sidebarKey})`}
2121 aria-label={drawer ? "Hide the sidebar" : "Show the sidebar"}
2122 aria-expanded={drawer}
2123 className={`max-md:size-11 ${inline ? "lg:hidden" : ""}`}
2124 />
2125 )}
2126 {ws && (
2127 <span className={`flex min-w-0 shrink items-center gap-1.5 ${inline ? "lg:hidden" : ""}`}>
2128 <WorkspaceSwitcher user={user} workspace={ws} compact />
2129 <span aria-hidden="true" className="text-line-strong">
2130 /
2131 </span>
2132 </span>
2133 )}
2134 <Breadcrumbs pathname={pathname} missing={missing} repo={shell.repo} workspace={ws?.slug ?? null} />
2135 {/* Search, then what's yours (spend, Ask g1t), then the bell and Create new: one height, one rhythm. */}
2136 <div className="ml-auto flex shrink-0 items-center gap-1 md:gap-1.5">
2137 {/* With the sidebar open, search is at its top. */}
2138 <span className={`flex ${inline && sidebarSearch ? "lg:hidden" : ""}`}>
2139 <SearchButton place="bar" onClick={() => setPalette(true)} />
2140 </span>
2141 {/* Your spend this month, or the workspace's for owners and billing managers; on a phone it is on Spend. */}
2142 {ws && (
2143 <span className="flex max-md:hidden">
2144 <SpendPill slug={ws.slug} mayWorkspace={ws.role === "owner" || !!ws.org_roles?.includes("billing_manager")} />
2145 </span>
2146 )}
2147 {ws && <AskG1tButton slug={ws.slug} />}
2148 <Separator orientation="vertical" className="mx-1 data-[orientation=vertical]:h-5 max-md:hidden" />
2149 {/* On a phone, Notifications is in the bottom bar. */}
2150 <span className="flex max-md:hidden">
2151 <NotificationsBell counts={shell.inbox ? { ...shell.inbox, unread: notificationsUnread } : null} />
2152 </span>
2153 <CreateMenu shell={shell} />
2154 {/* Without a workspace there is no rail: the account is here. */}
2155 {!ws && <AccountMenu user={user} side="bottom" />}
2156 </div>
2157 </header>
2158 {banner}
2159 <main id="content" tabIndex={-1} {...leaving} className={`min-w-0 grow outline-none ${leaving.className}`}>
2160 <InMain.Provider value={true}>{children}</InMain.Provider>
2161 </main>
2162 </div>
2163 </div>
2164 {ws && <BottomBar user={user} workspace={ws} pins={shell.pins ?? []} unread={unread} onReselect={panel ? () => setDrawer(true) : undefined} />}
2165 <CommandPalette open={palette} onOpenChange={setPalette} commands={commands} repo={shell.repo ? `${shell.repo.namespace}/${shell.repo.name}` : null} />
2166 </SidebarProvider>
2167 );
2168}
2169
2170/** Create new: a project, an issue in the one you are in, a workspace or a team. */
2171function CreateMenu({ shell }: { shell: ShellData }) {
2172 return (
2173 <DropdownMenu>
2174 <Hint label="Create new">
2175 <DropdownMenuTrigger asChild>
2176 <Button variant="ghost" size="bar" aria-label="Create new" className="gap-0.5 px-1.5 text-fg/90">
2177 <Plus size={17} className="max-md:size-5" />
2178 <ChevronDown size={12} className="text-faint max-md:hidden" />
2179 </Button>
2180 </DropdownMenuTrigger>
2181 </Hint>
2182 <DropdownMenuContent align="end" className="min-w-52">
2183 {shell.repo && (
2184 <>
2185 <DropdownMenuLabel className="truncate">In {shell.repo.name}</DropdownMenuLabel>
2186 <DropdownMenuItem asChild>
2187 <Link to={`/${shell.repo.namespace}/${shell.repo.name}/issues/new`}>
2188 <CircleDot />
2189 New issue
2190 </Link>
2191 </DropdownMenuItem>
2192 {shell.repo.member && (
2193 <DropdownMenuItem asChild>
2194 <Link to={`/${shell.repo.namespace}/${shell.repo.name}/plans`}>
2195 <ListTree />
2196 Plan work
2197 </Link>
2198 </DropdownMenuItem>
2199 )}
2200 <DropdownMenuSeparator />
2201 </>
2202 )}
2203 <DropdownMenuItem asChild>
2204 <Link to="/?agent=new">
2205 <Sparkles />
2206 Put an agent on it
2207 </Link>
2208 </DropdownMenuItem>
2209 <DropdownMenuItem asChild>
2210 <Link to="/new">
2211 <Box />
2212 New project
2213 </Link>
2214 </DropdownMenuItem>
2215 <DropdownMenuItem asChild>
2216 <Link to="/new/github">
2217 <GitBranch />
2218 Import from GitHub
2219 </Link>
2220 </DropdownMenuItem>
2221 <DropdownMenuSeparator />
2222 <DropdownMenuItem asChild>
2223 <Link to="/workspaces/new">
2224 <Users />
2225 New workspace
2226 </Link>
2227 </DropdownMenuItem>
2228 {/* A team in the workspace you are in, for whoever it lets create one. */}
2229 {shell.workspace &&
2230 (mayCreateTeams(shell.workspace.team_creation, shell.workspace.role) ? (
2231 <DropdownMenuItem asChild>
2232 <Link to={`/${shell.workspace.slug}/-/teams/new`}>
2233 <UsersRound />
2234 New team
2235 </Link>
2236 </DropdownMenuItem>
2237 ) : (
2238 <DropdownMenuItem disabled>
2239 <UsersRound />
2240 New team
2241 <span className="ml-auto pl-3 text-xs text-faint">Owners only</span>
2242 </DropdownMenuItem>
2243 ))}
2244 </DropdownMenuContent>
2245 </DropdownMenu>
2246 );
2247}