Skip to content

g1t/apps/sudo/app/lib/nav.ts

372 lines15,306 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

A menu shaped by how g1t works, Soon pages for every promise, and sudo for sales1/**
2 * sudo's navigation, and the roadmap for what g1t is building in house:
3 * its own CRM and back office, in place of bought ones. Each item is a
4 * real page. One marked `soon` renders a placeholder that says what it
5 * will do and why, so staff can see where sudo is going (routes.ts makes
6 * a route for each). No Workers or React imports, so it can be tested
7 * under Node.
8 */
9
10/** The icon a sidebar item shows; components/shell.tsx draws each one. */
11export type NavIcon =
12 | "overview"
13 | "workspaces"
14 | "enterprises"
15 | "reach-out"
16 | "people"
17 | "invoices"
18 | "prices"
19 | "credits"
20 | "usage"
21 | "stripe"
22 | "costs"
23 | "agents"
24 | "abuse"
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas25 | "incidents"
A menu shaped by how g1t works, Soon pages for every promise, and sudo for sales26 | "inbox"
27 | "view-as"
28 | "announcements"
29 | "staff"
30 | "audit"
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look31 | "requests"
32 | "overages"
33 | "velocity"
34 | "invites"
A menu shaped by how g1t works, Soon pages for every promise, and sudo for sales35 // Sections
36 | "customers"
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look37 | "spend"
A menu shaped by how g1t works, Soon pages for every promise, and sudo for sales38 | "revenue"
39 | "platform"
40 | "support"
41 | "team";
42
43/** What a page that is not built yet says about itself. */
44export type Roadmap = {
45 /** What it will do and why, two to four sentences. */
46 summary: string[];
47 /** What it will have, one line each. */
48 plans: string[];
49 /** Something staff should know now, such as where to go meanwhile. */
50 meanwhile?: { text: string; to?: string; link?: string };
51};
52
53export type NavItem = {
54 label: string;
55 /** Where it lives. A `soon` item's page is the placeholder. */
56 to: string;
57 icon: NavIcon;
58 /** One line, shown on hover. */
59 about: string;
60 /** Other paths under which this item is the current one. */
61 also?: string[];
62 /** Not built yet: the page says what it will be. */
63 soon?: Roadmap;
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas64 /** A number the sidebar shows beside it while it is above zero, such as requests waiting. */
65 count?: NavCount;
A menu shaped by how g1t works, Soon pages for every promise, and sudo for sales66};
67
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas68/** The numbers the sidebar can show, read by root.tsx on every page. */
69export type NavCount = "waitlist" | "incidents";
70
71export type NavCounts = Partial<Record<NavCount, number>>;
72
73/** What a page or a folded section shows beside it: its items' counts, added up. */
74export function countFor(items: Pick<NavItem, "count">[], counts: NavCounts): number {
75 return items.reduce((sum, item) => sum + (item.count ? (counts[item.count] ?? 0) : 0), 0);
76}
77
A menu shaped by how g1t works, Soon pages for every promise, and sudo for sales78/**
79 * A section of the sidebar: a row with an icon that opens to its pages,
80 * as GitLab and Vercel fold theirs. One with no title is top-level links.
81 */
82export type NavGroup = { title: string | null; icon?: NavIcon; items: NavItem[] };
83
84export const NAV: NavGroup[] = [
85 {
86 title: null,
87 items: [
88 { label: "Overview", to: "/", icon: "overview", about: "The business at a glance: this month, the last six, and who needs a word." },
89 { label: "Reach out", to: "/reach-out", icon: "reach-out", about: "Who is worth a word now, and who on the team has it." },
90 ],
91 },
92 {
93 title: "Customers",
94 icon: "customers",
95 items: [
96 { label: "Workspaces", to: "/workspaces", icon: "workspaces", about: "Every workspace, who owns it, and how it pays." },
97 { label: "Enterprises", to: "/enterprises", icon: "enterprises", about: "Customers paying for several workspaces with one bill." },
98 {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look99 label: "Invites",
100 to: "/invites",
101 icon: "invites",
102 about: "The waitlist, every invite, more invites for a person or workspace, and who invited whom.",
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas103 count: "waitlist",
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look104 },
105 {
A menu shaped by how g1t works, Soon pages for every promise, and sudo for sales106 label: "People",
107 to: "/people",
108 icon: "people",
109 about: "Everyone with a g1t account, across the workspaces they belong to.",
110 soon: {
111 summary: [
112 "Every person with a g1t account, not just the workspaces they belong to. Support starts from a person far more often than from a workspace: someone writes in from an email address, and staff need to find them, see which workspaces they own or belong to, and what they did lately.",
113 "It gives sales a view of contacts as well as accounts: the owner who signs, the engineer who brought g1t in, and who to ask when a workspace goes quiet.",
114 ],
115 plans: [
116 "Search by username, email or name, across every account",
117 "A person's page: their workspaces and role in each, sign-ins, verified email, two-factor status",
118 "Contacts on a workspace: who is the buyer, who is technical, who to bill",
119 "Merge duplicate accounts, and resend or change a verification email, each recorded",
120 ],
121 meanwhile: { text: "Search a workspace by an owner's username or email on Workspaces.", to: "/workspaces", link: "Workspaces" },
122 },
123 },
124 ],
125 },
126 {
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look127 title: "Spend",
128 icon: "spend",
129 items: [
130 {
131 label: "Requests",
132 to: "/requests",
133 icon: "requests",
134 about: "Owners asking for a higher limit or help with a month: answered within one business day.",
135 },
136 {
137 label: "Overages",
138 to: "/overages",
139 icon: "overages",
140 about: "Workspaces well past their typical month, what caused it, and goodwill credits.",
141 },
142 {
143 label: "Velocity",
144 to: "/velocity",
145 icon: "velocity",
146 about: "Who is spending fastest right now, against their usual hour, and any spikes.",
147 },
148 ],
149 },
150 {
A menu shaped by how g1t works, Soon pages for every promise, and sudo for sales151 title: "Revenue",
152 icon: "revenue",
153 items: [
154 {
155 label: "Invoices",
156 to: "/invoices",
157 icon: "invoices",
158 about: "Every invoice g1t has sent, to workspaces and enterprises.",
159 },
160 {
161 label: "Plans & prices",
162 to: "/prices",
163 icon: "prices",
164 about: "The price book: what each meter costs g1t and what it sells for.",
165 soon: {
166 summary: [
167 "The price book, edited in sudo instead of in code. Every metered unit (sandbox seconds, builds, app requests and CPU, app-months) has what it costs g1t and what g1t sells it for, and the price follows the cost with a markup.",
168 "Changing a markup or a plan's price is a decision finance makes and should be able to make safely: previewed against last month's usage, with a date it takes effect, and recorded with who made it and why.",
169 ],
170 plans: [
171 "Each meter's cost, markup and price, and where the cost came from (Cloudflare's list price or its bill)",
172 "Edit a markup or a plan's monthly price, with a preview of what last month would have charged",
173 "Schedule a change for the start of a month, so no one is charged mid-month on a new price",
174 "Every change in the history the public pricing page already shows",
175 ],
176 },
177 },
178 {
179 label: "Credits & refunds",
180 to: "/credits",
181 icon: "credits",
Billing: credits with a kind and expiry, discounts instead of comped, and safer charging182 about: "Every credit staff have given (promotional, goodwill, refunds), what was used, and each month by kind.",
A menu shaped by how g1t works, Soon pages for every promise, and sudo for sales183 },
184 {
185 label: "Usage explorer",
186 to: "/usage",
187 icon: "usage",
188 about: "What customers used, sliced by meter, model, repository and day.",
189 soon: {
190 summary: [
191 "What customers used, across every workspace, sliced any way: by meter, model, repository, task and day. It answers the questions that come up in a sales call or a cost review: who uses the most sandbox time, which model costs most, what a customer's agents spend per pull request.",
192 "Billing records every run and sandbox second with its cost and charge already. This puts it in front of the people who need it, without a query.",
193 ],
194 plans: [
195 "Charged, cost and margin over any range, for everyone or one customer",
196 "Group by meter, model, task, repository or workspace; compare two periods",
197 "The heaviest workspaces this month, and how fast each is growing",
198 "Export to CSV",
199 ],
200 },
201 },
202 ],
203 },
204 {
205 title: "Platform",
206 icon: "platform",
207 items: [
208 { label: "Stripe", to: "/stripe", icon: "stripe", about: "Billing's Stripe keys, webhook, and the events Stripe sent." },
209 {
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily210 label: "Costs & margin",
A menu shaped by how g1t works, Soon pages for every promise, and sudo for sales211 to: "/costs",
212 icon: "costs",
Costs: Cloudflare's subscriptions read from Cloudflare each day, the estimate only until then; sudo's costs split into Costs & margin and Bill & pricing213 about: "Where g1t's money goes, with what it gave away kept apart; on Bill & pricing, Cloudflare's bill, drift and the price book.",
A menu shaped by how g1t works, Soon pages for every promise, and sudo for sales214 },
215 {
216 label: "Agents & models",
217 to: "/agents",
218 icon: "agents",
219 about: "The models agents run on, what each costs, and how runs are going.",
220 soon: {
221 summary: [
222 "The models g1t's agents run on, and how they are doing: runs, failures, tokens and cost per model, and which workspaces bring their own provider. It is where staff decide which models to offer and see what a change in a provider's price means.",
223 "Hosted models are open to some workspaces and not others; that list belongs here, edited and recorded, not in configuration.",
224 ],
225 plans: [
226 "Runs, failures and cost per model, per day",
227 "Who may use g1t's hosted models, and the free allowance's pool",
Prices are what g1t pays plus 20%, from the first second228 "Workspaces on their own provider, and the sandbox time their runs use",
A menu shaped by how g1t works, Soon pages for every promise, and sudo for sales229 "Stuck or long-running agents, with a way to stop one",
230 ],
231 },
232 },
233 {
234 label: "Abuse & fraud",
235 to: "/abuse",
236 icon: "abuse",
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look237 about: "Sandboxes stopped for looking like mining, and disputes and declines.",
A menu shaped by how g1t works, Soon pages for every promise, and sudo for sales238 },
status.g1t.sh with incident management, invites that land you in the workspace, settings as pages, usage without quotas239 {
240 label: "Incidents",
241 to: "/incidents",
242 icon: "incidents",
243 about: "Declare and run incidents, schedule maintenance, and publish postmortems on status.g1t.sh.",
244 count: "incidents",
245 },
A menu shaped by how g1t works, Soon pages for every promise, and sudo for sales246 ],
247 },
248 {
249 title: "Support",
250 icon: "support",
251 items: [
252 {
253 label: "Inbox",
254 to: "/inbox",
255 icon: "inbox",
256 about: "Customers' messages, beside everything about who sent them.",
257 soon: {
258 summary: [
259 "Customers' email and in-app messages in one queue, each beside everything sudo knows about who sent it: their workspaces, what they pay, their limit, their last invoice, and the notes sales kept. Support answers faster when nothing needs looking up.",
260 "Built in house so a conversation can become an action without leaving it: a credit, a billing link, a note on the workspace.",
261 ],
262 plans: [
263 "Assign, snooze and close conversations; see who is answering what",
264 "The sender's workspaces, plan, limit and recent invoices alongside",
265 "Saved replies, and links that open the right page in g1t",
266 "Response times by person and by week",
267 ],
268 },
269 },
270 {
271 label: "View as customer",
272 to: "/view-as",
273 icon: "view-as",
274 about: "See g1t as a customer sees it, audited and time-limited.",
275 soon: {
276 summary: [
277 "See g1t exactly as a customer sees it, to reproduce what they describe. Read-only by default, it is the most sensitive thing staff can do, so it is built to be safe first.",
278 "Every session will be audited and time-limited: it needs a reason, it ends on its own, the customer's own audit log says that g1t staff looked, and nothing can be changed or any secret read while viewing.",
279 ],
280 plans: [
281 "Start a session with a reason (a support conversation or a note); it ends after 30 minutes",
282 "Read-only: no pushes, no settings, no secrets, no billing changes",
283 "A banner on every page while it lasts, and a record in the customer's audit log",
284 "Only roles allowed to, and a list of every session for review",
285 ],
286 },
287 },
288 {
289 label: "Announcements",
290 to: "/announcements",
291 icon: "announcements",
292 about: "Banners and notices for customers: incidents, maintenance, changes.",
293 soon: {
294 summary: [
295 "Tell customers what they need to know, from one place: a banner for an incident or maintenance, a notice about a price change, an email to the owners of the workspaces a change affects.",
296 "Notices can go to everyone or to a slice (owners on an enterprise, workspaces near their limit), with a start and an end, and a record of who sent what.",
297 ],
298 plans: [
299 "Banners in g1t with a start, an end, and a severity",
300 "Email to owners of chosen workspaces, previewed before it goes",
301 "Price-change notices with the notice period the terms require",
302 "A history of everything announced",
303 ],
304 },
305 },
306 ],
307 },
308 {
309 title: "Team",
310 icon: "team",
311 items: [
312 {
313 label: "Staff & roles",
314 to: "/staff",
315 icon: "staff",
316 about: "Who is staff, and what each role may do.",
317 soon: {
318 summary: [
319 "Who is g1t staff and what each of them may do. Today everyone in STAFF_EMAILS may do everything; as the team grows, roles should match the work: sales can see accounts and keep notes but cannot credit, support can make billing links and small credits, finance can change terms and issue refunds.",
320 "Access still decides who gets in. Roles decide what they can do once there, and every refusal is recorded like every change.",
321 ],
322 plans: [
323 "Roles (sales, support, finance, admin) with the permissions each grants",
324 "Per-role limits on money: the most a credit can be without a second person",
325 "Assign roles by email, recorded, with the date each was given",
326 "A second person's approval for comped terms and large credits",
327 ],
328 },
329 },
330 {
331 label: "Audit log",
332 to: "/audit",
333 icon: "audit",
334 about: "Every change made in sudo, by whom, across every customer.",
335 },
336 ],
337 },
338];
339
340/** Whether a section holds the page at `pathname`, so it is drawn open. */
341export function holdsCurrent(group: NavGroup, pathname: string): boolean {
342 return group.items.some((item) => isCurrent(item, pathname));
343}
344
345/** Every item, in sidebar order. */
346export function navItems(nav: NavGroup[] = NAV): NavItem[] {
347 return nav.flatMap((group) => group.items);
348}
349
350/** The items not built yet, each with the placeholder page routes.ts makes. */
351export function soonItems(nav: NavGroup[] = NAV): (NavItem & { soon: Roadmap })[] {
352 return navItems(nav).filter((item): item is NavItem & { soon: Roadmap } => item.soon != null);
353}
354
355/** The item for a path, if one is its page. */
356export function soonFor(pathname: string, nav: NavGroup[] = NAV): (NavItem & { soon: Roadmap }) | null {
357 const path = pathname.replace(/\/+$/, "") || "/";
358 return soonItems(nav).find((item) => item.to === path) ?? null;
359}
360
361/**
362 * Whether `item` is the current page at `pathname`: its own path or one
363 * beneath it. `/` is current only on itself.
364 */
365export function isCurrent(item: Pick<NavItem, "to" | "also">, pathname: string): boolean {
366 const path = pathname.replace(/\/+$/, "") || "/";
367 return [item.to, ...(item.also ?? [])].some((prefix) => {
368 const base = prefix.split("?")[0];
369 if (base === "/") return path === "/";
370 return path === base || path.startsWith(`${base}/`);
371 });
372}