Skip to content
Myr

Merge build/1312-home into main

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by oscabriel · committed by oscabriel · parents 9000f4e, d45955c · Browse files · 11 files+1223 added−71 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

11 files+1223 added−71 removed

  • tests:+445 added−38 removed
  • other:+778 added−33 removed

11 files+1223 added−71 removed

modified:apps/web/src/features/code/refs-view.tsx+8 added-12 removed
10 unmodified lines
11 * when they hold more than one, a list of packages, each with its newest12 * tag and its count, sits above the tags, and `?package=` lists one13 * package's tags alone.14 */15import type { ClaimState } from "@repo/protocol/domain/claim";15import { packageOf } from "@repo/protocol/domain/code";16import type {17 ForkRef,18 RefsView as Refs,
8 unmodified lines
27import { FactBlock } from "../shared/facts.tsx";28import { HandleLink } from "../shared/handle.tsx";29import { AppLink } from "../shared/link.tsx";30import { answerPath, personPath } from "../shared/paths.ts";32import { MetaCode, MetaLine, Row, RowGroup, RowList } from "../shared/row.tsx";33import type { RowState } from "../shared/row.tsx";31import {32 CLAIM_STATES,33 MetaCode,34 MetaLine,35 Row,36 RowGroup,37 RowList,38} from "../shared/row.tsx";39import { Workspace } from "../shared/shell/workspace.tsx";40import { Pager } from "./pager.tsx";41import { commitHref, shortSha, treeHref } from "./paths.ts";42
75 unmodified lines
118 <HandleLink handle={handle} />119 </span>120);121117/** Each claim state as a row says it: its mark and its word. */118const CLAIM_STATES = {119 answered: { mark: "landed", word: "Answered" },120 lapsed: { mark: "notNeeded", word: "Lapsed" },121 live: { mark: "claimed", word: "Claimed" },122 released: { mark: "notNeeded", word: "Given up" },123 warned: { mark: "waiting", word: "Warned, no push lately" },124} as const satisfies Record<ClaimState, RowState>;125122/** A group of rows, or what it would hold said plainly when it holds none. */123const Group = ({124 children,125 counts,
318 unmodified lines
modified:apps/web/src/features/docs/head.ts+1 added-2 removed
added:apps/web/src/features/home/home-page.tsx+401 added
1/**2 * A signed-in reader's own page: their work (each claim, its ask's want and3 * where its answer stands, with the command that runs next); the decisions4 * waiting for them when they decide somewhere; the open asks they may take;5 * and the way to their record. No score and no count of credit (DESIGN.md).6 * Signed out, it says what the page is and how to sign in. A view: what the7 * server read, and the instant, in; markup out.8 */9import { Brand } from "@repo/brand";10import type { Today } from "@repo/protocol/domain/decision";11import type { FrontPageEntry } from "@repo/protocol/domain/front-page";12import { Outcome } from "@repo/protocol/domain/outcome";13import type { Handle } from "@repo/protocol/ids";14import type { DateTime } from "effect";15import type { ReactNode } from "react";1617import { signInHref } from "../auth/session-slot.tsx";18import {19 decisionHref,20 decisionKey,21 describeSubject,22 subjectKind,23} from "../decision/subject.ts";24import { CommandLine } from "../shared/command.tsx";25import { CopyAction } from "../shared/copy-action.tsx";26import { EmptyState } from "../shared/empty.tsx";27import { HandleLink } from "../shared/handle.tsx";28import { AppLink } from "../shared/link.tsx";29import {30 answerPath,31 ASKS_PATH,32 askPath,33 HOME_PATH,34 personPath,35} from "../shared/paths.ts";36import { UnreachableNotice } from "../shared/pending.tsx";37import {38 AskRow,39 CLAIM_STATES,40 MetaCode,41 MetaLine,42 outcomeState,43 Row,44 RowGroup,45} from "../shared/row.tsx";46import { Workspace } from "../shared/shell/workspace.tsx";47import { When } from "../shared/time.tsx";48import { orderDecisions } from "../today/read.ts";49import {50 Decisions,51 HomeRead,52 isRunning,53 Takeable,54 WORK_SHOWN,55} from "./read.ts";56import type { Work } from "./read.ts";5758/** What the page is, said to a reader who is not signed in. */59const WHAT_HOME_IS =60 "Home is your own page: the asks you hold and where each answer stands, the decisions waiting for you, and the asks you may take next.";6162/** The decisions the page lists; the rest are on Today. */63const DECISIONS_SHOWN = 5;6465const LINK =66 "decoration-rule hover:decoration-foreground font-medium underline underline-offset-4";6768/** A block's empty state, under its header like its rows would be. */69const Empty = (props: Parameters<typeof EmptyState>[0]) => (70 <li className="pt-3">71 <EmptyState {...props} />72 </li>73);7475/**76 * What runs next on a claim: a refusal's own `next`, or, while the claim77 * runs with nothing refused, its local check before a push.78 */79const nextOf = ({ answer, claim }: Work) => {80 if (answer !== undefined) {81 return Outcome.guards.Refused(answer.outcome)82 ? {83 command: answer.outcome.refusals[0].next,84 label: "Copy next command",85 }86 : undefined;87 }8889 return isRunning(claim)90 ? { command: claim.checkCommand, label: "Copy check command" }91 : undefined;92};9394const WorkRow = ({95 now,96 work,97}: {98 readonly now: DateTime.Utc;99 readonly work: Work;100}) => {101 const { answer, claim, want } = work;102 const next = nextOf(work);103104 return (105 <Row106 action={next === undefined ? undefined : <CopyAction {...next} />}107 data={{108 "data-claim": claim.ask,109 "data-project": claim.project,110 "data-state": claim.state,111 }}112 href={113 answer === undefined114 ? askPath(claim.project, claim.ask)115 : answerPath(claim.project, claim.ask)116 }117 id={`${claim.project}/${claim.ask}/${claim.fork}`}118 meta={119 <MetaLine120 parts={[121 claim.project,122 want === undefined ? undefined : (123 <MetaCode key="ask">{claim.ask}</MetaCode>124 ),125 <MetaCode key="fork">{claim.fork}</MetaCode>,126 isRunning(claim) ? (127 <span key="lapses">128 lapses <When at={claim.lapsesAt} now={now} />129 </span>130 ) : undefined,131 ]}132 />133 }134 mono={want === undefined}135 state={136 answer === undefined137 ? CLAIM_STATES[claim.state]138 : outcomeState(answer.outcome)139 }140 title={want ?? claim.ask}141 />142 );143};144145const WorkRows = ({146 asks,147 now,148 read,149}: {150 readonly asks: Takeable;151 readonly now: DateTime.Utc;152 readonly read: typeof HomeRead.cases.Read.Type;153}) => {154 const [first] = Takeable.match(asks, {155 Listed: ({ asks: listed }) => listed,156 Unreachable: () => [],157 });158159 return (160 <div className="flex flex-col gap-3">161 <RowGroup162 counts={`${read.running} running`}163 label="Your work"164 name="Your work"165 under="bar"166 >167 {read.work.length === 0 ? (168 <Empty169 command={170 first === undefined171 ? `${Brand.cli} front`172 : `${Brand.cli} claim ${first.ask.ask} --project ${first.project}`173 }174 onward={175 <AppLink className={LINK} to={ASKS_PATH}>176 The open asks177 </AppLink>178 }179 title={180 first === undefined181 ? "You hold no claim. Find an ask to take, then claim it."182 : "You hold no claim. Claim the first ask you may take, or pick another below."183 }184 />185 ) : (186 read.work.map((work) => (187 <WorkRow188 key={`${work.claim.project}/${work.claim.ask}/${work.claim.fork}`}189 now={now}190 work={work}191 />192 ))193 )}194 </RowGroup>195 {read.held > WORK_SHOWN ? (196 <div className="flex flex-col items-start gap-2">197 <p className="text-ui text-muted-foreground">198 The newest {WORK_SHOWN} of your {read.held} claims; every one:199 </p>200 <CommandLine command={`${Brand.cli} status`} />201 </div>202 ) : null}203 </div>204 );205};206207const DecisionRows = ({ today }: { readonly today: Today }) => (208 <>209 {orderDecisions(today)210 .slice(0, DECISIONS_SHOWN)211 .map((decision) => (212 <Row213 data={{214 "data-decision": decision.id,215 "data-project": decision.project,216 }}217 href={decisionHref(decision)}218 id={decisionKey(decision)}219 key={decisionKey(decision)}220 meta={221 <MetaLine222 parts={[223 decision.project,224 subjectKind(decision.subject),225 <MetaCode key="id">{decision.id}</MetaCode>,226 ]}227 />228 }229 state={{ mark: "now", word: "Yours to decide" }}230 title={describeSubject(decision.subject)}231 />232 ))}233 </>234);235236const TODAY_LINK = (237 <AppLink className={LINK} to="/today">238 Today239 </AppLink>240);241242const DecisionsGroup = ({243 children,244 waiting,245}: {246 readonly children: ReactNode;247 readonly waiting?: number;248}) => (249 <RowGroup250 counts={waiting === undefined ? undefined : `${waiting} waiting`}251 label="Decisions waiting"252 name={<AppLink to="/today">Decisions waiting</AppLink>}253 under="bar"254 >255 {children}256 </RowGroup>257);258259/** A decider's waiting decisions, or that none waits. */260const Waiting = ({ today }: { readonly today: Today }) => {261 const waiting = today.decisions.length + today.overflow;262263 return (264 <DecisionsGroup waiting={waiting}>265 {waiting === 0 ? (266 <Empty267 onward={TODAY_LINK}268 title="Nothing waits for your decision. Today shows what landed without one."269 />270 ) : (271 <DecisionRows today={today} />272 )}273 </DecisionsGroup>274 );275};276277/** The decisions block: a decider's waiting decisions; nothing for anyone else. */278const DecisionsBlock = ({ decisions }: { readonly decisions: Decisions }) =>279 Decisions.match(decisions, {280 Decides: ({ today }) => <Waiting today={today} />,281 NotDecider: () => null,282 Unreachable: () => (283 <DecisionsGroup>284 <Empty285 command={`${Brand.cli} today`}286 onward={TODAY_LINK}287 title="Your decisions did not come: the platform did not answer. Try Today, or read them from a terminal."288 />289 </DecisionsGroup>290 ),291 });292293const AskRows = ({ asks }: { readonly asks: readonly FrontPageEntry[] }) =>294 asks.map(({ ask, project }) => (295 <AskRow296 key={`${project}/${ask.ask}`}297 listing={ask}298 project={project}299 showProject300 takeable301 />302 ));303304const EVERY_ASK = (305 <AppLink className={LINK} to={ASKS_PATH}>306 Every open ask307 </AppLink>308);309310/** The asks block's empty state: none to take, or none came. */311const NoAsks = ({ title }: { readonly title: string }) => (312 <Empty command={`${Brand.cli} front`} onward={EVERY_ASK} title={title} />313);314315/** The asks the reader may take, or why none shows. */316const AskList = ({ asks }: { readonly asks: Takeable }) =>317 Takeable.match(asks, {318 Listed: ({ asks: listed }) =>319 listed.length === 0 ? (320 <NoAsks title="No open ask is yours to take right now." />321 ) : (322 <AskRows asks={listed} />323 ),324 Unreachable: () => (325 <NoAsks title="The asks did not come: the platform did not answer." />326 ),327 });328329const AsksBlock = ({ asks }: { readonly asks: Takeable }) => (330 <RowGroup331 label="Asks you may take"332 name={<AppLink to={ASKS_PATH}>Asks you may take</AppLink>}333 under="bar"334 >335 <AskList asks={asks} />336 </RowGroup>337);338339/** Who is signed in, and the way to their record. */340const Record = ({ handle }: { readonly handle: Handle }) => (341 <>342 Signed in as <HandleLink handle={handle} />.{" "}343 <AppLink className={LINK} to={personPath(handle)}>344 Your record345 </AppLink>346 </>347);348349const SignedIn = ({350 now,351 read,352}: {353 readonly now: DateTime.Utc;354 readonly read: typeof HomeRead.cases.Read.Type;355}) => (356 <Workspace357 crumbs={[{ label: "Home" }]}358 meta={<Record handle={read.handle} />}359 title="Home"360 variant="list"361 >362 <div className="flex flex-col gap-8">363 <WorkRows asks={read.asks} now={now} read={read} />364 <DecisionsBlock decisions={read.decisions} />365 <AsksBlock asks={read.asks} />366 </div>367 </Workspace>368);369370/** Signed out: what the page is, the way in, and the command. */371const SignedOut = () => (372 <Workspace crumbs={[{ label: "Home" }]} title="Home">373 <div className="flex max-w-[70ch] flex-col items-start gap-3">374 <p className="text-body">{WHAT_HOME_IS}</p>375 <p className="text-ui">376 <a className={LINK} href={signInHref(HOME_PATH)}>377 Sign in378 </a>{" "}379 to see yours, or read it from a terminal:380 </p>381 <CommandLine command={`${Brand.cli} status`} />382 </div>383 </Workspace>384);385386export const HomeView = ({387 now,388 read,389}: {390 readonly now: DateTime.Utc;391 readonly read: HomeRead;392}) =>393 HomeRead.match(read, {394 Read: (signed) => <SignedIn now={now} read={signed} />,395 SignedOut: () => <SignedOut />,396 Unreachable: () => (397 <Workspace crumbs={[{ label: "Home" }]} title="Home">398 <UnreachableNotice />399 </Workspace>400 ),401 });
added:apps/web/src/features/home/read.ts+307 added
1/**2 * What `/home` reads, in a module with no view of its own: a route's loader3 * runs before its page's view loads.4 *5 * - `HomeRead`: the reader's work (each claim from `status`, its ask's want6 * and its latest answer), their Today when they decide somewhere, the7 * open asks they may take (`frontPage`, read as them), or why there is8 * none of it.9 * - `readHome`: that read, made with whatever `Client` the caller gives10 * (the server's, carrying the reader's own session).11 */12import { Client } from "@repo/protocol/contracts";13import { AnswerView } from "@repo/protocol/domain/answer";14import { ClaimView } from "@repo/protocol/domain/claim";15import { Today } from "@repo/protocol/domain/decision";16import { FrontPageEntry } from "@repo/protocol/domain/front-page";17import { Handle } from "@repo/protocol/ids";18import type { ProjectName } from "@repo/protocol/ids";19import { NotDecider } from "@repo/protocol/refusal";20import {21 Array as Arr,22 Cause,23 DateTime,24 Effect,25 Exit,26 Option,27 Order,28 Schema,29} from "effect";3031import { isSignedOut } from "../today/read.ts";3233/** The asks the page lists: the first few the reader may take; the rest are at `/asks`. */34const ASKS_SHOWN = 8;3536/** The claims the page lists, running first, then the newest; the rest are in `status`. */37export const WORK_SHOWN = 10;3839/** How many reads of one kind the page makes at once. */40const AT_ONCE = 4;4142/** One claim of the reader's, its ask's want, and its latest answer. */43export const Work = Schema.Struct({44 answer: Schema.optionalKey(AnswerView),45 claim: ClaimView,46 /** Absent when the ask did not come: the row names it by its id. */47 want: Schema.optionalKey(Schema.NonEmptyString),48});4950export type Work = typeof Work.Type;5152/** The decisions block: the reader's Today, or why there is none. */53export const Decisions = Schema.TaggedUnion({54 Decides: { today: Today },55 NotDecider: {},56 Unreachable: {},57});5859export type Decisions = typeof Decisions.Type;6061/** The asks block: the first the reader may take, or that the list did not come. */62export const Takeable = Schema.TaggedUnion({63 Listed: { asks: Schema.Array(FrontPageEntry) },64 Unreachable: {},65});6667export type Takeable = typeof Takeable.Type;6869/** What the page read for its reader: their work, or why there is none. */70export const HomeRead = Schema.TaggedUnion({71 Read: {72 asks: Takeable,73 decisions: Decisions,74 handle: Handle,75 /** Every claim the reader holds, of which `work` is the first `WORK_SHOWN`. */76 held: Schema.Int,77 /** How many of those are still running. */78 running: Schema.Int,79 work: Schema.Array(Work),80 },81 SignedOut: {},82 Unreachable: {},83});8485export type HomeRead = typeof HomeRead.Type;8687/** What the loader sends: the read, and the instant it was made. */88export const HomePageData = Schema.Struct({89 now: Schema.DateTimeUtcFromString,90 read: HomeRead,91});9293export type HomePageData = typeof HomePageData.Type;9495/** A claim still running: its holder's to push to. */96export const isRunning = (claim: ClaimView) =>97 claim.state === "live" || claim.state === "warned";9899const openedOrder = Order.mapInput(100 DateTime.Order,101 (claim: ClaimView) => claim.openedAt102);103104/** Running claims first, then the newest. */105const workOrder: Order.Order<ClaimView> = Order.combine(106 Order.mapInput(Order.Boolean, (claim: ClaimView) => !isRunning(claim)),107 Order.flip(openedOrder)108);109110const answerOrder = Order.mapInput(111 DateTime.Order,112 (answer: AnswerView) => answer.at113);114115const isNotDecider = Schema.is(NotDecider);116117/** Where a claim's ask lives: one key per (project, ask). */118export const askKey = ({ ask, project }: ClaimView) => `${project}/${ask}`;119120/**121 * The asks whose id the reader's claims hold in more than one project.122 * `status` names an answer's ask but not its project, so those asks' answers123 * are read again one project at a time.124 */125const sharedAsks = (claims: readonly ClaimView[]) =>126 new Set(127 Object.entries(Arr.groupBy(claims, ({ ask }) => ask)).flatMap(128 ([ask, holding]) =>129 new Set(holding.map(({ project }) => project)).size > 1 ? [ask] : []130 )131 );132133/** The reader's answers in each of `projects`; a project that did not answer gives none. */134const answersIn = (projects: readonly ProjectName[]) =>135 Effect.gen(function* () {136 const client = yield* Client;137138 return new Map(139 yield* Effect.forEach(140 projects,141 (project) =>142 client.status({ project }).pipe(143 Effect.map(({ answers }) => [project, answers] as const),144 Effect.orElseSucceed(() => [project, []] as const)145 ),146 { concurrency: AT_ONCE }147 )148 );149 });150151/** Each shown claim's ask's want, by `askKey`; an ask that did not come is left out. */152const wantsOf = (claims: readonly ClaimView[]) =>153 Effect.gen(function* () {154 const client = yield* Client;155 const asks = Arr.dedupeWith(claims, (a, b) => askKey(a) === askKey(b));156157 return new Map(158 yield* Effect.forEach(159 asks,160 (claim) =>161 client.showAsk({ ask: claim.ask, project: claim.project }).pipe(162 Effect.map(({ ask }) => [[askKey(claim), ask.brief.want] as const]),163 Effect.orElseSucceed(() => [])164 ),165 { concurrency: AT_ONCE }166 ).pipe(Effect.map((found) => found.flat()))167 );168 });169170/** The claims the page lists: running first, then the newest, the first `WORK_SHOWN`. */171const shownOf = (claims: readonly ClaimView[]) =>172 Arr.sort(claims, workOrder).slice(0, WORK_SHOWN);173174/**175 * The reader's first claims, each with its want and its latest answer. An176 * answer belongs to the newest claim on its ask in its project; an older177 * claim on the same ask shows its own state. An ask whose id the reader178 * holds in two projects takes its answers from `again`, read per project.179 */180export const pairWork = ({181 again,182 answers,183 claims,184 wants,185}: {186 readonly claims: readonly ClaimView[];187 readonly answers: readonly AnswerView[];188 readonly again: ReadonlyMap<ProjectName, readonly AnswerView[]>;189 readonly wants: ReadonlyMap<string, string>;190}): readonly Work[] => {191 const shared = sharedAsks(claims);192193 /** The claim each (project, ask) gives its answer to: the newest, set last. */194 const newest = new Map(195 Arr.sort(claims, openedOrder).map(196 (claim) => [askKey(claim), claim] as const197 )198 );199200 const answerOf = (claim: ClaimView) => {201 if (newest.get(askKey(claim)) !== claim) {202 return Option.none();203 }204205 const [latest] = Arr.sort(206 (shared.has(claim.ask)207 ? (again.get(claim.project) ?? [])208 : answers209 ).filter(({ ask }) => ask === claim.ask),210 Order.flip(answerOrder)211 );212213 return Option.fromUndefinedOr(latest);214 };215216 return shownOf(claims).map((claim): Work => ({217 claim,218 ...Option.match(answerOf(claim), {219 onNone: () => ({}),220 onSome: (answer) => ({ answer }),221 }),222 ...Option.match(Option.fromUndefinedOr(wants.get(askKey(claim))), {223 onNone: () => ({}),224 onSome: (want) => ({ want }),225 }),226 }));227};228229/** `pairWork` over what the platform answers: the wants, and answers read again where needed. */230const workOf = (claims: readonly ClaimView[], answers: readonly AnswerView[]) =>231 Effect.gen(function* () {232 const shown = shownOf(claims);233 const shared = sharedAsks(claims);234235 const [again, wants] = yield* Effect.all(236 [237 answersIn(238 Arr.dedupe(239 shown.flatMap(({ ask, project }) =>240 shared.has(ask) ? [project] : []241 )242 )243 ),244 wantsOf(shown),245 ],246 { concurrency: "unbounded" }247 );248249 return pairWork({ again, answers, claims, wants });250 });251252/** The reader's home, or why there is none, encoded for the page. */253export const readHome = Effect.gen(function* () {254 const client = yield* Client;255256 const [status, today, front] = yield* Effect.all(257 [258 Effect.exit(client.status({})),259 Effect.exit(client.today({})),260 Effect.option(client.frontPage({})),261 ],262 { concurrency: "unbounded" }263 );264265 const decisions = Exit.match(today, {266 onFailure: (cause) =>267 Option.exists(Cause.findErrorOption(cause), isNotDecider)268 ? Decisions.cases.NotDecider.make({})269 : Decisions.cases.Unreachable.make({}),270 onSuccess: (read) => Decisions.cases.Decides.make({ today: read }),271 });272273 const asks = Option.match(front, {274 onNone: () => Takeable.cases.Unreachable.make({}),275 onSome: ({ entries }) =>276 Takeable.cases.Listed.make({277 asks: entries.filter(({ takeable }) => takeable).slice(0, ASKS_SHOWN),278 }),279 });280281 const read = yield* Exit.match(status, {282 onFailure: (cause) =>283 Effect.succeed(284 isSignedOut(cause)285 ? HomeRead.cases.SignedOut.make({})286 : HomeRead.cases.Unreachable.make({})287 ),288 onSuccess: ({ answers, claims, handle }) =>289 workOf(claims, answers).pipe(290 Effect.map((work) =>291 HomeRead.cases.Read.make({292 asks,293 decisions,294 handle,295 held: claims.length,296 running: claims.filter(isRunning).length,297 work,298 })299 )300 ),301 });302303 return yield* Schema.encodeEffect(HomePageData)({304 now: yield* DateTime.now,305 read,306 });307});
modified:apps/web/src/features/shared/row.tsx+26 added-12 removed
18 unmodified lines
19 * press. `j` and `k` reach each row's link (`data-list-key`). Every20 * `data-*` a list carries sits on the row's `<li>`.21 */22import type { AskListing } from "@repo/protocol/domain/ask";23import type { ClaimState } from "@repo/protocol/domain/claim";24import { Outcome } from "@repo/protocol/domain/outcome";25import type { ProjectName } from "@repo/protocol/ids";26import type { MouseEvent, ReactNode } from "react";27import { Fragment } from "react";
269 unmodified lines
297 readonly name: ReactNode;298 /** The group's facts after its name: a project's posture. */299 readonly facts?: ReactNode;300 /** Its counts at the end, in words: "7 open · 6 to take". */300 readonly counts?: string;301 readonly counts?: string | undefined;302 /** The group's name in words, for its list (the name may be a link). */303 readonly label?: string;304 /** What the header sticks under. */305 readonly under?: keyof typeof STICK;
54 unmodified lines
360361 return { clear, focused, select, selected };362};363364/** An answer's latest outcome as a row's state: a retryable refusal turns back. */365export const outcomeState = (outcome: Outcome): RowState =>366 Outcome.match(outcome, {367 AwaitingDecision: (): RowState => ({ mark: "waiting", word: "Waiting" }),368 AwaitingFinish: (): RowState => ({ mark: "waiting", word: "Waiting" }),369 Checking: (): RowState => ({ mark: "checking", word: "Checking" }),370 Landed: (): RowState => ({ mark: "landed", word: "Landed" }),371 Refused: ({ refusals }): RowState => ({372 mark: refusals[0].retryable ? "retry" : "refused",373 word: "Refused",374 }),375 WaitingOnParent: (): RowState => ({ mark: "waiting", word: "Waiting" }),376 });377378/** Each claim state as a row says it: its mark and its word. */379export const CLAIM_STATES = {380 answered: { mark: "landed", word: "Answered" },381 lapsed: { mark: "notNeeded", word: "Lapsed" },382 live: { mark: "claimed", word: "Claimed" },383 released: { mark: "notNeeded", word: "Given up" },384 warned: { mark: "waiting", word: "Warned, no push lately" },385} as const satisfies Record<ClaimState, RowState>;386387/** Where an open ask stands for its reader, as a row's state. */388const askState = (389 listing: AskListing,390 takeable: boolean | undefined,
3 unmodified lines
394 return { mark: "landed", word: "Landed" };395 }396397 if (progress?.latest !== undefined) {374 return Outcome.match(progress.latest, {375 AwaitingDecision: (): RowState => ({ mark: "waiting", word: "Waiting" }),376 AwaitingFinish: (): RowState => ({ mark: "waiting", word: "Waiting" }),377 Checking: (): RowState => ({ mark: "checking", word: "Checking" }),378 Landed: (): RowState => ({ mark: "landed", word: "Landed" }),379 Refused: ({ refusals }): RowState => ({380 mark: refusals[0].retryable ? "retry" : "refused",381 word: "Refused",382 }),383 WaitingOnParent: (): RowState => ({ mark: "waiting", word: "Waiting" }),384 });398 return outcomeState(progress.latest);399 }400401 if (listing.claimed || progress?.claimant !== undefined) {402 return { mark: "claimed", word: "Claimed" };
97 unmodified lines
modified:apps/web/src/features/today/read.ts+5 added-1 removed
modified:apps/web/src/routes/home.tsx+30 added-6 removed
1import { createFileRoute } from "@tanstack/react-router";2import { createServerFn } from "@tanstack/react-start";3import { getRequest } from "@tanstack/react-start/server";4import { env } from "cloudflare:workers";5import { Effect, Schema } from "effect";67import { HomeView } from "../features/home/home-page.tsx";8import { HomePageData, readHome } from "../features/home/read.ts";9import { pageHead } from "../features/shared/head.ts";4import { Workspace } from "../features/shared/shell/workspace.tsx";10import { reloadOnEnter } from "../features/shared/shell/selection.ts";11import { personalPage } from "../server/cache-headers.ts";12import { serverClient } from "../server/client.ts";137// `/home`: a signed-in reader's own page, where the landing sends them. A8// page about its reader is kept by no cache.14// `/home`: the signed-in reader's own page, where the landing sends them.15// The loader reads it on the server with the reader's own session (their16// cookie goes with the call), so the page arrives with its rows. A page17// about its reader is kept by no cache.1810const HomePage = () => <Workspace title="Home">{null}</Workspace>;19/** A page about its reader, kept by no cache. */20export const homeHeaders = () => personalPage;2122const homePage = createServerFn({ method: "GET" }).handler(() =>23 Effect.runPromise(24 readHome.pipe(Effect.provide(serverClient(env, getRequest())))25 )26);2728const HomePage = () => {29 const data = Schema.decodeSync(HomePageData)(Route.useLoaderData());3031 return <HomeView now={data.now} read={data.read} />;32};3334export const Route = createFileRoute("/home")({13 component: HomePage,14 headers: () => personalPage,35 loader: () => homePage(),36 shouldReload: reloadOnEnter,37 headers: homeHeaders,38 head: () => pageHead({ title: "Home" }),39 component: HomePage,40});
added:apps/web/test/dev-client.ts+43 added
modified:apps/web/test/edge-cache.test.ts+1 added
457 unmodified lines
458 );459460 expect(reading.toSorted()).toStrictEqual([461 "../src/routes/$project/decisions/$decision.tsx",462 "../src/routes/home.tsx",463 "../src/routes/today.tsx",464 ]);465466 for (const path of reading) {
24 unmodified lines
added:apps/web/test/home.test.tsx+399 added
1/**2 * `/home`, a signed-in reader's own page: their work (each claim, its ask's3 * want, where its answer stands and the command that runs next), the4 * decisions waiting when they decide somewhere, the asks they may take, and5 * their record; each block says what to do when it is empty or did not6 * come. Read on the server with the reader's session from the dev world and7 * its fixtures, and drawn from reads made here. Signed out, it says what8 * the page is and how to sign in. A page about its reader, kept by no cache.9 */10import { describe, expect, it } from "@effect/vitest";11import { Brand } from "@repo/brand";12import type { AnswerView } from "@repo/protocol/domain/answer";13import { ClaimView } from "@repo/protocol/domain/claim";14import { DecisionSubject, Today } from "@repo/protocol/domain/decision";15import { FrontPageEntry } from "@repo/protocol/domain/front-page";16import { Outcome } from "@repo/protocol/domain/outcome";17import {18 AskId,19 CommitSha,20 Handle,21 ProjectName,22 RequestId,23} from "@repo/protocol/ids";24import { ClaimLapsed } from "@repo/protocol/refusal";25import { DateTime, Effect, Schema } from "effect";2627import { HomeView } from "../src/features/home/home-page.tsx";28import {29 askKey,30 Decisions,31 HomePageData,32 HomeRead,33 pairWork,34 readHome,35 Takeable,36} from "../src/features/home/read.ts";37import { homeHeaders, Route } from "../src/routes/home.tsx";38import { fixturesClient } from "./dev-client.ts";39import { textIn } from "./markup.ts";40import { renderAt } from "./render.tsx";4142const NOW = "2026-10-07T12:00:00.000Z";4344/** The page as the route renders it from what the loader sent. */45const pageFrom = (encoded: typeof HomePageData.Encoded) =>46 Effect.gen(function* () {47 const data = yield* Schema.decodeEffect(HomePageData)(encoded);4849 return yield* renderAt(50 "/home",51 <HomeView now={data.now} read={data.read} />52 );53 });5455/** The page drawn from a signed-in read made here. */56const pageOf = (read: Partial<typeof HomeRead.cases.Read.Type>) =>57 renderAt(58 "/home",59 <HomeView60 now={DateTime.makeUnsafe(NOW)}61 read={HomeRead.cases.Read.make({62 asks: Takeable.cases.Listed.make({ asks: [] }),63 decisions: Decisions.cases.NotDecider.make({}),64 handle: Handle.make("bram"),65 held: 0,66 running: 0,67 work: [],68 ...read,69 })}70 />71 );7273/** The sections' names, in order. */74const sectionsOf = (markup: string) =>75 [...markup.matchAll(/<section\b[^>]*aria-label="(?<name>[^"]+)"/gu)].map(76 (found) => found.groups?.name77 );7879/** The commands a reader can copy: each in the DOM as text. */80const commandsOf = (markup: string) =>81 [...markup.matchAll(/<code\b[^>]*>(?<command>.*?)<\/code>/gsu)].map((found) =>82 textIn(found.groups?.command ?? "").trim()83 );8485const claim = (fields: Partial<typeof ClaimView.Encoded> = {}) =>86 Schema.decodeSync(ClaimView)({87 ask: "fix-week-start",88 base: "a".repeat(40),89 checkCommand: `${Brand.cli} check fix-week-start --project datekit`,90 claimant: "bram",91 fork: "datekit--fix-week-start--bram",92 lapsesAt: "2026-10-08T12:00:00.000Z",93 openedAt: "2026-10-07T09:00:00.000Z",94 project: "datekit",95 remote: "https://git.example/datekit--fix-week-start--bram",96 state: "live",97 warnsAt: "2026-10-08T06:00:00.000Z",98 ...fields,99 });100101/** An answer refused because its claim lapsed, which a new claim can mend. */102const refused = (ask: string): AnswerView => ({103 ask: AskId.make(ask),104 at: DateTime.makeUnsafe("2026-10-07T11:00:00Z"),105 head: CommitSha.make("b".repeat(40)),106 outcome: Outcome.cases.Refused.make({107 refusals: [ClaimLapsed.of(AskId.make(ask))],108 }),109 requestId: RequestId.make(`req-${ask}`),110});111112const decision = (id: string, handle: string, expiresAt: string) => ({113 deciders: ["ines-v"] as const,114 default: "decline" as const,115 evidence: [],116 expiresAt,117 id,118 openedAt: "2026-10-06T09:00:00.000Z",119 project: "datekit",120 subject: DecisionSubject.cases.Vouch.make({ handle: Handle.make(handle) }),121});122123const today = Schema.decodeSync(Today)({124 budget: { finishes: 0, total: 5, used: 1 },125 decider: "ines-v",126 decisions: [127 decision("dec-000002", "lin-h", "2026-10-09T12:00:00.000Z"),128 decision("dec-000001", "tamsin", "2026-10-08T12:00:00.000Z"),129 ],130 expiringSoon: [],131 newcomers: [],132 overflow: 0,133 unattended: [],134});135136const takeable = Schema.decodeSync(FrontPageEntry)({137 ask: {138 ask: "split-format",139 blockedBy: [],140 claimed: false,141 kind: "migrate",142 territory: "format",143 want: "The format package calls the new parser.",144 },145 posture: "open",146 project: "burrow",147 takeable: true,148});149150describe(HomeView, () => {151 it.effect(152 "shows a running claim by its want, with its check command, and a refused answer with its next command",153 () =>154 Effect.gen(function* () {155 const markup = yield* pageOf({156 held: 2,157 running: 2,158 work: [159 {160 claim: claim(),161 want: "A week starts on the locale's first day.",162 },163 {164 answer: refused("parse-iso-week"),165 claim: claim({166 ask: "parse-iso-week",167 fork: "datekit--parse-iso-week--bram",168 }),169 want: "Parse an ISO week date.",170 },171 ],172 });173174 expect(textIn(markup)).toContain(175 "A week starts on the locale's first day."176 );177 expect(commandsOf(markup)).toStrictEqual(178 expect.arrayContaining([179 `${Brand.cli} check fix-week-start --project datekit`,180 `${Brand.cli} claim parse-iso-week`,181 ])182 );183 // A refusal a new push can mend turns back, in its own mark.184 expect(markup).toContain("lucide-rotate-ccw");185 expect(markup).toContain('href="/datekit/answers/parse-iso-week"');186 })187 );188189 it.effect(190 "orders its blocks: your work, the decisions waiting, then the asks to take",191 () =>192 Effect.gen(function* () {193 const markup = yield* pageOf({194 asks: Takeable.cases.Listed.make({ asks: [takeable] }),195 decisions: Decisions.cases.Decides.make({ today }),196 });197198 expect(sectionsOf(markup)).toStrictEqual([199 "Your work",200 "Decisions waiting",201 "Asks you may take",202 ]);203 expect(textIn(markup)).toContain("2 waiting");204 expect(markup).toMatch(205 /data-decision="dec-000001"[\s\S]*data-decision="dec-000002"/u206 );207 expect(markup).toContain('href="/today"');208 })209 );210211 it.effect("leaves the decisions out for a reader who decides nowhere", () =>212 Effect.gen(function* () {213 const markup = yield* pageOf({});214215 expect(sectionsOf(markup)).toStrictEqual([216 "Your work",217 "Asks you may take",218 ]);219 })220 );221222 it.effect(223 "says so, with a command, when the decisions or the asks did not come, rather than showing none",224 () =>225 Effect.gen(function* () {226 const markup = yield* pageOf({227 asks: Takeable.cases.Unreachable.make({}),228 decisions: Decisions.cases.Unreachable.make({}),229 });230231 const text = textIn(markup);232233 expect(text).toContain("Your decisions did not come");234 expect(text).toContain("The asks did not come");235 expect(text).not.toContain("No open ask is yours to take");236 expect(commandsOf(markup)).toStrictEqual(237 expect.arrayContaining([`${Brand.cli} today`, `${Brand.cli} front`])238 );239 })240 );241242 it.effect(243 "with no claim, gives the claim command for the first ask the reader may take",244 () =>245 Effect.gen(function* () {246 const markup = yield* pageOf({247 asks: Takeable.cases.Listed.make({ asks: [takeable] }),248 });249250 expect(textIn(markup)).toContain("You hold no claim.");251 expect(commandsOf(markup)).toContain(252 `${Brand.cli} claim split-format --project burrow`253 );254 })255 );256257 it.effect("links the reader's handle and their record", () =>258 Effect.gen(function* () {259 const markup = yield* pageOf({});260261 expect(textIn(markup)).toContain("Signed in as bram.");262 expect(markup).toContain('href="/people/bram"');263 })264 );265266 it.effect(267 "past the claims it shows, says how many there are and gives the command for every one",268 () =>269 Effect.gen(function* () {270 const markup = yield* pageOf({271 held: 14,272 running: 1,273 work: [{ claim: claim() }],274 });275276 expect(textIn(markup)).toContain("The newest 10 of your 14 claims");277 expect(commandsOf(markup)).toContain(`${Brand.cli} status`);278 })279 );280});281282describe(pairWork, () => {283 it("gives an answer to the newest claim on its ask, and an older claim its own state", () => {284 const older = claim({285 openedAt: "2026-10-01T09:00:00.000Z",286 state: "lapsed",287 });288289 const newer = claim();290 const answer = refused("fix-week-start");291292 const work = pairWork({293 again: new Map(),294 answers: [answer],295 claims: [older, newer],296 wants: new Map([297 [askKey(newer), "A week starts on the locale's first day."],298 ]),299 });300301 expect(302 work.map(({ answer: paired, claim: held }) => [held.state, paired])303 ).toStrictEqual([304 ["live", answer],305 ["lapsed", undefined],306 ]);307 expect(work.map(({ want }) => want)).toStrictEqual([308 "A week starts on the locale's first day.",309 "A week starts on the locale's first day.",310 ]);311 });312313 it("reads an ask held in two projects from each project's own answers", () => {314 const inDatekit = claim();315316 const inBurrow = claim({317 fork: "burrow--fix-week-start--bram",318 project: "burrow",319 });320321 const datekitAnswer = refused("fix-week-start");322323 const work = pairWork({324 again: new Map([325 [ProjectName.make("datekit"), [datekitAnswer]],326 [ProjectName.make("burrow"), []],327 ]),328 // `status` across every project: which project this answer is in, it does not say.329 answers: [datekitAnswer],330 claims: [inDatekit, inBurrow],331 wants: new Map(),332 });333334 expect(335 work.map(({ answer, claim: held }) => [held.project, answer])336 ).toStrictEqual([337 ["datekit", datekitAnswer],338 ["burrow", undefined],339 ]);340 });341});342343describe("home, read on the server with the reader's session", () => {344 it.live(345 "gives a contributor their work by its wants, the asks they may take and their record, and no decisions",346 () =>347 Effect.gen(function* () {348 const markup = yield* pageFrom(yield* readHome);349350 expect(sectionsOf(markup)).toStrictEqual([351 "Your work",352 "Asks you may take",353 ]);354 expect(markup).toMatch(/data-claim="[^"]+"[^>]*data-project="vellum"/u);355 expect(markup).toContain('href="/people/bram"');356 expect(markup).toContain('href="/asks"');357 }).pipe(Effect.provide(fixturesClient("bram")), Effect.scoped),358 60_000359 );360361 it.live(362 "gives a decider the decisions waiting for them, each linking its page, and Today",363 () =>364 Effect.gen(function* () {365 const markup = yield* pageFrom(yield* readHome);366367 expect(sectionsOf(markup)).toStrictEqual([368 "Your work",369 "Decisions waiting",370 "Asks you may take",371 ]);372 expect(markup).toMatch(/href="\/[a-z-]+\/decisions\/[^"]+"/u);373 expect(markup).toContain('href="/today"');374 }).pipe(Effect.provide(fixturesClient("ines-v")), Effect.scoped),375 60_000376 );377378 it.live(379 "signed out, says what the page is, how to sign in and come back, and the command",380 () =>381 Effect.gen(function* () {382 const markup = yield* pageFrom(yield* readHome);383384 expect(textIn(markup)).toContain(`${Brand.cli} status`);385 expect(markup).toContain(386 `href="/auth/signin?return=${encodeURIComponent("/home")}"`387 );388 expect(sectionsOf(markup)).toStrictEqual([]);389 }).pipe(Effect.provide(fixturesClient()), Effect.scoped),390 60_000391 );392393 it("is kept by no cache: its response is private and never stored", () => {394 expect(Route.options.headers).toBe(homeHeaders);395 expect(homeHeaders()).toStrictEqual({396 "Cache-Control": "private, no-store",397 });398 });399});
modified:apps/web/test/today.test.tsx+2 added-38 removed
9 unmodified lines
10 * loader over the dev world with its fixtures, signed in as a decider.11 */12import { describe, expect, it } from "@effect/vitest";13import { Brand } from "@repo/brand";14import { Client, Contracts } from "@repo/protocol/contracts";14import { RefNameText } from "@repo/protocol/domain/common";15import { DecisionSubject } from "@repo/protocol/domain/decision";16import type { Choice, Decision, Today } from "@repo/protocol/domain/decision";17import type { LandingView } from "@repo/protocol/domain/landing";
9 unmodified lines
27 RatchetName,28 RepoPath,29} from "@repo/protocol/ids";30import { DecisionClosed, NotDecider } from "@repo/protocol/refusal";32import { Cause, DateTime, Effect, Layer, Schema } from "effect";33import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";31import { Cause, DateTime, Effect, Schema } from "effect";32import { AsyncResult } from "effect/reactivity";35import { RpcClient, RpcSerialization } from "effect/rpc";33import type { ReactElement } from "react";34import { renderToStaticMarkup } from "react-dom/server";3539import { devServer } from "../src/dev/server.ts";40import { devToken } from "../src/dev/sessions.ts";36import {37 allowedChoices,38 consequenceOf,39 describeSubject,
7 unmodified lines
47 TodayRead,48 TodayView,49} from "../src/features/today/today-page.tsx";50import { Route, todayHeaders } from "../src/routes/today.tsx";51import { fixturesClient } from "./dev-client.ts";5253/** The entities React writes for text, and what each reads as. */54const ENTITIES: ReadonlyMap<string, string> = new Map([55 ["&#x27;", "'"],
514 unmodified lines
570});571572const vellum = ProjectName.make("vellum");573578/** A `Client` of a fresh dev world with its fixtures, signed in as `handle` (or as nobody). */579const fixturesClient = (handle?: string) =>580 Layer.unwrap(581 Effect.gen(function* () {582 const { dispose, handler } = devServer({ fixtures: "on" });583584 yield* Effect.addFinalizer(() => Effect.promise(dispose));585586 return Layer.effect(Client)(RpcClient.make(Contracts)).pipe(587 Layer.provide(588 RpcClient.layerProtocolHttp({589 transformClient: HttpClient.mapRequest((request) =>590 handle === undefined591 ? request592 : HttpClientRequest.bearerToken(593 request,594 devToken(Handle.make(handle))595 )596 ),597 url: "http://localhost/rpc",598 })599 ),600 Layer.provide([FetchHttpClient.layer, RpcSerialization.layerJson]),601 Layer.provide(602 Layer.succeed(FetchHttpClient.Fetch, (input, init) =>603 handler(new Request(input, init))604 )605 )606 );607 })608 );609574/** The page the route renders from what `readToday` sent, as the browser decodes it. */575const pageFrom = (encoded: typeof TodayPageData.Encoded) => {576 const data = Schema.decodeSync(TodayPageData)(encoded);577
51 unmodified lines