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