Bundle Station Master v0.5.3: games in progress, and a way to end one

Pin moves to v0.5.3, package version to 0.5.3:0.

The health check no longer just probes a port. It fetches the server's own
/api/health and reports what it says — "Multiplayer server is ready — 3
games in progress", with ", 1 waiting to start" appended only when a lobby
exists and "no games in progress" on an idle server. A server that doesn't
answer is reported as STARTING, never failed: the server replays its saved
games before binding its port, so a boot legitimately looks like nothing is
listening, and calling that a failure makes an ordinary restart look like a
crash.

Two new actions, both only-running. Games in Progress is read-only and
lists every game and lobby with players, Day/Stage/phase, who it waits on,
when it started and when it last moved. Manage Game picks one from a
dropdown built live from the server and either exports it or ends it —
ending being the only way a game finishes other than being played out,
since an abandoned game otherwise stays active and is resumed on every
restart forever. Ending always returns the deleted game's save, so nothing
is destroyed without being handed back first.

They are only-running because none of it is readable from disk: a save is a
seed plus a list of moves, so whose-turn-it-is exists only after a replay
through the engine, which lives in the game repo rather than here. The
running server has already done that work and is asked for the answer.
startos/serverApi.ts is the single place that asks.

store.json gained adminSecret (32 chars) beside joinSecret, seeded on
install and backfilled on update for a volume written before the field
existed. It is deliberately NOT the join secret: every player holds that
one, so gating a delete with it would let anyone at the table destroy
anyone else's game. init/generateJoinSecret.ts is renamed generateSecrets.ts
now that it mints both.

Also brought getJoinSecret's result strings under i18n(). They shipped as
plain strings two commits ago, which actions.md is explicit about — every
user-facing string including result titles, messages and thrown errors.
The new actions follow it, so the old one shouldn't be the odd one out.

Verified on phoenix.local, installed as an UPDATE from 0.5.2:0 rather than
a fresh install, which exercised three things at once: the boot log line
("Resuming 1 saved game(s)…"), the engine-version refusal firing for real
on a game recorded under 0.5.2, and the adminSecret backfill (store.json
came out with both secrets, 24 and 32 chars). Then, from inside the
container: the package-generated admin secret authenticating against
/api/games (200) while a wrong one is refused (403), health counts tracking
0 -> lobby 1 -> active 1 through a create/bot/start, and every field the
actions render present and correct on the listing.

NOT verified: the actions' own forms and result rendering. `start-cli
package action run` fails with a client-side deserialization error on every
action on this box — including the already-shipped get-join-secret and
actual-budget's equivalent — so it is a start-cli problem, not this
package's. The data path underneath them is verified above; the SDK
form/result rendering needs the web UI.

A test game (TRESTLE-3221, Alice + a bot) is left running on the box so
there is something for Games in Progress to show.
This commit is contained in:
Jesse
2026-08-21 16:00:05 -04:00
parent ea012f1329
commit c95620d566
20 changed files with 801 additions and 85 deletions
+44 -8
View File
@@ -2,6 +2,7 @@ import { i18n } from './i18n'
import { sdk } from './sdk'
import { uiPort, dataDir } from './utils'
import { storeJson } from './fileModels/store.json'
import { fetchHealth } from './serverApi'
export const main = sdk.setupMain(async ({ effects }) => {
console.info(i18n('Starting Station Master!'))
@@ -9,6 +10,7 @@ export const main = sdk.setupMain(async ({ effects }) => {
// Reactive, field-scoped: rotating the join secret (getJoinSecret.ts) rewrites store.json,
// which re-runs setupMain and restarts the daemon with the new value.
const joinSecret = await storeJson.read((s) => s.joinSecret).const(effects)
const adminSecret = await storeJson.read((s) => s.adminSecret).const(effects)
return sdk.Daemons.of(effects).addDaemon('server', {
subcontainer: sdk.SubContainer.of(
@@ -29,21 +31,55 @@ export const main = sdk.setupMain(async ({ effects }) => {
// 0.0.0.0, ./dist relative to the Dockerfile's WORKDIR) — nothing here needs to differ
// from them, so only what actually must be supplied is set explicitly.
DATA_DIR: dataDir,
// generateJoinSecret.ts seeds this before main.ts ever runs, so it is never actually
// generateSecrets.ts seeds this before main.ts ever runs, so it is never actually
// empty — the fallback only avoids threading `string | undefined` through `env`, which
// wants `Record<string, string>`.
JOIN_SECRET: joinSecret ?? '',
// Unset leaves the server's /api/games routes switched off entirely rather than open, so
// an empty string here fails closed — see src/server/http.ts in the game repo.
ADMIN_SECRET: adminSecret ?? '',
},
},
// Health check, run on each polling interval. `checkPortListening` reports ready once the
// daemon binds `uiPort`; the 'ui' interface (interfaces.ts) exposes the same port.
/**
* Reports what the server is actually doing, not merely that it is up.
*
* `/api/health` carries the game counts, so the check that proves the server is answering can
* say how many tables are in play in the same breath — which is the thing an administrator
* glancing at the service page wants to know.
*
* A refusal is reported as `starting`, never `failure`: the server replays its saved games
* before it binds the port, so a boot legitimately looks like nothing is listening. Calling
* that a failure would make an ordinary restart look like a crash.
*/
ready: {
display: i18n('Multiplayer Server'),
fn: () =>
sdk.healthCheck.checkPortListening(effects, uiPort, {
successMessage: i18n('The multiplayer server is ready'),
errorMessage: i18n('The multiplayer server is not ready'),
}),
fn: async () => {
const counts = await fetchHealth()
if (counts === null) {
return {
result: 'starting',
message: i18n('The multiplayer server is not ready'),
}
}
const games =
counts.active === 0
? i18n('no games in progress')
: counts.active === 1
? i18n('1 game in progress')
: `${counts.active} ${i18n('games in progress')}`
// Only mentioned when there is one — a permanent "0 waiting to start" is noise on a line
// that is read at a glance.
const waiting =
counts.lobby === 0
? ''
: counts.lobby === 1
? `, ${i18n('1 waiting to start')}`
: `, ${counts.lobby} ${i18n('waiting to start')}`
return {
result: 'success',
message: `${i18n('Multiplayer server is ready')} — ${games}${waiting}`,
}
},
},
requires: [],
})