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