Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat(events): keep public/event.json between events as an explicit no-event state

nirholasfbed72b25555
diff --git a/docs/event-souvenirs.md b/docs/event-souvenirs.md
index f1a3511d3..c36e1d1f8 100644
--- a/docs/event-souvenirs.md
+++ b/docs/event-souvenirs.md
@@ -43,9 +43,11 @@ Everything lives in one file: `public/event.json`, the
same config that drives the countdown pill, the agenda drawer, and the fireworks
finale.
-**That file is absent between events, which is the platform's resting state.**
-No event is scheduled right now, so nothing is being granted. Running one starts
-by writing the file, souvenir block included:
+**Between events that file carries an explicit no-event state (an all-null
+window), which is the platform's resting state.** The file itself always exists
+so `/event.json` answers 200 in every visitor console. No event is scheduled
+right now, so nothing is being granted. Running one starts by writing a real
+config into the file, souvenir block included:
```json
{
@@ -80,9 +82,10 @@ Omit the `souvenir` block entirely to run an event with no drop.
npx vitest run tests/event-souvenir.test.js
```
The suite's last block reads the real `public/event.json` and fails if the
- shipped config would grant nothing. It skips itself when there is no file, so
- a green run between events proves the drop logic, not your window: write the
- config first, then run it and read the count.
+ shipped config would grant nothing. It skips itself while the file carries
+ the no-event resting state, so a green run between events proves the drop
+ logic, not your window: write the config first, then run it and read the
+ count.
4. **Deploy.** The game server fetches the config over HTTP and re-reads it
every two minutes, so moving a window does not need a game-server redeploy.
`EVENT_CONFIG_TTL_MS` tightens that interval while you are setting up.
diff --git a/docs/play-live-events.md b/docs/play-live-events.md
index dad80bb7b..e41c809aa 100644
--- a/docs/play-live-events.md
+++ b/docs/play-live-events.md
@@ -7,14 +7,17 @@ when each segment starts, and a synchronized fireworks show everyone watches
together.
Everything below is driven by one file, `public/event.json`.
-Create it, redeploy, and the event exists. Delete it and the world goes back to
-normal with no code change and no dead pixels.
-
-**The repo ships without that file, and that is the resting state.** No event is
-scheduled right now, so `/event.json` answers 404, every surface below mounts
-nothing, and the world runs as a plain world. Scheduling an event means writing
-the file; ending one means deleting it again. Nothing in this document is live
-until that file exists.
+Schedule a window in it, redeploy, and the event exists. Reset it and the world
+goes back to normal with no code change and no dead pixels.
+
+**Between events the file carries an explicit no-event state, and that is the
+resting state.** The file always exists (four /play readers fetch `/event.json`
+per load, and its absence would put a 404 in every visitor's console), but its
+window is explicitly null, so every surface below mounts nothing and the world
+runs as a plain world. Scheduling an event means writing a real window into the
+file (`npm run event:schedule -- --start <ISO> --duration <minutes> --apply`);
+ending one means resetting it (`npm run event:schedule -- --clear --apply`).
+Nothing in this document is live until a real window is scheduled.
- **Surface:** `/play`, in the `$THREE` home town only (`isHomeTown()`).
- **Modules:** [`src/game/meetup-event.js`](../src/game/meetup-event.js) (the view),
@@ -118,9 +121,9 @@ shifts it to a specific instant instead. This runs through
`applyPreviewOverride()`, which every surface that reads the event shares, so a
preview never drifts from the real thing.
-It shifts a configured event; it does not invent one. With no `public/event.json`
-present, `?meetup=now` has nothing to move and the world loads as usual, so write
-the file first.
+It shifts a configured event; it does not invent one. While `public/event.json`
+carries the no-event resting state, `?meetup=now` has nothing to move and the
+world loads as usual, so schedule a window first.
```
http://localhost:3000/play?coin=FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump&name=three.ws&symbol=three&meetup=now
@@ -129,7 +132,8 @@ http://localhost:3000/play?coin=FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump&nam
## Verifying before an event
The audit drives the real layer through a real browser, so it needs a
-`public/event.json` in place before you run it (see the note under Previewing).
+real window in `public/event.json` before you run it (see the note under
+Previewing).
```bash
npm run dev # terminal 1: vite on :3000
diff --git a/public/event.json b/public/event.json
new file mode 100644
index 000000000..256a9277b
--- /dev/null
+++ b/public/event.json
@@ -0,0 +1,9 @@
+{
+ "id": null,
+ "name": null,
+ "tagline": null,
+ "startsAt": null,
+ "endsAt": null,
+ "link": null,
+ "note": "No event is scheduled. This file stays in place between events so /event.json answers 200 with an explicit no-event state instead of putting a 404 in every visitor console. Schedule the next event with: npm run event:schedule -- --start <ISO> --duration <minutes> --apply"
+}
diff --git a/scripts/check-event-window.mjs b/scripts/check-event-window.mjs
index 631118cad..7c39246fc 100644
--- a/scripts/check-event-window.mjs
+++ b/scripts/check-event-window.mjs
@@ -27,9 +27,13 @@
// the world that link points at and grants nothing without one.
// 7. Agenda beats are ordered, non-negative, and land inside the window.
//
-// There is no event to run? Delete public/event.json. Every surface handles an
-// absent config as a supported state and shows nothing, which is exactly right
-// between events. This check only fails on a config that is present and broken.
+// There is no event to run? Reset the file to its explicit no-event state
+// (`npm run event:schedule -- --clear --apply`). Every surface reads that as
+// "no event" and shows nothing, which is exactly right between events, and
+// /event.json keeps answering 200 so no visitor console carries a 404 and the
+// game server's minutely config poll stays quiet. This check fails on a config
+// that is present and broken, and on a missing file, which would resurrect
+// those 404s.
//
// Run: node scripts/check-event-window.mjs (wired as `npm run check:event`)
// node scripts/check-event-window.mjs --at 2026-08-09T15:30:00Z
@@ -46,6 +50,33 @@ const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
export const CONFIG_PATH = path.join(root, 'public/event.json');
const MAX_DURATION_MS = 24 * 3600 * 1000;
+// The canonical between-events document. Every reader parses `startsAt: null`
+// as "no event" and mounts nothing, while the file's presence keeps /event.json
+// answering 200 for the four /play readers and the game server's config poll.
+// `npm run event:schedule -- --clear --apply` writes exactly this.
+export const NO_EVENT_DOC = {
+ id: null,
+ name: null,
+ tagline: null,
+ startsAt: null,
+ endsAt: null,
+ link: null,
+ note: 'No event is scheduled. This file stays in place between events so /event.json answers 200 with an explicit no-event state instead of putting a 404 in every visitor console. Schedule the next event with: npm run event:schedule -- --start <ISO> --duration <minutes> --apply',
+};
+
+/**
+ * True only for the explicit no-event document: `startsAt` literally null and
+ * no event-bearing field carrying anything. A config that nulls the window but
+ * keeps a name, link, souvenir or agenda is a broken event, not a resting
+ * state, and must keep failing validation loudly.
+ */
+export function isNoEventSentinel(doc) {
+ if (!doc || typeof doc !== 'object' || Array.isArray(doc)) return false;
+ return doc.startsAt === null && doc.endsAt == null && doc.id == null
+ && doc.name == null && doc.tagline == null && doc.link == null
+ && doc.souvenir == null && doc.agenda == null;
+}
+
const ZONES = [
['Pacific', 'America/Los_Angeles'],
['Eastern', 'America/New_York'],
@@ -109,7 +140,7 @@ export function validateEventConfig(doc, now = Date.now()) {
failures.push(
`the event window ENDED ${agoH}h ago (${isoOf(win.endsAt)} UTC), so the countdown, agenda, ` +
'fireworks, souvenir grant and event leaderboard are all silently dormant. ' +
- 'Reschedule with `npm run event:schedule -- --start <ISO> --duration <mins> --apply`, or delete public/event.json if the event is done.',
+ 'Reschedule with `npm run event:schedule -- --start <ISO> --duration <mins> --apply`, or reset to the no-event state with `npm run event:schedule -- --clear --apply` if the event is done.',
);
}
@@ -187,11 +218,14 @@ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.me
process.exit(2);
}
- // No config at all is a supported state: between events the platform owes the
- // visitor zero pixels, and every reader already treats absent as "no event".
+ // The file must exist even between events: readers handle absence, but a
+ // missing file puts a 404 in every /play visitor's console (four readers
+ // fetch it per load) and an unreadable-config warn in the game server's
+ // minutely poll. The resting state is the explicit no-event document.
if (!existsSync(CONFIG_PATH)) {
- console.log('[check-event] OK: no public/event.json, so no event is configured (a supported state)');
- process.exit(0);
+ console.error('[check-event] public/event.json is MISSING. Between events it must carry the explicit no-event state, not be absent.');
+ console.error('[check-event] Restore it: npm run event:schedule -- --clear --apply');
+ process.exit(1);
}
let doc;
@@ -199,10 +233,15 @@ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.me
doc = JSON.parse(readFileSync(CONFIG_PATH, 'utf8'));
} catch (err) {
console.error(`[check-event] public/event.json is not valid JSON: ${err?.message || err}`);
- console.error('[check-event] Every event surface would mount nothing. Fix the syntax or delete the file.');
+ console.error('[check-event] Every event surface would mount nothing. Fix the syntax, or reset with `npm run event:schedule -- --clear --apply`.');
process.exit(1);
}
+ if (isNoEventSentinel(doc)) {
+ console.log('[check-event] OK: public/event.json carries the explicit no-event state, so no event is configured (a supported state)');
+ process.exit(0);
+ }
+
const { failures, notes } = validateEventConfig(doc, now);
for (const n of notes) console.log(`[check-event] ${n}`);
diff --git a/scripts/schedule-event.mjs b/scripts/schedule-event.mjs
index af6b786d3..2f9fd02dc 100644
--- a/scripts/schedule-event.mjs
+++ b/scripts/schedule-event.mjs
@@ -32,6 +32,11 @@
// live states can be walked in a browser. Prints the revert command,
// because a rehearsal left behind is the first bug listed above.
//
+// npm run event:schedule -- --clear --apply
+// Reset the file to the explicit no-event state (the between-events
+// resting document). The file is never deleted: absence puts a 404 in
+// every /play visitor's console and a warn in the game server's poll.
+//
// Also: --name "..." --tagline "..." --duration <minutes> --at <ISO>
// (--at judges the result from that instant instead of now, for proving a
// future window is correct today.)
@@ -39,7 +44,9 @@
// Dry run is the default. Nothing is written without --apply.
import { readFileSync, writeFileSync } from 'node:fs';
-import { validateEventConfig, CONFIG_PATH, isoOf, zoneLines } from './check-event-window.mjs';
+import {
+ validateEventConfig, isNoEventSentinel, NO_EVENT_DOC, CONFIG_PATH, isoOf, zoneLines,
+} from './check-event-window.mjs';
const argv = process.argv.slice(2);
const flag = (name) => {
@@ -49,6 +56,7 @@ const flag = (name) => {
const has = (name) => argv.includes(`--${name}`);
const apply = has('apply');
+const clear = has('clear');
const rehearse = flag('rehearse');
const startArg = flag('start');
const durationArg = flag('duration');
@@ -62,15 +70,27 @@ if (!Number.isFinite(judgeAt)) {
process.exit(2);
}
+// --clear needs no readable config: it writes the resting document outright.
+if (clear) {
+ if (!apply) {
+ console.log('[event-schedule] DRY RUN: would reset public/event.json to the explicit no-event state.');
+ console.log('[event-schedule] Re-run with --apply to write it.');
+ process.exit(0);
+ }
+ writeFileSync(CONFIG_PATH, JSON.stringify(NO_EVENT_DOC, null, '\t') + '\n', 'utf8');
+ console.log('[event-schedule] WROTE public/event.json: the explicit no-event state.');
+ console.log('[event-schedule] Every surface now mounts nothing, and /event.json keeps answering 200.');
+ process.exit(0);
+}
+
let doc;
try {
doc = JSON.parse(readFileSync(CONFIG_PATH, 'utf8'));
} catch (err) {
console.error(`[event-schedule] cannot read public/event.json: ${err?.message || err}`);
- console.error('[event-schedule] Between events the file is deleted on purpose, so HEAD may not carry one.');
- console.error('[event-schedule] Restore the last shipped config, then schedule on top of it:');
- console.error('[event-schedule] git show "$(git rev-list -1 HEAD -- public/event.json)^:public/event.json" > public/event.json');
- console.error('[event-schedule] Or write a fresh one from the template in docs/play-live-events.md.');
+ console.error('[event-schedule] The file must exist even between events (its absence 404s in every /play console).');
+ console.error('[event-schedule] Restore the resting state, then schedule on top of it:');
+ console.error('[event-schedule] npm run event:schedule -- --clear --apply');
process.exit(1);
}
@@ -118,6 +138,13 @@ if (startsAt !== null) {
if (nameArg) doc.name = nameArg;
if (taglineArg) doc.tagline = taglineArg;
+// Previewing the resting document is not a failure: there is simply no event.
+if (startsAt === null && !nameArg && !taglineArg && isNoEventSentinel(doc)) {
+ console.log('[event-schedule] no event is scheduled (public/event.json carries the explicit no-event state).');
+ console.log('[event-schedule] Schedule one with --start <ISO> --duration <minutes> --apply, or --rehearse 10 --apply for a walkthrough.');
+ process.exit(0);
+}
+
// Validate the document as it would actually ship, with the deploy's own rules.
const { failures, notes, window: win, state } = validateEventConfig(doc, judgeAt);
@@ -166,9 +193,11 @@ if (!apply) {
const raw = readFileSync(CONFIG_PATH, 'utf8');
const setString = (text, key, value) => {
// The value is JSON-encoded, so quotes and backslashes in a name are safe.
- const pattern = new RegExp(`("${key}"\\s*:\\s*)"(?:[^"\\\\]|\\\\.)*"`);
+ // `null` is matched too: the no-event resting document carries every event
+ // field as null, and scheduling on top of it fills them in place.
+ const pattern = new RegExp(`("${key}"\\s*:\\s*)(?:"(?:[^"\\\\]|\\\\.)*"|null)`);
if (!pattern.test(text)) {
- console.error(`[event-schedule] could not find a "${key}" string field to update in public/event.json`);
+ console.error(`[event-schedule] could not find a "${key}" field to update in public/event.json`);
process.exit(1);
}
return text.replace(pattern, (_m, head) => head + JSON.stringify(value));
diff --git a/tests/check-event-window.test.js b/tests/check-event-window.test.js
index 0ee50f39f..11055bf2a 100644
--- a/tests/check-event-window.test.js
+++ b/tests/check-event-window.test.js
@@ -1,6 +1,8 @@
import { describe, it, expect } from 'vitest';
import { existsSync, readFileSync } from 'node:fs';
-import { validateEventConfig, CONFIG_PATH, isoOf, zoneLines } from '../scripts/check-event-window.mjs';
+import {
+ validateEventConfig, isNoEventSentinel, NO_EVENT_DOC, CONFIG_PATH, isoOf, zoneLines,
+} from '../scripts/check-event-window.mjs';
// The shape of public/event.json, minus the fields the validator ignores. Kept
// close to the real file so a rule that only passes on a toy config fails here.
@@ -122,15 +124,41 @@ describe('validateEventConfig', () => {
});
});
+// The between-events resting state: the file exists (so /event.json answers
+// 200 in every visitor console instead of 404ing four times per /play load)
+// and carries an explicitly null window every reader parses as "no event".
+describe('the no-event resting state', () => {
+ it('recognises the canonical resting document', () => {
+ expect(isNoEventSentinel(NO_EVENT_DOC)).toBe(true);
+ });
+
+ it('is what every reader parses as "no event"', () => {
+ expect(validateEventConfig(NO_EVENT_DOC, BEFORE).window).toBeNull();
+ });
+
+ // A config that nulls the window but keeps event-bearing fields is a broken
+ // event, not a resting state, and must keep failing validation loudly.
+ it('refuses a null window that still carries event fields', () => {
+ expect(isNoEventSentinel({ ...NO_EVENT_DOC, name: '$THREE meetup' })).toBe(false);
+ expect(isNoEventSentinel({ ...NO_EVENT_DOC, link: '/play?coin=x' })).toBe(false);
+ expect(isNoEventSentinel({ ...NO_EVENT_DOC, souvenir: { cosmeticId: 'laurel-meetup' } })).toBe(false);
+ expect(isNoEventSentinel(null)).toBe(false);
+ expect(isNoEventSentinel({})).toBe(false);
+ });
+});
+
// The config that ships is the one that matters; a green suite over fixtures
// while the real file is broken would be the same silent failure in a new place.
-// Between events there is no file at all (the documented "no event scheduled"
-// state every surface handles), so these run only when one is actually shipping.
+// Between events the file carries the no-event resting document (see above), so
+// these run only when an event is actually shipping.
// Read inside the tests rather than in the suite body: vitest still collects a
-// skipped suite's body, so an eager read would throw with no event scheduled.
+// skipped suite's body, so an eager read would throw on an unreadable file.
const shippedEvent = () => JSON.parse(readFileSync(CONFIG_PATH, 'utf8'));
+const shippedIsResting = () => {
+ try { return isNoEventSentinel(shippedEvent()); } catch { return false; }
+};
-describe.skipIf(!existsSync(CONFIG_PATH))('the configured event that ships', () => {
+describe.skipIf(!existsSync(CONFIG_PATH) || shippedIsResting())('the configured event that ships', () => {
it('is coherent when judged at its own start', () => {
const doc = shippedEvent();
const { failures } = validateEventConfig(doc, Date.parse(doc.startsAt));
diff --git a/tests/event-souvenir.test.js b/tests/event-souvenir.test.js
index b0b085d0b..df188c94c 100644
--- a/tests/event-souvenir.test.js
+++ b/tests/event-souvenir.test.js
@@ -32,6 +32,7 @@ import {
import { boutiqueListings, boutiquePrice } from '../multiplayer/src/shop.js';
import { existsSync, readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
+import { isNoEventSentinel } from '../scripts/check-event-window.mjs';
const SOUVENIR_ID = 'laurel-meetup';
const EVENT_COIN = 'FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump';
@@ -194,15 +195,20 @@ describe('the souvenir stays out of the shop economy', () => {
const EVENT_CONFIG = fileURLToPath(new URL('../public/event.json', import.meta.url));
-// Between events the file is absent on purpose (every surface reads that as "no
-// event" and mounts nothing), so there is no shipped config to hold to account.
-// The server reads this exact file over HTTP at runtime. A typo in it is a
-// silent no-drop on the night of the event, which is the worst possible time to
-// find out. Read inside the tests, not in the suite body: a skipped suite still
-// has its body collected, so an eager read would throw with no event scheduled.
+// Between events the file carries the explicit no-event resting document (an
+// all-null window every surface reads as "no event"; it exists so /event.json
+// answers 200 instead of 404ing in visitor consoles), so there is no shipped
+// config to hold to account. The server reads this exact file over HTTP at
+// runtime. A typo in it is a silent no-drop on the night of the event, which is
+// the worst possible time to find out. Read inside the tests, not in the suite
+// body: a skipped suite still has its body collected, so an eager read would
+// throw on an unreadable file.
const shippedEvent = () => JSON.parse(readFileSync(EVENT_CONFIG, 'utf8'));
+const restingState = () => {
+ try { return isNoEventSentinel(shippedEvent()); } catch { return false; }
+};
-describe.skipIf(!existsSync(EVENT_CONFIG))('the shipped event config', () => {
+describe.skipIf(!existsSync(EVENT_CONFIG) || restingState())('the shipped event config', () => {
it('declares a souvenir the server will actually grant', () => {
const drop = parseEventDrop(shippedEvent());
expect(drop).not.toBeNull();