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