1
0
This repository has been archived on 2026-08-25. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
tera/server/src/cache.ts
T
Karti Tripathi d464459838 Spaces: the inside of the world, and a sun that is actually where it should be
Ten agents wrote this in parallel against CONTRACT.md, which exists because the
five design agents before them collided on fifteen blocking points — four files
specified twice with incompatible contents, three separate backends for one box,
and `Environment` exported twice meaning different things.

What landed: a Stage owning only the renderer and the loop, with the city and an
office as two scenes over it. They cannot share one — San Francisco is ~94 m per
scene unit with 3.6x vertical exaggeration and an office is 1 unit = 1 m — and
the city is paused rather than disposed on the way in, because rebuilding its
336,864-point heightfield costs about a second on the way back out.

Offices are data. `src/offices/lumbridge-hq.ts` is fifteen rooms and seventy-six
seats, and it is the file a self-hoster copies. Walls are a segment list with
1-D openings, so doors and windows are holes punched in a wall rather than
placed objects, and the pass that splits a wall around its openings hands the
walk-mode collider its segments for free.

The sun is real. `solar.ts` is a NOAA/Meeus implementation with no imports at
all — not even three.js — so time of day keeps working on a laptop in a field.
Verified against known values: 75.45 degrees at the June solstice in SF, 28.79
at December, sunset at 03:15Z. The first screenshot after wiring it was a black
rectangle, which turned out to be correct: it was midnight in San Francisco.

Presence binds to a seat id and never to a coordinate. The pack knows where
`eng-04` is; who is sitting in it is private data behind an API. Same shape as
the marker rule, one level in.

Two corrections to ARCHITECTURE.md are in here. Containment does not discharge
ODbL — publishing OSM-derived coordinates is Public Use of a Derivative Database
wherever the rows live, so the rule is about the geocoder (US Census, public
domain) and not the storage. And a person at a desk is not a Marker; markers are
geographic.

One contract gap surfaced only in a screenshot: two agents read `height` on a
viewpoint differently, so the establishing shot aimed at empty air fourteen
metres above the roof. It now means what the same field means for a city.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-05 00:11:01 -07:00

37 lines
1.5 KiB
TypeScript

/**
* `Cache-Control`, fail-closed.
*
* A global `onRequest` hook stamps `private, no-store` on every reply before any
* route runs, and a route that wants a CDN or a browser to keep a copy has to
* say so out loud with `publicCache()`. The order matters: doing this in
* `onSend` "only if the header is missing" would leave error paths, 404s and
* anything thrown before the handler with no policy at all, and the one body
* that must never be cached is the one that came out of a mistake.
*
* CONTRACT.md §5.
*/
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
export function registerCachePolicy(app: FastifyInstance): void {
app.addHook("onRequest", async (_req, reply) => {
reply.header("cache-control", "private, no-store");
});
}
/**
* Opt this reply in to shared caching.
*
* The credential check is not paranoia for its own sake. A route can be
* *usually* public and still be reached with a session attached, and a shared
* cache that stored that response would serve one viewer's body to the next. If
* the request carried anything that could personalise the answer, the fail-closed
* default stands.
*/
export function publicCache(req: FastifyRequest, reply: FastifyReply, seconds: number): void {
if (req.headers.authorization !== undefined || req.headers.cookie !== undefined) return;
const maxAge = Math.max(0, Math.floor(seconds));
reply.header("cache-control", `public, max-age=${maxAge}`);
reply.header("vary", "Origin");
}