project-page.tsx
This file
Path
apps/web/src/features/project/project-page.tsx
572 lines · 16.3 KiB · TypeScript
Last changed by
Merge redesign into mainoscabrielbefore adoptioncaedd21
History of this fileTake it
1import { IMPORTED_NOTE } from "@repo/agent-kit/docs/imported-note";2import { Brand } from "@repo/brand";3import type { Ask, AskListing } from "@repo/protocol/domain/ask";4import type { FileView, TreeListing } from "@repo/protocol/domain/code";5import type { Glob } from "@repo/protocol/domain/common";6import type { ProjectListing } from "@repo/protocol/domain/front-page";7import type { LandingView } from "@repo/protocol/domain/landing";8import { StageName } from "@repo/protocol/domain/outcome";9import type { ImportSource } from "@repo/protocol/domain/policy";10import { LedgerEntry } from "@repo/protocol/domain/visibility";11import type { Ledger } from "@repo/protocol/domain/visibility";12import type { AreaName, AskId, Handle, ProjectName } from "@repo/protocol/ids";13import type { Posture } from "@repo/protocol/posture";14import { useRouter } from "@tanstack/react-router";15import { Predicate } from "effect";16import type { DateTime } from "effect";17import { LockKeyhole } from "lucide-react";18import type { ReactNode } from "react";1920import { ForAgents, Onward, plural } from "../front/facts.tsx";21import { stillWaiting } from "../front/families.ts";22import { ProposeLink } from "../propose/propose-link.tsx";23import type { AskProgress } from "../shared/ask-progress.ts";24import { LINK } from "../shared/classes.ts";25import { CommandLine } from "../shared/command.tsx";26import { EmptyState } from "../shared/empty.tsx";27import { CommandSlotProvider } from "../shared/keys.tsx";28import { AppLink } from "../shared/link.tsx";29import {30 ENVIRONMENT_ANCHOR,31 LEDGER_ANCHOR,32 visibilityPath,33} from "../shared/paths.ts";34import { ReadingRows, UnreachableNotice } from "../shared/pending.tsx";35import { MetaCode, useRowSelection } from "../shared/row.tsx";36import { GUTTER } from "../shared/shell/gutter.ts";37import { stageNames, stageRuns } from "../shared/status-line.tsx";38import { AskList, askListIds, openAsks, openToTake } from "./asks.tsx";39import { LandingList, recentShown } from "./landings.tsx";40import { CloneSteps } from "./project-header.tsx";41import { ReadmeSection } from "./readme-section.tsx";4243export interface ProjectCode {44 readonly readme?: FileView | undefined;45 readonly root: TreeListing;46}4748export interface Deciders {49 readonly handles: readonly Handle[];50 readonly paths: Glob;51}5253export interface HeldBackArea {54 readonly area: AreaName;55 readonly checks: number;56 readonly detail: string;57}5859const noCount = (): readonly (readonly [AreaName, number])[] => [];6061export const heldBackOf = (ledger: Ledger): readonly HeldBackArea[] => {62 const checks = new Map(63 ledger.entries64 .toSorted((a, b) => a.seq - b.seq)65 .flatMap((entry) =>66 LedgerEntry.match(entry, {67 Admitted: noCount,68 CommitmentPublished: ({ area, checks: count }) => [69 [area, count] as const,70 ],71 CountChanged: ({ area, count }) => [[area, count] as const],72 LayerDeclared: noCount,73 PostureChanged: noCount,74 Released: noCount,75 ValueSet: noCount,76 })77 )78 );7980 return [...checks]81 .toSorted(([a], [b]) => a.localeCompare(b))82 .map(([area, count]) => ({83 area,84 checks: count,85 detail: `${count} sealed ${count === 1 ? "check" : "checks"}`,86 }));87};8889/**90 * Until its own ledger has said it, the page says no posture, never one it was91 * not told.92 */93export type HomeListing = Omit<ProjectListing, "posture"> & {94 readonly posture?: Posture | undefined;95};9697export const homeListing = ({98 asks,99 ledger,100 project,101}: {102 readonly asks: readonly AskListing[] | undefined;103 readonly ledger: Ledger | undefined;104 readonly project: ProjectName;105}): HomeListing => ({106 openAsks: asks?.length ?? 0,107 posture: ledger?.posture,108 project,109});110111export interface ProjectViewProps {112 readonly asks: readonly AskListing[] | undefined;113 readonly unreachable?: boolean;114 readonly landings: readonly LandingView[];115 readonly listing: HomeListing;116 readonly lastLanded?: DateTime.Utc | undefined;117 readonly heldBack?: readonly HeldBackArea[] | undefined;118 readonly deciders?: readonly Deciders[] | undefined;119 readonly importedFrom?: ImportSource | undefined;120 readonly now: DateTime.Utc;121 readonly platformUrl: string;122 readonly code?: ProjectCode | undefined;123 readonly parents?: readonly Ask[];124 readonly states?: ReadonlyMap<AskId, AskProgress>;125 readonly stamps?: ReadonlySet<AskId>;126 readonly signedIn?: boolean;127}128129/** A plain bordered surface, its headline first (DESIGN.md "Cards"). */130const AboutCard = ({131 children,132 id,133 title,134}: {135 readonly title: string;136 readonly id: string;137 readonly children: ReactNode;138}) => (139 <section140 aria-labelledby={id}141 className="border-rule bg-card flex min-w-0 flex-col gap-3 rounded-md border p-4"142 >143 <h2 className="text-ui scroll-mt-(--stick-toolbar) font-semibold" id={id}>144 {title}145 </h2>146 {children}147 </section>148);149150const HowItLands = () => (151 <AboutCard id="how-it-lands" title="How a change lands here">152 <p className="text-ui text-muted-foreground">153 Every answer is checked on the exact tree it would land as, by seven154 stages in turn.155 </p>156 <ol aria-label="Gate stages" className="flex flex-col gap-2">157 {StageName.literals.map((stage, at) => (158 <li className="flex min-w-0 gap-3" data-stage={stage} key={stage}>159 <span className="text-label text-muted-foreground w-4 shrink-0 pt-0.5 text-right tabular-nums">160 {at + 1}161 </span>162 <span className="flex min-w-0 flex-col">163 <span className="text-ui font-medium" data-term="">164 {stageNames(stage).label}165 </span>166 <span className="text-label text-muted-foreground font-normal">167 {stageRuns(stage)}168 </span>169 </span>170 </li>171 ))}172 </ol>173 <Onward to="/docs/landing">How a landing happens</Onward>174 </AboutCard>175);176177const WhoDecides = ({178 deciders,179 project,180}: {181 readonly deciders: readonly Deciders[] | undefined;182 readonly project: ProjectName;183}) => {184 const shown = deciders?.slice(0, 3) ?? [];185 const more = (deciders?.length ?? 0) - shown.length;186187 return (188 <AboutCard id="who-decides" title="Who decides">189 {deciders === undefined || deciders.length === 0 ? (190 <p className="text-ui text-muted-foreground">191 Its policy names who decides for which paths.192 </p>193 ) : (194 <ul className="flex flex-col gap-1">195 {shown.map(({ handles, paths }) => (196 <li className="text-ui min-w-0" key={paths}>197 <MetaCode>{paths}</MetaCode>198 <span className="text-muted-foreground"> · </span>199 {handles.join(", ")}200 </li>201 ))}202 {more > 0 ? (203 <li className="text-ui text-muted-foreground">204 and {plural(more, "set of paths", "sets of paths")} more205 </li>206 ) : null}207 </ul>208 )}209 <Onward to={`/${project}/people`}>Policy</Onward>210 </AboutCard>211 );212};213214/** The posture is the header's to say; this card says what is held back and where to read more. */215const VisibilitySummary = ({216 heldBack,217 project,218}: {219 readonly heldBack: readonly HeldBackArea[] | undefined;220 readonly project: ProjectName;221}) => {222 let held: ReactNode;223224 if (heldBack === undefined) {225 held = null;226 } else if (heldBack.length === 0) {227 held = <p className="text-ui text-muted-foreground">Nothing held back</p>;228 } else {229 held = (230 <ul className="flex flex-col gap-1">231 {heldBack.map(({ area, detail }) => (232 <li233 className="text-ui text-sealed flex items-start gap-2"234 data-area={area}235 key={area}236 >237 <LockKeyhole238 aria-hidden="true"239 className="mt-0.5 size-4 shrink-0"240 strokeWidth={1.75}241 />242 <span className="min-w-0 [overflow-wrap:anywhere]">243 <span className="text-mono font-mono">{area}</span>: {detail}244 </span>245 </li>246 ))}247 </ul>248 );249 }250251 return (252 <AboutCard id="visibility" title="Visibility">253 {held}254 <p className="text-ui flex flex-wrap gap-x-4 gap-y-1">255 <AppLink256 className={LINK}257 hash={LEDGER_ANCHOR}258 to={visibilityPath(project)}259 >260 Ledger261 </AppLink>262 <AppLink263 className={LINK}264 hash={ENVIRONMENT_ANCHOR}265 to={visibilityPath(project)}266 >267 Environment268 </AppLink>269 </p>270 </AboutCard>271 );272};273274const ImportedFrom = ({ source }: { readonly source: ImportSource }) => (275 <AboutCard id="imported-from" title="Imported from">276 <p className="text-ui">277 <a278 className={`${LINK} [overflow-wrap:anywhere]`}279 href={source.url}280 rel="noreferrer"281 >282 {source.url}283 </a>284 {source.branch === undefined ? null : (285 <>286 {" "}287 · branch <MetaCode>{source.branch}</MetaCode>288 </>289 )}290 </p>291 <p className="text-ui text-muted-foreground">292 This project is {IMPORTED_NOTE}.293 </p>294 </AboutCard>295);296297const About = ({ props }: { readonly props: ProjectViewProps }) => {298 const { project } = props.listing;299300 return (301 <aside302 aria-label="About"303 className="flex min-w-0 flex-col gap-4"304 data-column="about"305 >306 <AboutCard id="clone" title="Clone">307 <CloneSteps platformUrl={props.platformUrl} project={project} />308 </AboutCard>309 <HowItLands />310 <WhoDecides deciders={props.deciders} project={project} />311 <VisibilitySummary heldBack={props.heldBack} project={project} />312 {props.importedFrom === undefined ? null : (313 <ImportedFrom source={props.importedFrom} />314 )}315 <ForAgents href={`/${project}/llms.txt`} />316 </aside>317 );318};319320const SectionHead = ({321 action,322 count,323 id,324 title,325}: {326 readonly id: string;327 readonly title: string;328 readonly count?: string | undefined;329 readonly action?: ReactNode;330}) => (331 <div className="flex min-h-8 flex-wrap items-baseline gap-x-3 gap-y-1">332 <h2 className="text-title scroll-mt-(--stick-toolbar)" id={id}>333 {title}334 </h2>335 {count === undefined ? null : (336 <span className="text-label text-muted-foreground tabular-nums">337 {count}338 </span>339 )}340 {action === undefined ? null : <span className="ml-auto">{action}</span>}341 </div>342);343344/**345 * Adopting main is not a landing event, so the replay may hold no landing:346 * never say "nothing landed".347 */348const RecentLandings = ({349 landedAt,350 landings,351 now,352 platformUrl,353 project,354}: {355 readonly landedAt: DateTime.Utc | undefined;356 readonly landings: readonly LandingView[];357 readonly now: DateTime.Utc;358 readonly platformUrl: string;359 readonly project: ProjectName;360}) => {361 let shown: ReactNode;362363 if (landings.length > 0) {364 shown = <LandingList landings={recentShown(landings)} now={now} />;365 } else if (landedAt === undefined) {366 shown = (367 <>368 <p className="text-ui">369 Nothing has landed yet. The first push to main, by whoever ran init,370 lands it.371 </p>372 <CommandLine373 command={`git push ${platformUrl}/${project}.git HEAD:main`}374 />375 </>376 );377 } else {378 shown = (379 <p className="text-ui text-muted-foreground">380 No landings among the recent events of {project}.381 </p>382 );383 }384385 return (386 <section387 aria-labelledby="recent-landings"388 className="flex min-w-0 flex-col gap-2"389 >390 <SectionHead391 action={<Onward to={`/${project}/commits/main`}>Every landing</Onward>}392 id="recent-landings"393 title="Recent landings"394 />395 {shown}396 </section>397 );398};399400const countOf = (open: readonly AskListing[]) =>401 `${plural(open.length, "open ask", "open asks")}, ${402 open.filter(openToTake).length403 } open to take`;404405const AsksSection = ({406 asks,407 now,408 parents,409 project,410 selected,411 stamps,412 states,413 unreachable,414}: {415 readonly asks: readonly AskListing[] | undefined;416 readonly now: DateTime.Utc;417 readonly unreachable: boolean;418 readonly project: ProjectName;419 readonly parents: readonly Ask[];420 readonly states: ReadonlyMap<AskId, AskProgress>;421 readonly stamps: ReadonlySet<AskId>;422 readonly selected: string | undefined;423}) => {424 let list: ReactNode;425426 if (asks === undefined) {427 list = unreachable ? <UnreachableNotice /> : <ReadingRows />;428 } else if (asks.length === 0) {429 list = (430 <EmptyState431 command={`${Brand.cli} ask open <ask> --files <files>`}432 title="No open asks. A maintainer opens one from an ask file."433 />434 );435 } else {436 list = (437 <AskList438 asks={asks}439 now={now}440 parents={parents}441 project={project}442 selected={selected}443 stamps={stamps}444 states={states}445 />446 );447 }448449 return (450 <section451 aria-labelledby="open-asks"452 className="flex min-w-0 flex-col gap-2"453 >454 <SectionHead455 count={asks === undefined ? undefined : countOf(openAsks(asks))}456 id="open-asks"457 title="Open asks"458 />459 {list}460 </section>461 );462};463464/**465 * The Proposals tab opens this region until a project's proposals have a466 * page of their own, so the tab keeps the project's header and tabs.467 */468const ProposalsSection = ({469 project,470 signedIn,471}: {472 readonly project: ProjectName;473 readonly signedIn: boolean;474}) => (475 <section aria-labelledby="proposals" className="flex min-w-0 flex-col gap-2">476 <SectionHead477 action={signedIn ? <ProposeLink project={project} /> : undefined}478 id="proposals"479 title="Proposals"480 />481 <p className="text-ui text-muted-foreground max-w-(--measure)">482 A proposal asks a maintainer to open an ask. An agent on the platform483 drafts its ask file and check, and it expires unless a maintainer accepts484 it.485 {signedIn ? null : " Sign in to propose one."}486 </p>487 </section>488);489490/**491 * Overview: open asks, recent landings, proposals and the README in the main column,492 * and the about column beside it from `columns`, under it below.493 */494const ProjectPanes = ({495 props,496 selected,497}: {498 readonly props: ProjectViewProps;499 readonly selected: string | undefined;500}) => {501 const { asks, code, listing } = props;502 const states = props.states ?? new Map<AskId, AskProgress>();503 const { project } = listing;504505 return (506 <main507 className="flex min-w-0 flex-1 flex-col outline-none"508 data-scroll-restoration-id="main"509 data-variant="overview"510 id="main"511 tabIndex={-1}512 >513 <CommandSlotProvider slot="main">514 <div515 className={`columns:grid columns:grid-cols-[minmax(0,1fr)_var(--column-about)] columns:items-start flex flex-col gap-10 pt-6 pb-16 ${GUTTER}`}516 >517 <div className="flex min-w-0 flex-col gap-8">518 <AsksSection519 asks={asks}520 now={props.now}521 parents={props.parents ?? []}522 project={project}523 selected={selected}524 stamps={props.stamps ?? new Set()}525 states={states}526 unreachable={props.unreachable === true}527 />528 <RecentLandings529 landedAt={props.lastLanded ?? listing.landedAt}530 landings={props.landings}531 now={props.now}532 platformUrl={props.platformUrl}533 project={project}534 />535 <ProposalsSection536 project={project}537 signedIn={props.signedIn === true}538 />539 {code?.readme === undefined ? null : (540 <div className="max-w-(--measure) min-w-0">541 <ReadmeSection file={code.readme} project={project} />542 </div>543 )}544 </div>545 <About props={props} />546 </div>547 </CommandSlotProvider>548 </main>549 );550};551552const Selectable = ({ props }: { readonly props: ProjectViewProps }) => {553 const { selected } = useRowSelection(554 props.asks === undefined ? [] : askListIds(props.asks),555 "ask"556 );557558 return <ProjectPanes props={props} selected={selected} />;559};560561export const ProjectView = (given: ProjectViewProps) => {562 const props = {563 ...given,564 asks: given.asks && stillWaiting(given.asks),565 };566567 return Predicate.isNotNullish(useRouter({ warn: false })) ? (568 <Selectable props={props} />569 ) : (570 <ProjectPanes props={props} selected={undefined} />571 );572};