List each project at the posture its own ledger stands at
Before adoption: this commit came in with the history the project adopted, so no landing records it.
- New `withStandingPosture` (packages/project/src/standing-posture.ts): overlays each listing with its project's anonymous `ledger` posture, at most 8 reads at once (the handlers' FAN_OUT). A project never made, or a read that fails or dies, keeps the projected posture and logs a warning; an interruption stays one. The list never fails. - The platform's `listProjects`, its `/` (HTML and Markdown, so `/` and the web's `/llms.txt` stay one text) and the dev world's `listProjects` read through it. `homeResponse` and the `home` route gain `Projects`. `everywhere` and the FrontPage port are untouched. - Nothing is written: no ledger row, D1 row, migration or backfill. demo's datekit reads "Open with sealed evidence" after a redeploy alone. - Doc comments in front-page.ts, projection-d1/{projection,tables}.ts, the dev front page and `listingOf` say the projected posture is the fallback. - Tests: standing-posture.test.ts (overlay, ghost and broken keep theirs, order and fields kept, empty list asks nobody, peak of 8 under it.live); posture-listing.test.ts (handlers over FrontPageMemory); visibility/posture-listing.test.ts (Node world with the cartridge: the ledger and the list agree on datekit after a sealed first config, red before); home.test.ts (sealed datekit on `/` equals frontLlms); dev-backend.test.ts (list equals each ledger, both open). front-page.test.ts now records the list's one `get datekit`. - bytes:check, no limit changed: web entry 711006 of 818000. - ASSUMPTION: one ledger read per listed project per list is cheap enough for today's handful of projects; the whole ledger is read for one field.
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
16 files+609 added−21 removed
- tests:+498 added−6 removed
- other:+111 added−15 removed
Provenance
- Commit
9328872- Tree
72ba654- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent
42ea9b7
16 files changed+609 added−21 removed
modified:apps/platform/src/handlers.ts+8 added-2 removed
1 unmodified line2 * The contracts' handlers: routing, the rate limit and the fan-out, nothing3 * more. A contract that names a project calls4 * that project's `ProjectApi` (its Durable Object, through `Projects`) as5 * the caller `Authenticated` named; the cross-project reads (`listProjects`,6- * `frontPage`, `credits`) come from the front-page projection; `status` and6+ * `frontPage`, `credits`) come from the front-page projection, each listed7+ * project's posture read from its own ledger (`withStandingPosture`); `status` and8 * `today` without a project ask every project the projection lists and9 * merge what each says. `claim`, `proposeAsk` and `flagAsk` spend the10 * caller's rate limit first, so a call past it reaches no project; a11 * proposal with a draft, and `draftAsk`, spend the draft limit too.24 unmodified lines36 import { FrontPage } from "@repo/project/front-page";37 import { GatewayUrl } from "@repo/project/project";38 import type { ProjectApi } from "@repo/project/project";39 import { Projects } from "@repo/project/projects";40+import { withStandingPosture } from "@repo/project/standing-posture";41 import { Contracts, EnvSchemaOf } from "@repo/protocol/contracts";42 import type { AnswerView } from "@repo/protocol/domain/answer";43 import type { ClaimView } from "@repo/protocol/domain/claim";44 import type { Decision, Today } from "@repo/protocol/domain/decision";279 unmodified lines324 ),325 listPaths: ({ at, project }) =>326 code(project, (of) => pathsOf(of, Option.fromUndefinedOr(at))),327 listProjects: () =>326- Effect.map(frontPage.projects(), (listed) => ({ projects: listed })),328+ frontPage.projects().pipe(329+ Effect.flatMap(withStandingPosture),330+ Effect.provideService(Projects, projects),331+ Effect.map((listed) => ({ projects: listed }))332+ ),333 listRefs: ({ project }) => code(project, refsOf),334 log: ({ at, from = 0, limit = LOG_PAGE, path, project }) =>335 code(project, (of) =>336 logOf(of, {109 unmodified linesmodified:apps/platform/src/home.ts+12 added-3 removed
6 unmodified lines7 *8 * Every URL is built from the request's origin, the one the client reached:9 * the platform is also the git remote, the MCP base and the CLI's URL, so10 * the page names them as the reader will type them. The projects are the11- * front page's, and nothing else: no layer and no fork is listed. Every11+ * front page's, and nothing else: no layer and no fork is listed; each12+ * one's posture is the one its own ledger stands at, as `listProjects`13+ * answers it (`withStandingPosture`), so `/` and the web's `/llms.txt`14+ * stay one text. Every15 * value that reaches the HTML is escaped. Not a redirect: the web app is a16 * link, so the host stays discoverable at its own address.17 */18 import { commandDocs } from "@repo/agent-kit/command-doc";19 import { frontLlms, MCP_PROTOCOL } from "@repo/agent-kit/host-doc";20 import { Brand } from "@repo/brand";21 import { FrontPage } from "@repo/project/front-page";22+import type { Projects } from "@repo/project/projects";23+import { withStandingPosture } from "@repo/project/standing-posture";24 import { Contracts } from "@repo/protocol/contracts";25 import type { ProjectListing } from "@repo/protocol/domain/front-page";26 import { Effect, Option } from "effect";27 139 unmodified lines167 168 /** `/` for `request`: Markdown for an agent that asks for it, else the page. */169 export const homeResponse = (170 request: Request166-): Effect.Effect<Response, never, FrontPage | HostInfo> =>171+): Effect.Effect<Response, never, FrontPage | HostInfo | Projects> =>172 Effect.gen(function* () {173 const { draftModel, webUrl } = yield* HostInfo;174+169- const projects = yield* FrontPage.use((frontPage) => frontPage.projects());175+ const projects = yield* FrontPage.use((frontPage) =>176+ frontPage.projects()177+ ).pipe(Effect.flatMap(withStandingPosture));178+179 const { origin } = new URL(request.url);180 181 if (wantsMarkdown(request)) {182 return new Response(30 unmodified linesmodified:apps/platform/src/surfaces.ts+2 added-1 removed
366 unmodified lines367 /** `/`: what this host serves, for a browser and for an agent (`home.ts`). */368 const home = HttpRouter.use((router) =>369 Effect.gen(function* () {370 const services = Context.make(FrontPage, yield* FrontPage).pipe(371- Context.add(HostInfo, yield* HostInfo)371+ Context.add(HostInfo, yield* HostInfo),372+ Context.add(Projects, yield* Projects)373 );374 375 yield* router.add(376 "GET",111 unmodified linesadded:apps/platform/test/visibility/posture-listing.test.ts+117 added
1+/**2+ * The project list's posture over the platform's Node world (the core3+ * loop's world) with the visibility cartridge's project state composed4+ * into every Project DO, as `ledger-mcp.test.ts` composes it. datekit's5+ * first push carries a `visibility.ts` that declares sealed checks: a first6+ * config stands at once and writes no `PostureChanged` row, so the7+ * projection still lists datekit as `open`, the row D1 holds on demo. The8+ * list reads datekit's posture from datekit's own ledger, so the badge and9+ * the ledger say the same.10+ */11+import { describe, expect, it } from "@effect/vitest";12+import { Fetch } from "@repo/artifacts/fetch";13+import { RepoHost } from "@repo/artifacts/repo-host";14+import { RepoHostMemory } from "@repo/artifacts/repo-host/memory";15+import { Brand } from "@repo/brand";16+import { FrontPageMemory } from "@repo/project/front-page/memory";17+import { ProjectName } from "@repo/protocol/ids";18+import { fakeArtifactsBinding } from "@repo/testkit/fake-artifacts-binding";19+import { untouchable } from "@repo/testkit/untouchable";20+import { Effect, Layer } from "effect";21+22+import { decodeEnv } from "../../src/platform.ts";23+import { stateLive } from "../../src/visibility/state.ts";24+import { fakeEnv } from "../fake-env.ts";25+import { coreLoopWorld } from "../world.ts";26+27+const project = ProjectName.make("datekit");28+29+const sdk = `${Brand.cliPackage}/rules`;30+31+/** datekit as dora first pushes it, its visibility config declaring sealed checks. */32+const start = {33+ [`${Brand.configDir}/project.ts`]: [34+ `import { kinds, project } from "${sdk}";`,35+ ``,36+ `export default project({`,37+ ` kinds: [kinds.fix],`,38+ ` run: { checks: {}, test: "bun test {path}" },`,39+ `});`,40+ ``,41+ ].join("\n"),42+ [`${Brand.configDir}/visibility.ts`]: [43+ `import { flows, layer, sealedChecks, visibility } from "${sdk}";`,44+ ``,45+ `export default visibility({`,46+ ` checks: sealedChecks({`,47+ ` areas: { export: "src/format.ts", parser: "src/parse.ts" },`,48+ ` }),`,49+ ` flows: flows.noWriteDown(),`,50+ ` layers: {`,51+ ` maintainers: layer({`,52+ ` disclose: "sealed",`,53+ ` holds: ["checks", "notes"],`,54+ ` reason: "Held-back checks for export and parser",`,55+ ` }),`,56+ ` },`,57+ `});`,58+ ``,59+ ].join("\n"),60+ "package.json": '{ "name": "datekit", "private": true }\n',61+ "src/parse.ts": "export const parse = (iso: string) => 0;\n",62+};63+64+/** A `Fetch` that nothing here may call. */65+const noFetch = Layer.succeed(Fetch, untouchable<Fetch["Service"]>("Fetch"));66+67+/** The cartridge's project state for the world's stage, over a private namespace of its own. */68+const cartridge = Layer.unwrap(69+ Effect.gen(function* () {70+ const host = yield* Effect.provide(71+ Effect.service(RepoHost),72+ RepoHostMemory73+ );74+75+ const config = yield* decodeEnv({76+ ...fakeEnv(),77+ ARTIFACTS_PRIVATE: fakeArtifactsBinding(host, {78+ remoteBase: "https://artifacts.test",79+ }),80+ }).pipe(Effect.orDie);81+82+ return stateLive(config).pipe(Layer.provide(noFetch));83+ })84+);85+86+describe("the project list, with the visibility cartridge composed", () => {87+ it.live(88+ "lists datekit at the posture its ledger stands at, though the projection says open",89+ () =>90+ Effect.scoped(91+ Effect.gen(function* () {92+ const world = yield* coreLoopWorld({93+ frontPage: FrontPageMemory.layer({94+ credits: [],95+ entries: [],96+ projects: [{ openAsks: 0, posture: "open", project }],97+ }),98+ });99+100+ const dora = world.rpc("dora");101+ const made = yield* dora.initProject({ project });102+ const home = yield* world.git("dora").clone(made.remote);103+104+ yield* world.git("dora").commit(home, "Start datekit", start);105+ yield* world.git("dora").push(home);106+107+ const anyone = world.rpc("anonymous");108+ const { posture } = yield* anyone.ledger({ project });109+ const { projects } = yield* anyone.listProjects({});110+111+ expect(posture).toBe("openWithSealedEvidence");112+ expect(projects).toStrictEqual([{ openAsks: 0, posture, project }]);113+ }).pipe(Effect.provide(cartridge))114+ ),115+ 30_000116+ );117+});modified:apps/platform/test/front-page.test.ts+3 added-2 removed
261 unmodified lines262 });263 264 describe("the project list and credits over the platform's /rpc", () => {265 it.effect(266- "after a landing, lists the project and its people's credits from D1 without calling a project",266+ "after a landing, lists the project from D1, asking it only its posture, and its people's credits without calling a project",267 () =>268 Effect.gen(function* () {269 yield* advanceTo(noon);270 19 unmodified lines290 credits: [291 { area: "parser", count: 1, project, role: "Signed-off-by" },292 ],293 },294- calls: [],294+ // The list's one read: datekit's posture, from its ledger.295+ calls: [`get ${project}`],296 listed: {297 projects: [298 { landedAt: at(noon), openAsks: 1, posture: "open", project },299 ],5 unmodified linesmodified:apps/platform/test/home.test.ts+86 added-4 removed
8 unmodified lines9 import { commandDocs } from "@repo/agent-kit/command-doc";10 import { frontLlms } from "@repo/agent-kit/host-doc";11 import { Brand } from "@repo/brand";12 import { FrontPageMemory } from "@repo/project/front-page/memory";13+import type { ProjectApi } from "@repo/project/project";14+import { Projects } from "@repo/project/projects";15 import { Contracts } from "@repo/protocol/contracts";16 import type { ProjectListing } from "@repo/protocol/domain/front-page";17 import { ProjectName } from "@repo/protocol/ids";18+import { UnknownProject } from "@repo/protocol/refusal";19+import { untouchable } from "@repo/testkit/untouchable";20 import { Effect, Layer, Option } from "effect";21 22 import { MemorySessions } from "../src/sessions/memory.ts";23 import { HostInfo } from "../src/surfaces.ts";9 unmodified lines33 project: ProjectName.make("burrow"),34 },35 ];36 33-/** The platform listing `listed`, on a host whose web app is `web`. */37+/**38+ * The platform's projects where datekit's ledger stands sealed: its first39+ * config declared sealed checks, which writes no `PostureChanged` row, so40+ * the projection still lists it `open`. burrow was never made here.41+ */42+const datekitSealed = Layer.succeed(43+ Projects,44+ Projects.of({45+ create: () => Effect.die("the home page makes no project"),46+ get: (project) =>47+ project === "datekit"48+ ? Effect.succeed(49+ untouchable<ProjectApi>("ProjectApi", {50+ ledger: () =>51+ Effect.succeed({52+ entries: [],53+ layers: [],54+ posture: "openWithSealedEvidence",55+ postureLabel: "Open with sealed evidence",56+ project,57+ }),58+ })59+ )60+ : Effect.fail(new UnknownProject({ project })),61+ })62+);63+64+/** The platform's projects before any is made: each listed one keeps its listed posture. */65+const noneMade = Layer.succeed(66+ Projects,67+ Projects.of({68+ create: () => Effect.die("the home page makes no project"),69+ get: (project) => Effect.fail(new UnknownProject({ project })),70+ })71+);72+73+/**74+ * The platform listing `listed`, on a host whose web app is `web`, with75+ * `made` for its projects.76+ */77 const platform = (78 listed: readonly ProjectListing[],36- web: Option.Option<string> = Option.some(webUrl)79+ web: Option.Option<string> = Option.some(webUrl),80+ made: Layer.Layer<Projects> = noneMade81 ) =>82 served(83 Layer.mergeAll(84+ made,85 noProjects,86 MemorySessions.layer({}),87 FrontPageMemory.layer({ credits: [], entries: [], projects: listed }),88 Layer.succeed(6 unmodified lines95 /** `/` as `headers` ask for it: its status, type and text. */96 const home = (97 listed: readonly ProjectListing[],98 init: RequestInit = {},54- web?: Option.Option<string>99+ web?: Option.Option<string>,100+ made?: Layer.Layer<Projects>101 ) =>102 Effect.gen(function* () {57- const { fetch } = yield* platform(listed, web);103+ const { fetch } = yield* platform(listed, web, made);104 const response = yield* fetch(new Request(`${origin}/`, init));105 106 return {107 status: response.status,98 unmodified lines206 })207 );208 209 it.effect(210+ "gives each project the posture its own ledger stands at, as the web's /llms.txt does",211+ () =>212+ Effect.gen(function* () {213+ const { text } = yield* home(214+ projects,215+ { headers: { accept: "text/markdown" } },216+ undefined,217+ datekitSealed218+ );219+220+ expect(text).toBe(221+ frontLlms({222+ commands: commandDocs(Contracts),223+ platformUrl: origin,224+ projects: [225+ {226+ openAsks: 3,227+ posture: "openWithSealedEvidence",228+ project: ProjectName.make("datekit"),229+ },230+ {231+ openAsks: 1,232+ posture: "openWithSealedEvidence",233+ project: ProjectName.make("burrow"),234+ },235+ ],236+ webUrl,237+ })238+ );239+ expect(text).toContain(240+ `- [datekit](${webUrl}/datekit/llms.txt): Open with sealed evidence, 3 open asks.`241+ );242+ })243+ );244+245+ it.effect(246 "gives an agent the platform's own Markdown on a host with no web app",247 () =>248 Effect.gen(function* () {249 const { text, type } = yield* home(64 unmodified linesadded:apps/platform/test/posture-listing.test.ts+94 added
1+/**2+ * `listProjects` as the platform's handlers answer it: the projection lists3+ * each project, and each listed project's posture is the one its own4+ * ledger stands at now, so the badge and the ledger say the same. The5+ * projection here lists datekit as `open`, the row D1 holds for a project6+ * whose first config declared sealed checks (that config writes no7+ * `PostureChanged` row); datekit's ledger stands sealed. A project the8+ * platform never made keeps the posture the projection listed.9+ */10+import { describe, expect, it } from "@effect/vitest";11+import { RepoHost } from "@repo/artifacts/repo-host";12+import { EvidenceStoreMemory } from "@repo/checks/evidence-store/memory";13+import { FrontPageMemory } from "@repo/project/front-page/memory";14+import type { ProjectApi } from "@repo/project/project";15+import { Projects } from "@repo/project/projects";16+import { Contracts } from "@repo/protocol/contracts";17+import { ProjectName } from "@repo/protocol/ids";18+import {19+ Anonymous,20+ Authenticated,21+ CurrentPrincipal,22+} from "@repo/protocol/principal";23+import { UnknownProject } from "@repo/protocol/refusal";24+import { untouchable } from "@repo/testkit/untouchable";25+import { Effect, Layer } from "effect";26+import { RpcTest } from "effect/rpc";27+28+import { MemoryRateLimits, WorkerCaps } from "../src/adapters/rate-limits.ts";29+import { Handlers } from "../src/handlers.ts";30+31+const datekit = ProjectName.make("datekit");32+33+const ghost = ProjectName.make("ghost");34+35+/** datekit's project, whose only answered read is its ledger, standing sealed. */36+const datekitApi = untouchable<ProjectApi>("ProjectApi", {37+ ledger: () =>38+ Effect.succeed({39+ entries: [],40+ layers: [],41+ posture: "openWithSealedEvidence",42+ postureLabel: "Open with sealed evidence",43+ project: datekit,44+ }),45+});46+47+const platform = Handlers.pipe(48+ Layer.provide([49+ Layer.succeed(50+ Projects,51+ Projects.of({52+ create: () => Effect.die("a listing makes no project"),53+ get: (project) =>54+ project === datekit55+ ? Effect.succeed(datekitApi)56+ : Effect.fail(new UnknownProject({ project })),57+ })58+ ),59+ FrontPageMemory.layer({60+ credits: [],61+ entries: [],62+ projects: [63+ { openAsks: 3, posture: "open", project: datekit },64+ { openAsks: 0, posture: "openCore", project: ghost },65+ ],66+ }),67+ MemoryRateLimits(WorkerCaps),68+ EvidenceStoreMemory,69+ Layer.succeed(RepoHost, untouchable<RepoHost["Service"]>("RepoHost")),70+ ])71+);72+73+const anonymous = Layer.succeed(Authenticated, (effect) =>74+ Effect.provideService(effect, CurrentPrincipal, Anonymous.make({}))75+);76+77+describe("the platform's project list", () => {78+ it.effect("gives each project the posture its ledger stands at", () =>79+ Effect.gen(function* () {80+ const anyone = yield* RpcTest.makeClient(Contracts);81+82+ expect(yield* anyone.listProjects({})).toStrictEqual({83+ projects: [84+ {85+ openAsks: 3,86+ posture: "openWithSealedEvidence",87+ project: datekit,88+ },89+ { openAsks: 0, posture: "openCore", project: ghost },90+ ],91+ });92+ }).pipe(Effect.provide(Layer.mergeAll(platform, anonymous)))93+ );94+});modified:apps/web/src/dev/front-page.ts+2 added-1 removed
6 unmodified lines7 * the anonymous viewer sees: takeable when no live claim holds it, nothing8 * it waits on is still on the page, and it is held for nobody; newest first.9 * A project is listed from its first event, `open` until a `PostureChanged`10 * ledger entry moves it, with when it last landed (the `projects`11- * table). A person's credits are each project's own count, joined11+ * table); `listProjects` reads each one's standing posture from its own12+ * ledger (`withStandingPosture`), and keeps this one only as the fallback. A person's credits are each project's own count, joined13 * (`creditsFor`): the rule D1's `credits` table is fed by, read at the source.14 */15 import { FrontPage } from "@repo/project/front-page";16 import type { FrontPageFilter } from "@repo/project/front-page";213 unmodified linesmodified:apps/web/src/dev/handlers.ts+6 added-1 removed
26 unmodified lines27 import type { CodeProject } from "@repo/project/code";28 import { FrontPage } from "@repo/project/front-page";29 import type { ProjectApi } from "@repo/project/project";30 import { Projects } from "@repo/project/projects";31+import { withStandingPosture } from "@repo/project/standing-posture";32 import { Contracts, EnvSchemaOf } from "@repo/protocol/contracts";33 import type { AnswerView } from "@repo/protocol/domain/answer";34 import type { ClaimView } from "@repo/protocol/domain/claim";35 import type { Decision, Today } from "@repo/protocol/domain/decision";242 unmodified lines278 ),279 listPaths: ({ at, project }) =>280 code(project, (of) => pathsOf(of, Option.fromUndefinedOr(at))),281 listProjects: () =>281- Effect.map(frontPage.projects(), (listed) => ({ projects: listed })),282+ frontPage.projects().pipe(283+ Effect.flatMap(withStandingPosture),284+ Effect.provideService(Projects, projects),285+ Effect.map((listed) => ({ projects: listed }))286+ ),287 listRefs: ({ project }) => code(project, refsOf),288 log: ({ at, from = 0, limit = LOG_PAGE, path, project }) =>289 code(project, (of) =>290 logOf(of, {107 unmodified linesmodified:apps/web/src/routes/$project/index.tsx+4 added-3 removed
97 unmodified lines989910010110210310410210310410510610710810982 unmodified lines97 unmodified lines
const root = getRouteApi("__root__");
/** * The project as listed; a project the list has not heard from yet (its * projection catches up after its first event) reads as the platform lists * every project until a `PostureChanged` entry projects a posture: open. * The project as listed, its posture the one its own ledger stands at (the * list reads it from each project); a project the list has not heard from * yet (its projection catches up after its first event) reads open, as * the projection lists a project before any posture is projected. */const listingOf = ( project: ProjectName, projects: readonly ProjectListing[],82 unmodified linesmodified:apps/web/test/dev-backend.test.ts+32 added
169 unmodified lines170 };171 })172 );173 174+/** The project list beside each project's ledger, as anyone reads them. */175+const listedWithLedgers = inFreshWorld((as) =>176+ Effect.gen(function* () {177+ const anyone = yield* clientOf(as());178+ const { projects } = yield* anyone.listProjects({});179+180+ const ledgers = yield* Effect.forEach(PROJECTS, (project) =>181+ anyone.ledger({ project })182+ );183+184+ return { ledgers, projects };185+ })186+);187+188 /**189 * Each test seeds whole worlds, the first one cold, while turbo runs every190 * package's tests at once: about 0.5 s alone, near vitest's 5 s default191 * under that load once burrow's migrate opens as a family of eight asks.46 unmodified lines238 expect(landedAt).toHaveLength(1);239 })240 );241 242+ it.live("lists each project at the posture its own ledger gives", () =>243+ Effect.gen(function* () {244+ const { ledgers, projects } = yield* listedWithLedgers;245+246+ expect(247+ projects.map(({ posture, project }) => [project, posture])248+ ).toStrictEqual(249+ ledgers.map(({ posture, project }) => [project, posture])250+ );251+ // The dev world composes no visibility cartridge, so every ledger,252+ // and the list with it, reads Open.253+ expect(ledgers.map(({ posture }) => posture)).toStrictEqual([254+ "open",255+ "open",256+ ]);257+ })258+ );259+260 it.live("lands bram's answer to datekit with its credit trailers", () =>261 Effect.gen(function* () {262 const { landing, sampled } = yield* landedAnswer;263 133 unmodified linesmodified:packages/project/src/projection-d1/projection.ts+5 added-1 removed
3 unmodified lines4 * Project DO stays the system of record; this is a read model it feeds5 * through its outbox, and nothing else writes it.6 *7 * - A project is listed from its first event on (no event says a project8- * was made), `open` until a `PostureChanged` ledger entry moves it. Its8+ * was made), `open` until a `PostureChanged` ledger entry moves it: the9+ * fallback for a list, which reads each project's standing posture from10+ * its own ledger (`withStandingPosture`), since a first config, a11+ * widening and a narrowing taking effect by the clock write no such12+ * entry. Its13 * open asks are counted again from the front page whenever an ask opens14 * or closes, and a landing stamps when it last landed.15 * - A landing credits each person it names once per role, in its ask's16 * area: the module of the ask's territory, read from the ask's front252 unmodified linesmodified:packages/project/src/projection-d1/tables.ts+3 added-1 removed
55 unmodified lines56 * and the projection's credits test applies the file and checks that it57 * does.58 *59 * - `projects`: one row per project the projection has heard from: its60- * posture (`open` until a `PostureChanged` ledger entry), its open asks60+ * posture (`open` until a `PostureChanged` ledger entry; the fallback a61+ * list keeps when it cannot read the project's own ledger, which it reads62+ * for the posture standing now: `withStandingPosture`), its open asks63 * (counted from `front_page` whenever an ask opens or closes), and when64 * it last landed (null before its first landing).65 * - `credits`: how many landings credit a person (by `handle_key`, the66 * handle lowercased: `handleKey`) in one role, in one area of one project.43 unmodified linesmodified:packages/project/src/front-page.ts+9 added-2 removed
1 /**2 * The `FrontPage` port: the read side of the projection every project feeds3 * (the write side is `Projection`, whose rows come from each project's4 * outbox). The front page, the project list and a person's credits read from5- * here without waking any project.5+ * here without waking any project. A listed project's `posture` is the6+ * fallback only: a list's callers read each project's posture from its own7+ * ledger at list time (`withStandingPosture`), since its standing changes8+ * without any event this read model hears, and keep this one for a project9+ * whose ledger could not be read.10 *11 * Adapters: `/memory` here, seeded from data, for tests; `projection-d1`12 * over D1 in the Worker.13 */15 unmodified lines29 30 export class FrontPage extends Context.Service<31 FrontPage,32 {29- /** Every project, with its posture and how many asks it has open. */33+ /**34+ * Every project, with how many asks it has open and the posture last35+ * projected (the fallback for its standing posture).36+ */37 readonly projects: () => Effect.Effect<readonly ProjectListing[]>;38 /** The open asks across every project, as the anonymous viewer sees them. */39 readonly entries: (40 filter: FrontPageFilter7 unmodified linesadded:packages/project/src/standing-posture.ts+60 added
1+/**2+ * A listed project's posture, as its own record says it now. The3+ * projection's `posture` moves only on a `PostureChanged` ledger entry, and4+ * a project's standing changes without one: its first config stands at5+ * once, a widening needs no decision, and an accepted narrowing takes6+ * effect when its notice runs out, by the clock. So a list of projects7+ * reads each one's ledger, the public read whose `posture` is the standing8+ * at now (`visibility/ledger.ts`), and shows that: the badge and the ledger9+ * are one value, read at the source, with nothing written to keep them in10+ * step.11+ *12+ * Cost: one ledger read per listed project per list, a few at once.13+ */14+import type { ProjectListing } from "@repo/protocol/domain/front-page";15+import { Anonymous } from "@repo/protocol/principal";16+import { Cause, Effect } from "effect";17+18+import { Projects } from "./projects.ts";19+20+/** How many projects a list reads at once (the platform handlers' `FAN_OUT`). */21+const READS_AT_ONCE = 8;22+23+/**24+ * `listed` with each project's posture as its own record says it now (its25+ * ledger's standing), read at most 8 at once; a project never made, or one26+ * whose read fails, keeps the posture the projection listed.27+ */28+export const withStandingPosture = (29+ listed: readonly ProjectListing[]30+): Effect.Effect<readonly ProjectListing[], never, Projects> =>31+ Effect.gen(function* () {32+ const projects = yield* Projects;33+34+ return yield* Effect.forEach(35+ listed,36+ (listing) =>37+ Effect.suspend(() => projects.get(listing.project)).pipe(38+ Effect.flatMap((api) => api.ledger(Anonymous.make({}))),39+ Effect.map(({ posture }): ProjectListing => ({40+ ...listing,41+ posture,42+ })),43+ // The list answers whatever one project does, a `get` that44+ // throws included: an interruption stays one, and anything else45+ // keeps the projected posture.46+ Effect.catchCause((cause) =>47+ Cause.hasInterruptsOnly(cause)48+ ? Effect.interrupt49+ : Effect.as(50+ Effect.logWarning(51+ `${listing.project}'s posture is the projection's: its ledger was not read`,52+ cause53+ ),54+ listing55+ )56+ )57+ ),58+ { concurrency: READS_AT_ONCE }59+ );60+ });added:packages/project/test/standing-posture.test.ts+166 added
1+/**2+ * A listed project's posture, as its own record says it now: each listing3+ * the projection gives is overlaid with the posture its project's ledger4+ * stands at, read as anyone reads it, a few projects at once. A project the5+ * platform never made, or one whose read breaks, keeps the posture the6+ * projection listed, and the list still answers.7+ */8+import { describe, expect, it } from "@effect/vitest";9+import type { ProjectListing } from "@repo/protocol/domain/front-page";10+import { ProjectName } from "@repo/protocol/ids";11+import type { Posture } from "@repo/protocol/posture";12+import { Principal } from "@repo/protocol/principal";13+import { UnknownProject } from "@repo/protocol/refusal";14+import { untouchable } from "@repo/testkit/untouchable";15+import { Array, DateTime, Duration, Effect, Layer, Ref } from "effect";16+17+import type { ProjectApi } from "../src/project.ts";18+import { Projects } from "../src/projects.ts";19+import { withStandingPosture } from "../src/standing-posture.ts";20+21+const datekit = ProjectName.make("datekit");22+23+const ghost = ProjectName.make("ghost");24+25+const broken = ProjectName.make("broken");26+27+const burrow = ProjectName.make("burrow");28+29+const landedAt = DateTime.makeUnsafe("2026-10-08T12:00:00Z");30+31+/**32+ * An api whose only answered read is `ledger`, standing at `posture` for33+ * anyone; a person's read is a defect, since a listing is public.34+ */35+const standingAt = (36+ project: ProjectName,37+ posture: Posture,38+ before: Effect.Effect<void> = Effect.void39+) =>40+ untouchable<ProjectApi>("ProjectApi", {41+ ledger: (caller) =>42+ Principal.match(caller, {43+ Anonymous: () =>44+ Effect.as(before, {45+ entries: [],46+ layers: [],47+ posture,48+ postureLabel: "As its ledger says",49+ project,50+ }),51+ Person: ({ handle }) =>52+ Effect.die(`a listing read ${project}'s ledger as ${handle}`),53+ }),54+ });55+56+/**57+ * The platform's projects: datekit's ledger stands sealed, burrow's open,58+ * `broken`'s read dies, and `ghost` was never made.59+ */60+const platform = Layer.succeed(61+ Projects,62+ Projects.of({63+ create: () => Effect.die("a listing makes no project"),64+ get: (project) => {65+ switch (project) {66+ case datekit: {67+ return Effect.succeed(standingAt(datekit, "openWithSealedEvidence"));68+ }69+70+ case burrow: {71+ return Effect.succeed(standingAt(burrow, "open"));72+ }73+74+ case broken: {75+ return Effect.succeed(76+ untouchable<ProjectApi>("ProjectApi", {77+ ledger: () => Effect.die("the project's storage is down"),78+ })79+ );80+ }81+82+ default: {83+ return Effect.fail(new UnknownProject({ project }));84+ }85+ }86+ },87+ })88+);89+90+const listed: readonly ProjectListing[] = [91+ { landedAt, openAsks: 3, posture: "open", project: datekit },92+ { openAsks: 1, posture: "openCore", project: ghost },93+ { openAsks: 0, posture: "sourceAvailable", project: broken },94+ { landedAt, openAsks: 2, posture: "openOnSchedule", project: burrow },95+];96+97+describe("a listing's standing posture", () => {98+ it.effect("reads each project's posture from its own ledger", () =>99+ Effect.gen(function* () {100+ const standing = yield* withStandingPosture(listed);101+102+ expect(standing).toStrictEqual([103+ {104+ landedAt,105+ openAsks: 3,106+ posture: "openWithSealedEvidence",107+ project: datekit,108+ },109+ { openAsks: 1, posture: "openCore", project: ghost },110+ { openAsks: 0, posture: "sourceAvailable", project: broken },111+ { landedAt, openAsks: 2, posture: "open", project: burrow },112+ ]);113+ }).pipe(Effect.provide(platform))114+ );115+116+ it.effect("lists nothing for an empty list, and asks no project", () =>117+ Effect.gen(function* () {118+ expect(yield* withStandingPosture([])).toStrictEqual([]);119+ }).pipe(120+ Effect.provide(121+ Layer.succeed(Projects, untouchable<Projects["Service"]>("Projects"))122+ )123+ )124+ );125+126+ it.live("reads at most 8 projects at once", () =>127+ Effect.gen(function* () {128+ const under = yield* Ref.make(0);129+ const peak = yield* Ref.make(0);130+131+ const timed = Effect.acquireUseRelease(132+ Ref.updateAndGet(under, (count) => count + 1).pipe(133+ Effect.tap((count) =>134+ Ref.update(peak, (most) => Math.max(most, count))135+ )136+ ),137+ () => Effect.sleep(Duration.millis(10)),138+ () => Ref.update(under, (count) => count - 1)139+ );140+141+ const many = Array.makeBy(20, (at): ProjectListing => ({142+ openAsks: at,143+ posture: "open",144+ project: ProjectName.make(`p${at}`),145+ }));146+147+ const standing = yield* withStandingPosture(many).pipe(148+ Effect.provide(149+ Layer.succeed(150+ Projects,151+ Projects.of({152+ create: () => Effect.die("a listing makes no project"),153+ get: (project) =>154+ Effect.succeed(standingAt(project, "openCore", timed)),155+ })156+ )157+ )158+ );159+160+ expect(standing).toStrictEqual(161+ many.map((listing) => ({ ...listing, posture: "openCore" }))162+ );163+ expect(yield* Ref.get(peak)).toBe(8);164+ })165+ );166+});