Next.js 16 (App Router, Turbopack) + TypeScript + SCSS modules.
Needs Node 22.18 or newer (CI and the container use Node 26). The database
scripts and pnpm test run .ts files directly, which older Node
versions refuse. just doctor checks the version.
pnpm install
pnpm devOpen http://localhost:3000.
Copy .env.example to .env.local. The static pages run without it. The
data search and graph pages need SEARCH_API_BASE, which the sample points
at the proxy in Reach the dev APIs; the Studio needs a harness at
STUDIO_API_BASE and a STUDIO_TOKEN; accounts need DATABASE_URL and
BETTER_AUTH_SECRET. Email sign-in also needs a mail transport,
AUTH_EMAIL_FROM and the two Turnstile keys (.env.example has
Cloudflare's test keys for local use). Deployed, mail goes through the
Amazon SES API with SES_ROLE_ARN, SES_REGION and SES_TOKEN_AUDIENCE,
on temporary AWS credentials traded for the service account's Google ID
token minted for that audience. The role sends only as the address its
policy names, studio@developmentfinance.org, so AUTH_EMAIL_FROM and
FEEDBACK_FROM use that address in the same case, with or without a
display name. Locally, SMTP_HOST and the other SMTP settings point mail
at a mail catcher. To open the dev server from a
phone/tablet on the same network, put the machine's LAN IP in
DEV_ORIGINS.
The Studio has two layouts: classic, with the chat column, and prompt,
with the prompt box over the canvas. /studio?studio=prompt or
?studio=classic sets the studio_variant session cookie that picks one,
and a page with no cookie draws classic. Shares and gallery items always
draw classic. The cookie picks prompt only while STUDIO_PROMPT_ENABLED
is true, 1, on or yes. Unset or any other value draws classic on
every page. Every prompt request carries hold_removals, which an older
harness refuses, so turn the switch on after the harness that accepts
hold_removals is deployed, and off before that harness is rolled back.
A tab opened while the switch was on keeps sending hold_removals until it
reloads.
A live Studio share draws each card from dfo-apis' public slot card route
(GET /api/presentation/shares/{id}/slots/{n}), which checks for newer data
at most once per 15 minutes and takes no credential.
The dev apis service (dfo-dev-apis) admits only callers that hold
roles/run.invoker on it. The deployed site proves its identity with an ID
token from the Cloud Run metadata server (src/lib/apisAuth.ts); off Cloud
Run the site sends no token. Local work goes through gcloud run services proxy, which signs each call with your gcloud login:
gcloud auth login
gcloud run services proxy dfo-dev-apis --region northamerica-northeast1 \
--project dev-fin-observatory --port 8083Leave it running and set SEARCH_API_BASE=http://localhost:8083, as
.env.example does. Your account needs roles/run.invoker on the service,
directly or through a group; without it the proxy answers 403. Google does
not document whether the proxy renews its token after an hour, so if calls
start answering 401 or 403 later in a session, restart it.
The scripts below reach the APIs the same way.
just stack runs the dev apis proxy (8083) and the Studio harness (8080)
from an ai checkout beside this one, Mailpit, and the dev server, in one
terminal. Each output line starts with its service's name (apis, ai,
mail, web), in its own colour on a terminal, with lines that look like
errors in red (NO_COLOR=1 turns colour off). Ctrl-C stops them all:
gcloud auth login # the proxy cannot prompt for it under `stack`
just stackIt looks for the ai checkout at ../ai; pass AI_DIR=<path> for another
one. The harness needs ai's own setup first (just setup and just env
there), and its environment synced after pulling (uv sync --all-packages
in ai). The harness waits briefly for the proxy to serve the presentation
release. If the release is unavailable, the harness starts with a warning.
Restart the harness once the proxy is ready to load its presentation tools.
A service that exits on its own leaves the others running. Postgres runs
outside stack (see Database).
Mailpit catches the site's mail locally (brew install mailpit); just stack starts it when it is installed and port 1025 is free, and its inbox
is at http://localhost:8025. It listens on 127.0.0.1 only, since the
inbox holds sign-in codes that anyone on the network could otherwise read.
Point the site at it in .env.local:
SMTP_HOST=localhost
SMTP_PORT=1025The SMTP transport requires STARTTLS and checks the server's certificate,
so a plain mailpit refuses the site's mail. just mail-cert (run by
stack) makes a self-signed certificate for localhost in .mailpit/, and
just dev adds it to Node's trusted certificates, keeping any certificates
already configured through NODE_EXTRA_CA_CERTS. To run Mailpit by hand,
generate the certificate and bind both listeners to loopback:
just mail-cert
mailpit --smtp 127.0.0.1:1025 --listen 127.0.0.1:8025 \
--smtp-tls-cert .mailpit/cert.pem --smtp-tls-key .mailpit/key.pem --smtp-require-starttlsThe justfile is the entry point for the commands below. It
wraps the pnpm scripts (listed under Scripts) plus the container and deploy
workflows. just with no arguments lists everything. Install it with
brew install just if you don't have it.
| Section | Recipes |
|---|---|
| Setup & Configuration | setup, env |
| Development | dev, stack, mail-cert, start, optimize-svg |
| Database | db-up, db-migrate, db-reset, db-generate |
| Quality | lint, format, typecheck, test, build, studio-replay, bundles, workflow-lint, check |
| Container | docker-build, run-local, clean |
| Diagnostics | status, doctor, logs, deployed |
| Deploy config | set-dev-deploy-vars |
Run just <recipe> to see what each one does, or just --list for the
one-line descriptions.
Accounts and saved conversations live in Postgres, migrated by
db/apply-migrations.ts. db/migrate.ts runs it against Cloud SQL in
deployed environments, and db/migrate-local.ts runs it locally.
First-time setup:
just db-up # start a local Postgres container (postgres:18.4, port 5433)
just db-migrate # create the migrator/runtime roles and apply migrations.env.local's default DATABASE_URL (copied from .env.example) already
points at the website_runtime role db-migrate creates, so nothing else
to configure. Until just db-up and just db-migrate have run,
database-backed requests (sign-in, saved conversations) fail with a
connection error. The pnpm dev fallback that logs a warning and keeps
serving applies only when neither DATABASE_URL nor WEBSITE_DB_* is set.
A production start with no database fails outright.
The container uses port 5433 so it can run next to a Postgres installed on
the machine. If 5433 is taken too, set PGPORT to another port for
just db-reset, just db-migrate and pnpm test, and change the port in
.env.local's DATABASE_URL to match. db-up keeps the port a container
was created with, so switching ports, including moving an older container
off 5432, needs just db-reset.
Instead of the container, the database can live on a Postgres you already
run, such as a Homebrew postgresql@18 on 5432. Docker isn't needed for
that. It should be version 18, the version CI runs. db-migrate and the
tests read the superuser connection from PGHOST, PGPORT, PGUSER and
PGPASSWORD, which default to the container (localhost, 5433,
postgres, postgres). Set them for your server, for example in a
gitignored .envrc if you use direnv:
export PGHOST=localhost
export PGPORT=5432
export PGUSER="$USER" # Homebrew's superuser is your login name
export PGPASSWORD= # empty under Homebrew's default trust authChange the port in .env.local's DATABASE_URL to match, then run
just db-up && just db-migrate as usual. When something other than the
container answers at PGHOST:PGPORT, db-up starts no container. It checks
that PGUSER logs in as a superuser, warns if the server isn't version 18,
and leaves the rest to db-migrate.
On that server, db-migrate creates a website database and three roles:
website_migrator, website_runtime and the NOLOGIN
website_export_reader. Roles are cluster-wide, so they stay after the
database is dropped, and db-migrate resets the two passwords each run.
pnpm test creates randomly named databases and roles and drops them when
it finishes. just db-reset refuses to touch a server it didn't create. To start over
there, use the same connection defaults as db-migrate:
PGPASSWORD="${PGPASSWORD-postgres}" dropdb \
-h "${PGHOST:-localhost}" -p "${PGPORT:-5433}" \
-U "${PGUSER:-postgres}" website &&
just db-migrateSchema change workflow:
- Edit
db/schema.ts. just db-generategenerates a migration underdb/migrationsfrom the diff.- Review the generated SQL.
just db-migrateapplies it to the local database.- Commit the migration alongside the schema change.
Never run drizzle-kit push, drizzle-kit migrate, or better-auth migrate directly. Migrations apply only through
db/apply-migrations.ts (via db-migrate), which renders the
migrator/runtime role placeholders in migration 0000 and takes the
advisory lock that keeps concurrent runs from double-applying. The other
tools do neither. Never edit a migration that has already applied, even
locally. Write a follow-up migration.
In the dev environment, every deploy runs a migration Job against the same image before the service rolls out.
scripts/backfill-card-refs.ts gives Studio cards stored without a
component reference their ref and frame, in conversation.data and
share.data. A card needs both to be shared live. Cards saved before
3 October 2026 have neither and hold their values as csv.
node scripts/backfill-card-refs.ts # dry run: report only
node scripts/backfill-card-refs.ts --validate # counts and validation only
node scripts/backfill-card-refs.ts --write # write matched cardsIt reads the database from DATABASE_URL, or from the WEBSITE_DB_*
variables the runtime uses for Cloud SQL, and component revisions from
SEARCH_API_BASE. Node does not load .env.local, so set them on the
command line. Against dev, start the proxy from
Reach the dev APIs and pass
SEARCH_API_BASE=http://localhost:8083.
A card's id is its component id. The script reads every revision of that
component and takes the one revision that gives the card its title and its
values exactly (src/lib/studio/cardRefMatch.ts). A card that no revision
reproduces, or that more than one does, is left without ref and listed
with the reason. Text cards, cards that have ref, and search shares are
left as they are.
Every run prints the shares by kind and mode, the data cards with no
component reference, and the cards on a derived frame by week, for shares
and for conversations. It then validates the match on the cards saved with
their revision: it takes ref and frame off each, matches it, and reports
how many it recovered correctly, wrongly, and not at all. --write is
refused unless that run finds no wrong match over at least 300 cards, which
puts the wrong-match rate below 1% at 95% confidence.
--override-validation writes anyway.
A write changes one row per transaction and only the matched cards in it. Running it again writes nothing.
Changing any of these is fine if the workflows and deploy/Dockerfile change in the same pull request.
- pnpm is the package manager, with a committed
pnpm-lock.yamland apackageManagerfield inpackage.json. The pnpm setup inci.ymlreads its version from that field and fails without it. - TypeScript runs in strict mode on the Next.js App Router.
package.jsondefineslint,typecheck,testandbuildscripts, whichci.ymlruns.ci.ymlruns on every ready pull request, anddeploy.ymlcalls it on every push todev. It runs five jobs in parallel, each on its own checkout and install:static(client provenance, ESLint, Stylelint, typecheck),test(pnpm testagainst a Postgres service),replay(two shards, each building the site and playing half the Studio replay tests, with the first also checking the docs URLs),bundles(the fivedb/bundle builds andscripts/check-bundles.sh), andworkflow-lint(actionlint and zizmor, offline, at the versions pinned inci.yml, over.github). Thecijob passes only when every other job succeeds, and it is the check the branch rulesets require.just checkruns the same steps one after another, except the docs URL check.deploy.ymldeploys to the dev service oncecipasses, when the push changes a file outsideprototypes/and.github/workflows/deploy-prototypes.yml.next.config.tssetsoutput: 'standalone', sodeploy/Dockerfilecan copy the standalone server into the runtime image.
dev is the default branch. Contributors branch from it and open a pull request into it. The ci check has to pass before merge, and force-pushes are blocked. Each merge deploys to the dev service.
main is production. To release:
- Confirm the
devcommit you want is deployed and validated on the dev service. - Open a pull request from
devintomain.mainrequires one approval and thecicheck, and blocks force-pushes and deletion. - Merge it.
deploy-prod.ymlbuilds and deploys that commit once the release reviewers approve theproductionGitHub Environment. - Tag it:
git tag prod-YYYY-MM-DD <sha> && git push origin prod-YYYY-MM-DD.
The services run in the dev-fin-observatory GCP project, region northamerica-northeast1. GitHub Actions builds the dfo-website image and updates the Cloud Run dev service after ci passes on a push to dev that changes a file outside prototypes/ and .github/workflows/deploy-prototypes.yml. infra owns the Cloud Run service definition (service account, scaling, secrets, environment variables). This repository's CI only swaps images onto the service infra defined. just deployed prints the live service's URL, revision and image, and just logs tails its logs.
The apis, ai and dcp repositories run their own dev services. apis and ai return 404 at the root and serve Swagger UI at /docs. deploy/README.md lists the GitHub variables, secrets and GCP prerequisites.
LIBRARY_ENABLED on the Cloud Run service decides who sees the Library. Exactly true opens it to everyone. Unset or any other value keeps /library and its artifact pages to the admins on ADMIN_EMAILS, who publish from the Studio and edit artifacts as usual while their Library pages say noindex, and answers everyone else with the site's 404. While it is off the footer leaves out its Library link and the sitemap leaves out every Library URL. infra sets the variable, and a new revision applies it with no rebuild: the Library pages and the sitemap render per request, and the footer asks GET /api/library/enabled in the browser, since a page prerendered at build time holds the build's environment.
A publish makes an unlisted share in dfo-apis, which anyone with its /s/ link can open while the Library is off as well, so preview publishing is for material already cleared for public access.
Withdrawing an artifact (Delete in its Edit dialog) first takes its share down in dfo-apis, or records it in share_cleanup when dfo-apis cannot. Once one of those holds, one statement sets withdrawn_at and clears the share token, and the library_artifact_erase_withdrawn trigger (migration 0033) erases the title, description, text section, sources, steps and topic links of any row written with withdrawn_at set. The row keeps its slug, kind, mode, dates, publisher reference, share id and publish key. The slug stays taken, so a cited URL keeps naming the artifact and says it was withdrawn and when. The publish key makes a retried publish answer artifact_withdrawn, and the share id names the share an operator looks up. When neither the take-down nor the record succeeds, DELETE /api/library/artifacts/<id> answers a retryable 502 transient_unavailable and changes nothing, so the artifact stays published and a second Delete tries again.
db/check-library-shares.ts (node dist/check-library-shares.cjs in the image, a daily Cloud Run Job) proves that every published Library artifact reads and draws as its page draws it. It lists the library_artifact rows with no withdrawn_at and reads each one's share from dfo-apis (GET /api/presentation/shares/{id}) with the runtime service account's ID token. The share's mode must be the artifact's. For each card the page shows from a slot (shownPageCards in src/lib/studio/slotCards.ts: the payload's held data cards among those the share shows through shownCardsOf in src/lib/chat/canvas.ts, the rule EmbedView and the Library page apply, which is every card its canvas shows and only the first for a card share, or every filled slot when the payload has none) it reads and draws the slot's card (GET .../slots/{n}) through the page's own read, slotTargetOf and readSlotTarget in src/lib/share/cardLoad.ts, uncached, which refuses a snapshot slot's answer on another frame or of another card. Then it reads each such slot's JSON rows (GET .../slots/{n}/data). A card the canvas hides, such as an older live card the latest turn replaced, holds no slot and is not read. It checks four artifacts at a time, each making its reads in turn. Each artifact's line names it by artifact (its id) and slug, with result (ok, failed or unfinished). No line carries a share id. Each failed read is one JSON log line with event library_share_check_failed, severity ERROR, and the read's read (share, card or data), slot, widget, class, status, dfo-apis' code and retryable. The classes are share_gone (the share answers 404, so the page shows nothing), empty_slot (the page draws a card from a slot that holds none, or names no slot), undrawable (a slot's card resolves nothing the page can draw), frame_unavailable (a slot's card or rows answer 404 frame_unavailable), no_rows (a live slot answers 200 with no rows; a snapshot keeps the rows it was published with), refused (any other refusal, a data card whose slot records no frame, a snapshot slot that answers another frame or card than its record pins, a share whose mode is not the artifact's, with code mode_mismatch, or an answer that arrives but cannot be read) and transient (a 5xx, a 429, a timeout, or an answer that never came or stopped before its end). The class names the fault, and retryable decides whether the read is made again: a read that met no answer, a 429, a 5xx with no problem document, or a refusal dfo-apis marks retryable (a frame_unavailable whose frame is expired or pending, a service_unavailable). An artifact whose failures are all final is logged as it finishes, as is one that reads (library_share_check_ok). After 30 seconds the run makes each retryable read again, alone, and logs its artifact. The run stops 57 minutes after the command starts (RUN_DEADLINE_MS), three minutes under the Job's 3600 s task timeout, which leaves time for the container's start, the log lines and the pool's close. The deadline aborts every read in flight and the wait before the second reads, and no read starts after it. Each artifact without a verdict by then logs a line for each failure its reads met before the deadline, then one library_share_check_failed line with class unfinished, code run_deadline and read null. A read the deadline cuts off is left out, and a second read it cuts off leaves the first one's failure. Opening the pool and listing the artifacts spend the same deadline, so a database that never answers ends the run with a check_failed line of code run_deadline. A share whose payload holds malformed canvas fields reads as a save without them, as the viewers read it, and a payload the check still cannot read fails that artifact alone, as refused with code payload_invalid. The run's last line, library_share_check_summary, counts the artifacts, the unfinished ones, the failures by class, the reads made again, and the requests, response bytes and milliseconds the run took. A run that cannot run at all, for want of a setting or the database, logs one library_share_check_failed line with class check_failed and the error's code. The job exits 1 when any artifact fails after the second read, any is unfinished, or the run cannot run, and 0 otherwise, including when no artifact is published. A log-based metric on jsonPayload.event="library_share_check_failed" is the alert hook, so keep that name unchanged. Run it locally with DATABASE_URL and SEARCH_API_BASE set, after pnpm build:check-library-shares.
db/backfill-card-cites.ts (node dist/backfill-card-cites.cjs in the image) gives each stored citation of a published Library artifact the id of the card it cites (LibraryCardCite.card), so the page reads a card's citation by its id. An artifact published before citations named their cards holds them in its share's page order (shownDataCardIds), so the backfill reads each share from dfo-apis and names the citation at each place by the card at that place. It writes an artifact only when its share shows as many distinct data cards as it holds citations, and only while its citations equal the ones it read. Each artifact gets one library_card_cites_backfill log line with its outcome, and the run ends with a library_card_cites_backfill_summary line counting them. The run exits 1 when an artifact was left unnamed for a fault an operator can act on (unreadable, count_mismatch, duplicate_ids or changed), and 0 otherwise. share_gone and mixed are permanent states, logged and counted apart.
Run it dry first, which logs what a write would do and writes nothing, then with --write:
- On Cloud Run, as an execution of the Library share check Job, whose command is
node, with its arguments overridden:gcloud run jobs execute <library share check job> --region northamerica-northeast1 --wait --args=dist/backfill-card-cites.cjs, then again with--args=dist/backfill-card-cites.cjs,--write. The Job holds the database settings and the service account that dfo-apis accepts. - Locally, with
DATABASE_URLand aSEARCH_API_BASEthat reaches dfo-apis through an authenticated proxy:pnpm build:backfill-card-cites, thennode dist/backfill-card-cites.cjsandnode dist/backfill-card-cites.cjs --write.
A publish and an edit of a live artifact's text hold the text to the evergreen rule. A snapshot's data stays as published, so its text is not checked. The text says what the data measures and how to read it, and leaves the figures to the data, which refreshes after publication while the text stays as written. src/lib/library/evergreen.ts splits the title, description, section heading and section text into sentences and sends each sentence to TypeSafe's Jev model (MODEL in src/lib/library/evergreenRule.ts, pinned to a release) in a request of its own, up to REQUEST_CONCURRENCY (8) at once. A line ending in a colon and the list items after it that carry no full stop, ! or ? make one sentence, since an item such as "Norway" says nothing without the line that introduces it. The request's state holds the sentence and its part (title, description, section heading or section text) and nothing else. Five Nouls ask about it. stale asks whether a data refresh could make the sentence false or out of date. value, ranking, change and period ask whether it states a figure, an order, a movement or a dated result, each with structured criteria and examples, and the highest of them names the claim's kind. The criteria count text that names the kind of view without stating the result, such as "Latest data", "Top 10 recipients" or "Trend in aid to agriculture", as evergreen.
decide refuses a sentence when its stale Noul is at least T_HIGH (0.8) and its highest kind Noul at least T_KIND (0.5). A title or section heading that names a range of years ("2013 to 2022", "2000–2023", "between 2016 and 2021") is refused in code whatever the answers, since the chart outgrows the range when new data arrive. So is one that names a single year as the data's period, as the object of "in", "for", "during", "as of" or "at end" ("Total ODA in 2023") or after a closing comma, colon or dash ("Bilateral giving by member, 2023"). A year after "since", "from", "compared with", "relative to", "before", "after", "base year" or "prices", or before "prices" or "dollars", is a base or a start, and one after "target", "goal", "agenda" or "deadline" dates a goal. Neither counts (namesDataYear). Both year rules apply only while some data card's periods can move. When any sentence of the text names a year from 1900 to 2099 (namesYear), the check reads each data card's period_mode from dfo-apis (GET /api/presentation/components/{id}?revision={n}, allPeriodsFixed in src/lib/library/periods.ts). The publish reads the cards it shares, and an edit reads the slots of the artifact's share. When every card is fixed, as with a chart pinned to 2023, the year rules spare the title and headings, and the period Noul names no claim, since a fixed period cannot go stale. A sentence then passes without a warning unless its value, ranking or change Noul is at least T_KIND, and with one that high it warns or is refused by its stale Noul as any sentence is. A missing or unknown period_mode (mode_missing, mode_unknown), a card with no revision (no_revision), no data card (no_cards), a refusal, or no answer within PERIOD_DEADLINE_MS (3 s) counts as rolling and is logged as library_period_mode_unknown with that cause. The reads run beside the TypeSafe requests, inside CHECK_DEADLINE_MS. Years in a description or section text are left to Jev. A refused sentence makes the route answer 400 not_evergreen with one entry per sentence in errors. Each entry holds pointer (the field, as /content), start and end (offsets into the field as the server stores it), quote, kind and reason. A sentence passes with a warning when its stale Noul is between T_LOW (0.3) and T_HIGH, or at least T_HIGH with no kind Noul at T_KIND. The publish's 201 or 200, the edit's 200 and the 400 all carry warnings, a list of { pointer, start, end, quote, kind }. An edit checks only the fields it changes. Nothing is stored and no share is made until the text passes.
The check fails closed, and publishing stays closed until TypeSafe answers again. Without TYPESAFE_API_KEY, or when TypeSafe times out, rate-limits, fails, answers with another model or leaves a question unanswered, the route answers 503 evergreen_check_unavailable with Retry-After: 5. Each request gets one retry, which ignores a longer Retry-After, and the whole check stops after CHECK_DEADLINE_MS (12 s). When TypeSafe refuses the text itself, with a 400 or a 413, the route answers 502 evergreen_check_refused, which a retry would not mend. Any other 4xx answers 503. Text of more than MAX_CANDIDATES (160) sentences in all is refused before any call, with 400 evergreen_too_long at the field that passes the limit and the limit in limit. That is 20 rounds of 8 requests, which at the recorded 95th-percentile request time of 0.29 s take about 6 s. Only the publish and edit routes call TypeSafe, so the server starts and every page works without the key. The log lines carry no text. Each names the artifact by its id on an edit or its publish key on a publish. library_evergreen_unavailable and library_evergreen_refused give the cause (missing_key without the key) and status. library_evergreen_not_evergreen logs each refused sentence and library_evergreen_doubt each warned one, with the field, offsets, kind and all five Nouls in nouls, and the refusal also names its rule (nouls, year_range or data_year).
The thresholds are fitted on the dev set of 294 sentences, 219 of them evergreen. Of these, 73 come from src/lib/library/test/evergreen/labelled.json, sentences in the style of Studio text, less the 10 the criteria quote. The other 221 are the sentences of the 45 whole artifacts in eval-candidates.json and eval-additions.json, labelled in eval-labelled.json and eval-additions-labelled.json as the routes split them. Errors, as false blocks and misses, by threshold:
T_HIGH |
T_KIND 0 |
0.25 to 0.45 | 0.50 | 0.55 | 0.60 |
|---|---|---|---|---|---|
| 0.70 | 5 / 1 | 1 / 2 | 1 / 2 | 1 / 2 | 0 / 3 |
| 0.75 | 4 / 1 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 3 |
| 0.80 | 4 / 1 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 3 |
| 0.85 | 4 / 1 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 3 |
| 0.90 | 1 / 3 | 0 / 4 | 0 / 4 | 0 / 4 | 0 / 5 |
T_HIGH 0.8 and T_KIND 0.5 sit inside the flat region. T_KIND 0 is the refresh Noul alone. The two misses both warn: "The figure for 2024 is preliminary and may be revised." (stale 0.57) and "Adaptation finance is still far below what countries need." (stale 0.92, no kind Noul above 0.1). Every one of the 24 artifacts with a claim has a refused sentence, and none of the 21 evergreen artifacts does. Asked five times, no sentence's refusal changed. stale Nouls moved by up to 0.19, and 256 of 294 stayed within 0.05.
Two held-out sets, which no fit reads, check the rule on artifacts that share no sentence with the dev set or with each other, each labelled blind by a second model. The figures below replay their recordings through the check as it ships, at 0.8 and 0.5.
holdout-candidates.json holds 30 artifacts, labelled in holdout-labelled.json, covering definition lists, lists under a lead-in, years in titles, "latest" and "top" labels, and noun-phrase titles. Of their 128 sentences, 18 are not evergreen. The check refuses 2 of 110 evergreen sentences (1.8%), both descriptions that name a top list ("The recipients that took the most bilateral aid in one year."), and lets 1 of 18 claims through (6%), the heading "Recent rise", with a warning. Every one of the 18 artifacts with a claim is refused, and 1 of 12 evergreen artifacts is refused, on its description.
holdout2-candidates.json holds 21 artifacts, labelled in holdout2-labelled.json. Half name a year in a title or heading as the data's period, a base year, a range, the date of a method or an edition, or the latest year, and the rest are ordinary artifacts. Of their 87 sentences, 11 are not evergreen. The check refuses 1 of 76 evergreen sentences (1.3%), the heading "Why the line breaks in 2018", whose year dates a method and which namesDataYear reads as a period. It lets 1 of 11 claims through (9%), the title "Debt statistics, 2024 edition" (stale 0.52), with a warning. 9 of the 10 artifacts with a claim are refused, and the one that passes warns on its missed title. 1 of 11 evergreen artifacts is refused, on that heading.
TYPESAFE_API_KEY=<dev key> node scripts/fit-evergreen.mjs sends every dev sentence as the routes do, writes the answers and the model to recorded.json and eval-recorded.json, and prints the errors for each pair of thresholds. node scripts/fit-evergreen.mjs --sweep prints the same from the recordings with no call. --holdout and --holdout2 send a held-out set, write holdout-recorded.json or holdout2-recorded.json and print the errors at T_HIGH and T_KIND, and with --sweep they reprint them with no call.
src/lib/library/test/evergreenReplay.test.ts and src/lib/library/test/evergreenEvalReplay.test.ts replay the four recordings in CI against the lists of sentences the rule is known to misjudge (KNOWN and known). A change to MODEL, to the questions, to the sentence splitting or to the thresholds changes the requests' digests or the decisions, and fails until the sets are recorded again or the lists updated.
prototypes/ lives on the prototypes branch and builds and deploys apart from the website. deploy-prototypes.yml publishes that branch to developmentfinance.org/prototypes* on each push to it and previews pull requests into it. prototypes-sync.yml merges every push to dev into prototypes, opening a pull request when the merge conflicts or touches .github/workflows/, and prototypes-daily.yml rebuilds it every morning so its figures follow DFO. deploy.yml and deploy-prod.yml ignore prototypes/. Branch from prototypes to work on a prototype; its prototypes/README.md covers adding one, building and previewing locally, and the deploy secrets.
The site serves /docs, the Markdown twins, the llms files and docs search from one corpus, in the layout of the docs corpus contract (docs/contracts/docs-corpus.md in the dfo-docs repository). Two settings choose where it comes from, read in this order:
DOCS_BUCKETnames the bucket thedfo-docspublisher writes: a bucket name orgs://<name>on Cloud Run, or afile://URL or absolute path for a directory laid out the same way. The site serves the version thatcurrent.jsonnames.DOCS_CORPUS_DIRnames a corpus directory, read once per process.
With neither set, the docs pages, Markdown twins, llms files, docs search and skill zips answer 503, the first such request logs a docs_corpus_unconfigured line, the Roadmap page fails and its vote writes answer 503, and the rest of the site works. A production server refuses to start without one of the two (src/instrumentation.ts). At startup the server loads the served corpus before it takes requests, waiting up to 8 s (DOCS_LOAD_WAIT_MS in src/instrumentation.ts, run by awaitDocsWarmup in src/lib/docs/source/warmup.ts), and logs a warning when the load fails or outlasts the wait. After a timeout the load keeps running and the first docs request waits for it. After a failure with DOCS_BUCKET, docs requests answer 500 until the pointer's 60 s check interval has passed, even when the bucket has recovered, and the first request after that loads the corpus again. After a failure with DOCS_CORPUS_DIR, the first docs request opens the directory again. Next opens the port before that wait ends and holds requests until it does, so Cloud Run's HTTP startup probe on /robots.txt keeps a new instance out of traffic, and on full CPU, until the corpus has loaded. For a local run without a published corpus, set DOCS_CORPUS_DIR to the absolute path of the fixture corpus, src/lib/docs/test/fixtures/corpus.
The Roadmap page (/data/roadmap) and POST /api/roadmap/votes read the roadmap from the same corpus version, the roadmap.json and roadmap/<track>.json files the contract describes, through src/lib/roadmap/. The docs pointer refuses a version whose roadmap breaks its schemas, as it refuses a page that fails to compile. A version without a roadmap still serves the docs, and every instance treats it alike: the Roadmap page answers 200 with a "roadmap unavailable" line and a noindex robots tag, vote writes answer 503 with a roadmap_votes_unavailable line, and a roadmap_missing line goes to the log at ERROR, once per version and then at most once a minute. While no corpus loads, the Roadmap page fails as the docs pages do, and vote writes answer 503.
The page keeps its state in the query (view, tab, filter, release), so /data/roadmap?view=released&tab=<track>&release=<id> is a release's permalink, with the release's title and description in its metadata (src/lib/roadmap/released.ts). Release and category links always name the track, so they survive a reordering of the tracks. /data/roadmap/released.md is the Markdown twin of the Released view, every track or the one ?tab= names, narrowed by ?filter=. The page's copy button builds the same Markdown from the roadmap the page rendered, so it copies what the reader sees. Reads of the twin log docs_read like the docs twins.
The header, footer, Build tools and API keys links into the docs come from a fixed list in src/lib/docs/nav.ts, so the root layout never reads the corpus and a corpus outage costs only the docs routes and the Roadmap page. Each path in that list is in required-pages.yaml in dfo-docs, whose publish refuses a corpus that lacks one, and refuses a version that drops a page the live version serves without a redirect. The sitemap lists the pages of the live corpus, and leaves them out with a logged line when the corpus cannot load.
The docs home (DocsHome) links to a second fixed list of pages, DOCS_HOME_JOBS, DOCS_HOME_MACHINES and DOCS_HOME_SETUP_PATHS in src/lib/docs/layout/home.ts, and takes each link's title and note from the page's title and description. Each of those paths belongs in required-pages.yaml with used_by: docs home, so add a path there before linking to it. A path the live corpus lacks drops out of the home, a group left with no links shows nothing, and the first request on that version logs a docs_home_pages_missing line.
With DOCS_BUCKET set, the first docs request reads current.json and loads the version it names, so a bucket outage costs only the docs routes and the Roadmap page. After that, a docs request that finds the pointer more than 60 s old starts one check and is answered from the live version while the check runs. A new version is unpacked into its own directory under the system's temporary directory, and every page is opened and compiled before the site serves it, the pages of a held blog included. The site keeps the live version and logs a docs_corpus_refused line at ERROR when the pointer cannot be read or the new version fails a check: an archive that does not match the pointer's SHA-256, a broken archive, another contract version, a page that does not parse or compile, a page body whose server components throw. That last check renders each served page's body through React's server component renderer, as a request does (prerenderPageBody in src/components/organisms/DocsShell/pageBody.tsx, run by renderCorpusPages in src/lib/docs/source/prerender.ts). Client components, such as tab sets, code blocks and diagrams, run only when a request renders the page to HTML, so a client component that throws is outside the check. The compiled pages are kept for the pages to serve. It logs docs_corpus_loaded when it moves to a version. It does not download a refused archive again while current.json names it, and each check (the first docs request after 60 s) logs the same docs_corpus_refused line again, so the alert on that line stays open until the pointer names another version. An instance with no live version whose pointer names a version it refuses loads the pointer's previous version instead and logs docs_corpus_loaded with fallback: true; when neither loads, docs requests answer 500 at once until 60 s have passed. src/lib/docs/source/pointer.ts holds the rules.
GET /api/docs/corpus is the route an uptime check calls. Cloud Run throttles the CPU of an idle instance, so a check started beside a page request can stall once the page has answered. This route waits for the check. When 60 s have passed since the last check it runs one, when a check is running it joins it, and otherwise it answers from the last check, so calls inside the interval read nothing from the bucket. It answers { "live_version", "pointer_version", "fallback" } with Cache-Control: no-store: 200 when the site serves the version current.json names, and 503 when it serves a fallback (a refused version, or a pointer it cannot read) or has no corpus. With DOCS_CORPUS_DIR it answers 200 with the directory's version and a null pointer_version. The route writes no log line of its own. A due check logs as any check does, so a probe once a minute keeps a refused version's docs_corpus_refused lines coming. src/lib/docs/source/corpusStatus.ts holds the handler.
The skill zips at /docs/<path>.zip come from the live version's files/ in the bucket (src/app/docs-files), or from the DOCS_CORPUS_DIR corpus, where they sit at their paths.
Cloud Run reads the bucket with the runtime service account's token from the metadata server, so a gs:// bucket works only there. For a local run, publish a corpus to a directory and point the site at it:
# in dfo-docs: build a corpus, then publish it into a directory bucket
uv run dfo-docs-publish --site-out <corpus dir> --bucket /tmp/docs-bucket
# in the website
DOCS_BUCKET=file:///tmp/docs-bucket just startpnpm test:docs checks a running site against the URL list of the fixture corpus, src/lib/docs/test/fixtures/corpus-urls.json, so the site under test serves that corpus through DOCS_CORPUS_DIR, as CI's "Docs URLs" step does. With DOCS_E2E_BUCKET_DIR set to the directory the site reads, it also publishes a new version there, checks that the site serves it within a check interval, checks that a corrupt version after it is refused, then puts the pointer back and removes the versions it wrote.
The docs pages render in the Fumadocs docs layout (DocsShell in src/components/organisms/DocsShell, which each docs page renders around its body): area tabs under the site header, a sidebar with the docs search button, and the page with its outline.
The area tabs come from the tabs list in the corpus's root meta.json ({ "title", "icon", "paths" } rows, docs corpus contract "Tabs"). A page belongs to the tab whose paths entry is its longest prefix on path-segment boundaries, and the docs home belongs to none. Each tab that holds a page becomes a root folder of the page tree, so the sidebar shows the tree of the current page's tab, and a tab with no pages is hidden. A corpus with no tabs list shows one sidebar over the whole tree and no tab row. tabbedTree in src/lib/docs/layout/tabs.ts holds the rules. A tab's icon names a site icon (Icon); a name the site lacks shows no icon.
The API reference at /docs/reference/api, built from dfo-apis's OpenAPI document (src/lib/docs/reference), is served only while DOCS_API_REFERENCE is on (apiReferenceServed in src/lib/docs/reference/reference.ts). Otherwise its pages and twins answer 404, it leaves the Reference tab, docs search, the sitemap and llms.txt, the Try-it proxy at /api/docs/playground answers 404, and the site never reads the OpenAPI document.
The Technical blog, the corpus's tech-blog folder, is served once the corpus holds a finished essay: a page with template: essay and no status: draft (essaysPublished in src/lib/docs/source/essays.ts). Until then openDocsCorpus leaves the folder out, so its tab is hidden and its pages, twins and RSS feed answer 404. Publishing the first finished essay brings the blog in with that corpus version.
Below 768 px, where Fumadocs turns its sidebar into a drawer, a docs bar under the site header shows the reader's place ("Docs › Reference › API") and opens the drawer (DocsBar in src/components/organisms/DocsShell/DocsBar.tsx). The drawer starts with the docs search box, then the area tabs, then the page tree.
GET /api/docs/search?query=<text>&limit=<n> searches the docs corpus the site serves. It feeds the docs search box (DocsSearchBox). query holds 1 to 200 characters and limit is 1 to 20 pages (default 8). The answer is JSON:
{
"query": "share embed",
"version": "20261203T090000Z-4c73448",
"results": [
{
"title": "Share live data or a snapshot",
"url": "/docs/build/share#live-or-snapshot",
"twin": "/docs/build/share.md",
"section": "Build with the DFO",
"heading": "Live or snapshot",
"excerpt": "A live link reads the data each time it opens.",
"sections": [
{
"url": "/docs/build/share#live-or-snapshot",
"path": ["Live or snapshot"],
"excerpt": "A live link reads the data each time it opens."
}
]
}
]
}results lists one entry per page, best first. url carries the matched heading's anchor when there is one. twin is the page's Markdown twin, and null for a page that links out to an external package's docs. section is the top-level docs section, null for a page at the top. heading is null for a passage above the page's first heading. excerpt is plain prose of about 160 characters around the first matched word, with the corpus's alert and tab syntax removed. sections lists up to three matched sections of the page, best first, the first being url, heading and excerpt. Each section has its url, its heading path (from the first heading below the page title down to its own, empty above the first heading) and its excerpt. version names the corpus the results come from.
The index lives in memory, one per corpus object (src/lib/docs/search/). The first search after a new corpus loads builds it. The route takes no API key and counts against no visitor allowance. Each address gets RATE_LIMIT_DOCS_SEARCH calls per rate-limit window (default 300), on a counter of its own. A call over it answers 429 rate_limited with Retry-After, and a bad query or limit answers 400 request_invalid.
| Script | What it does |
|---|---|
pnpm dev |
Dev server (Turbopack) |
pnpm build |
Production build (standalone output) |
pnpm start |
Serve the production build |
pnpm lint |
ESLint |
pnpm typecheck |
tsc --noEmit |
pnpm test |
Migration integration tests (just db-up first) |
pnpm test:studio-replay |
Recorded Studio conversations on both layouts (pnpm build first) |
pnpm lint:css |
Stylelint (SCSS, BEM pattern) |
pnpm lint:css:fix |
Stylelint with autofix |
pnpm format |
Prettier over src/ |
pnpm optimize:svg |
SVGO over src/assets (run after adding) |
pnpm db:generate |
Generate a migration from db/schema.ts |
pnpm db:migrate:local |
Apply migrations to the local database |
pnpm test:studio-replay plays every recorded Studio conversation in e2e/studio-replay/fixtures/ to its end on both layouts, ?studio=classic and ?studio=prompt, against the production build. It starts the standalone server on a free localhost port with a made-up environment that reaches nothing, opens each conversation in headless Chromium, and answers every request the page makes from the recording, so no model, harness or search service runs. A run fails on a console error, a page error, a request no route answers, a request the recording did not expect, or a page that does not show what the recording says. The page must show the plan or question at each pause, and at the end as many cards as the last canvas holds and the start of the last reply. pnpm test leaves it out. CI's replay job runs it after its build.
The same run plays the chart on the Prompt layout at a phone's width and with reduced motion, card changes through the page's own controls (e2e/studio-replay/regressions.ts), with the harness's answers built from the recorded cards (changes.ts), and placeholders for coming cards (placeholders.ts), from recordings with the contract's coming and placeholder_id members added (coming.ts). A reply shown twice, a placeholder left at the end of a turn, and a second turn or answer request while a stream is open also fail it. Two of them need a signed-in reader, since only an account's page saves its conversation and reads the harness's state. For those, account.ts creates a database of the run's own on the Postgres that pnpm test uses (PGHOST, PGPORT, PGUSER, PGPASSWORD), migrates it, adds a test account with one session, and drops it at the end. The account, its session token and the site's auth secret are made per run and appear in no output. Without a reachable Postgres those two fail and name the variables to set. With STUDIO_REPLAY_NO_DB=1 they are reported as skipped instead.
Run it locally after pnpm build, or with just studio-replay, which builds first, with the PG* variables you give pnpm test. It takes about three minutes. STUDIO_REPLAY_SHARD=i/n runs the i-th test and every n-th after it, in the order the file declares them, so the runs for 1/n to n/n together play every test once. CI runs 1/2 and 2/2 in parallel. A value other than i/n with 1 <= i <= n fails the run before any test starts. Before the first run, install the browser with pnpm exec playwright-core install --only-shell chromium.
A fixture is one conversation: its name, a description, and its turns, each with the question the test types and the harness's stream in segments. The first segment answers the question's POST /api/studio/turn. Each later segment answers the POST /api/studio/interrupt the page sends at the pause the segment before it ended on, a plan (plan.proposed) or a clarifying question (elicitation.request), and carries act, how the test answers that pause ({ "kind": "approve" }, or { "kind": "answer", "picks": { "q1": "<option label>" } }), and expect, the members the interrupt request must carry. Frames are the harness's data: frames in the order it sent them.
To record one, run the stack (just stack), send the question from Studio, and save each response body of /api/studio/turn and /api/studio/interrupt from the browser's network panel or with curl -N. Then:
node e2e/studio-replay/fromStream.ts <name> "<question>" turn.sse [interrupt.sse ...] > e2e/studio-replay/fixtures/<name>.jsonAdd act and expect to each later segment, a description, further turns by hand, and the name to SCENARIOS in e2e/studio-replay/scenario.ts. The repository is public, so before committing a fixture, reword any question a person typed unless it is one of the landing page's examples (src/lib/studio/examples.ts), and search it for credentials, tokens, email addresses, internal hostnames and session links. Keep every value as the harness sent it.
pnpm test:visual --base <url> --head <url> screenshots the same routes on two running servers and counts the pixels that differ, so a styling change needs no committed baseline. Build the base revision and the head revision, start each on its own port with the same environment (the same .env.local, or the same API_KEYS_ENABLED=false VISITOR_LIMITS_ENABLED=false and database), and run:
pnpm test:visual --base http://localhost:3201 --head http://localhost:3202The command refuses to run when --base and --head share an origin. It captures the routes in e2e/visual/routes.ts (home, docs, a deep docs page, data, sources, about, AI policy, Studio, an embed 404 and the site 404) and one scripted capture that opens /docs, follows the header's home link and shoots the page after the client navigation. That capture sets a window marker before the click and fails when the marker is gone on /, which means the link did a hard navigation. Each capture runs at 1440x900 and 390x844 in headless Chromium with reduced motion, loaded fonts, an idle network, and classic scrollbars drawn.
Each route declares the status of its main document (200, or 404 for the two 404 routes). A capture fails when either server answers another status, when a page raises a pageerror, when the page size differs between the servers, or when a mask matches no element.
Parts of the site animate or draw at random: the home page's canvas and Studio's example questions. They carry a data-visual-noise attribute, which the harness paints over, and Math.random is seeded. Other noise is measured. A capture shoots the base twice and the head once, one after the other, and the pixels that differ between the two base shots form a noise mask that the head comparison leaves out.
A capture passes when no more than --max-pixels <n> pixels differ outside the masks and the noise (default 0). --out <dir> sets the report directory (default visual-report, ignored by git). The directory holds <route>-<viewport>.base.png, .head.png and .diff.png for each capture and a summary.json with each capture's differing and noise pixel counts and its result. The command exits 1 when a capture fails, and 2 on bad arguments. The browser installs as for the Studio replay test.
The Search, Datasets and Graph types come from @developmentfinance/client, vendored as vendor/developmentfinance-client-0.10.0.tgz. The tarball is the typescript/ package of the sdk repository, built and packed. It records only its package version, so vendor/developmentfinance-client.provenance.json beside it names the sdk commit it was packed from and the spec-kit revision that commit's contract/SOURCE pins. To refresh the tarball, pack that package into vendor/, update the provenance file, and re-lock:
cd <sdk checkout>/typescript
pnpm install && pnpm run build
pnpm pack --pack-destination <website checkout>/vendor
cd <website checkout>
just relock-clientWrite the sdk checkout's git rev-parse HEAD as sdk.commit and its contract/SOURCE as spec_kit.commit in the provenance file, both as full hashes. Name the sdk commit in the subject of the commit that vendors the tarball, as the earlier ones do (chore(deps): vendor the client at sdk 82701c8), and keep it in the pull request title, since a squash merge takes its subject from there. CI's pnpm check:client-provenance (scripts/check-client-provenance.mjs) fails when the provenance file names a tarball other than the one package.json installs, when either hash is not a full commit hash, or when the last commit that touched the tarball names no sdk commit or a different one from the provenance file. It reads the git log, so run it after committing.
A new package version packs under a new file name. Point the @developmentfinance/client entry in package.json and the provenance file's package at it, delete the old tarball, then re-lock. just relock-client deletes the client's stale directory under node_modules/.pnpm (pnpm keeps an installed file: package of the same name and version, so a rebuilt tarball is otherwise ignored), has pnpm re-resolve the client's lockfile entries from the tarball with pnpm install --lockfile-only --fix-lockfile, runs pnpm install --frozen-lockfile, and imports the client to prove it loads. The re-lock needs the registry. It changes the client's entries and those of any dependency the new tarball adds. pnpm 10.34.9 also fills in deprecation notices and writes eslint-plugin-import's peer suffix in one of two equivalent forms, so a re-lock can touch those few lines too. Commit the tarball and the lockfile together.
The tarball carries the statuses of the codes the proxy raises itself and not their descriptions. src/lib/proxy/proxy-codes.json holds the full file, copied from the spec-kit repository's python/client-contract/src/dfo_client_contract/proxy-codes.json and formatted with Prettier. Copy it again when the client contract changes it.
- Styles: global partials live in
src/styles(_variables,_mixins,_breakpoints, …). They are on the Sass load path, so import them from anywhere as@use "variables" as *;with no relative paths. Fluid rem sizing,html { font-size: vw(16px) }, scales the whole layout with the viewport (separate bases for desktop, tablet and phone, see$widths). Size things withrem()and@include font-size(), and write every design px value asrem(x). Breakpoints are@include breakpoint(phone)(< 660px) and@include breakpoint(tablet)(660–1023px). - Tailwind is for the docs pages only.
src/app/(site)/docs/docs.csscompiles Tailwind v4 (@tailwindcss/postcss,postcss.config.mjs) withsource(none), and its@sourcelines name the only files it scans:src/app/(site)/docsandsrc/components/organisms/DocsShell. Write Tailwind classes there and nowhere else; every other component uses its SCSS module. Next keeps a route's stylesheet after a client navigation away from it, so no rule indocs.cssmay match markup outside the docs layout: key a rule to[data-docs-scope], whichDocsShellrenders, or to a Fumadocs id. Tailwind's preflight and Fumadocs' base rules come in throughpreflight.scoped.cssandfumadocs-base.scoped.css, whichnode scripts/scope-docs-css.mtswrites from the installed packages, each rule limited to[data-docs-scope], Fumadocs' search panel (#fd-search-dialog-content, which portals to<body>), and their contents; run it after upgradingtailwindcssorfumadocs-ui, andsrc/lib/docs/test/scopedCss.test.tsfails until you do. Tailwind's colour palette is off, since its names (--color-yellow-800,--color-white) are site tokens: use thefd-*colours, whichdocs.cssmaps to the site tokens, or a token by name (bg-(--color-sage)). The site's reset (_reset.scssand the*block inmain.scss) sits in theresetcascade layer, below Tailwind's layers. Unlayered site rules beat every Tailwind utility, so a site component inside the docs layout, such asIcon, keeps the sizes its SCSS module gives it unless an unlayered rule indocs.csssets them. - Colors and fonts: components use
var(--color-*)andvar(--font-*), and do not use$color-*or$font-*directly. The custom properties are emitted once insrc/styles/_root.scssfrom the SCSS palette in_variables.scss, so add new colors in both places. CSS vars let sections re-theme parts of the UI by overriding them locally (for example, the header changes theme depending on what is underneath it). SCSS variables are for what CSS vars cannot do: breakpoints, sizes, andrem()math. - Fonts: Outfit (300–800) and DM Mono (300–500), self-hosted via
@fontsourceand imported insrc/app/layout.tsx. - Icons: put the SVG in
src/assets/svg/, register it in theiconsmap insrc/components/atoms/Icon/Icon.tsx, and use it as<Icon name="arrow" />. SVGR compiles SVGs to React components (Turbopack rule innext.config.ts), so usestroke="currentColor"for icons to inherit text color. Static image imports are disabled (images.disableStaticImages), so reference bitmaps frompublic/by URL. - Components: atomic design,
src/components/atoms|molecules|organisms/Name/Name.tsx+Name.module.scss. - Buttons: use the
Buttonatom (src/components/atoms/Button) for every button, and add new variants there. When a button has an icon, the icon renders in its own wrapper segment 1px next to the label (icon itself 20×20). Passicon="name", and give icon-only buttons anaria-label. Hover plays a one-shot swap (the arrow flies out in its own direction, a copy rides in, and the label words roll up with a stagger) driven by the.swappingclass from JS. Timings live only inButton.tsx(SWAP_MS,WORD_STAGGER_MS,HOVER_INTENT_MS) and reach the SCSS via--swap-durationand--word-stagger. To make a whole card trigger its button's hover, putdata-button-zoneon the card, and the button listens there. Hover styles are gated behind@media (hover: hover)so touch screens do not get stuck hover states. - Animations use one system:
- Reveals (
src/styles/_reveal.scss+useRevealhook): attachuseReveal()once per section (it returns the section ref), and mark elements withdata-reveal(rise, fade and subtle scale),data-reveal="text"(no scale, for all text),data-reveal-group(card-style unit: container + inner cascade) ordata-reveal-group="trigger"(shared trigger, container static). Stagger viastyle={revealIndex(n)}, with the global pace in$reveal-stagger. The entrance is a CSS animation that starts when the HTML is styled, so content above the fold paints before hydration and shows without JavaScript. The hook parks an element once it is fully off screen (data-reveal-parked: the hidden pose with no animation) and unparks it when it enters the viewport's middle band, which replays the entrance. Parking is an attribute, because React rewritesclassNamewholesale on re-render and would wipe a class. - Text fill on scroll:
SectionHeading(label + h2, one continuous progression, per-section colors via--section-label-colorand--section-heading-color) or theTextFillatom for any other text (--text-fill-color). Both are driven byuseFillProgress, which lerps the displayed progress toward the scroll target so the fill trails the scroll smoothly. The scrub window lives inutils/scroll.ts#travelProgress. - Parallax and scroll work:
useScrollFrame(callback)(rAF-throttled scroll and resize, disabled by passingnull), progress formulas inutils/scroll.ts(centeredProgress,travelProgress,enterProgress),usePrefersReducedMotion()for gating, anduseInView(ref)for visibility flags. The header hides on scroll down and returns on scroll up (direction tracking inHeader.tsx, same scroll frame as its theme probe).
- Reveals (
- Safe areas: the viewport is
viewport-fit: cover. The page paints under the notch and home-indicator bands, and the fixed pieces (header, footer, Studio, drawers) pad byenv(safe-area-inset-*)themselves.