5.4 KiB
5.4 KiB
AGENTS.md
Guidance for AI agents and contributors working in this repository.
What this is
Unofficial open-source implementation of the board game Outpost (1991, James Hlavaty) for
boardgamers.space (BGS). Two packages: packages/engine (outpost-engine, rules + BGS
wrapper) and packages/viewer (outpost-viewer, Svelte 5 browser UI). See README.md for
the full picture, including the rules set implemented (Expert Rules v1.32) and the known
data deviations (some production deck distributions are inferred, not confirmed).
Conventions
- ESM everywhere:
"type": "module"in every package. TS imports use explicit.jsextensions in the engine (moduleResolution: nodenext) and no extension in the viewer (moduleResolution: bundler) — follow the local pattern of each package. - Node >= 24 (
enginesfield,.nvmrc), pnpm 11 workspaces (pnpm-workspace.yaml). - TypeScript strict, including
noUncheckedIndexedAccess. Code must passpnpm tsc(enginetsc --noEmit, viewersvelte-check) with zero errors. - No comments by default — write self-explanatory code; comment only the non-obvious "why" (e.g. a BGS contract quirk, a rules edge case). No emojis in code or docs.
- Formatting: oxfmt (
.oxfmtrc.json) — tabs for indentation (tabWidth 2), 120-column lines, Svelte formatting enabled. Runpnpm fmtto format,pnpm fmt:checkin CI. Linting: oxlint (.oxlintrc.json) withcurly: all— always braceif/for/whilebodies. Runpnpm lint. - Tests: colocated
*.spec.tsnext to engine sources, run withnode --testagainst compiled output (pnpm --filter outpost-engine testcompiles todist-test/first). Usenode:assert/strict. - Dependencies: pin exact versions; verify a version exists (
npm view <pkg> version) before adding it. Keep the dependency list minimal.
Engine specifics
- In-place state mutation is intentional.
applyMove/dropPlayermutate the passedGameStateand return it, matching BGS/take6 engine semantics (the game-server JSON-serializes the state between calls). Illegal moves must throw before any mutation — validation runs first. Never mutate-then-throw. - The game state must stay JSON-serializable at all times (no functions, no class
instances, no Map/Set) because BGS round-trips it through
JSON.parse(JSON.stringify(...)). - All randomness goes through the seeded PRNG (
src/prng.ts); the seed arrives viainit. Never useMath.randomin the engine — replay determinism depends on it. Randomness is drawn asseedrandom(seed:counter)with the counter stored in the state, so nothing needs to persist PRNG internals. - The wrapper boundary deep-validates untrusted input.
wrapper.movereceives raw network JSON;applyMoverunssanitizeMove(src/sanitize.ts) which rebuilds the move as a fresh literal with only whitelisted fields, strict type checks and bounded arrays — this protects both interpretation and the log (moves are stored verbatim instate.log). - Hidden information:
stripSecrethides the seed (it derives all deck orders), deck values, other players' hand values (v = -1), and produced card values in round log entries.logSliceapplies the same treatment. When writing features, never leak deck contents or opponents' card values into what a client can see. - Replay (
src/replay.ts) rebuilds state from the log without consuming randomness: "round" log entries carry purchase order, market, supply and production draws, and areplayModeflag (src/moves.ts) makes round transitions and affordability checks inert so a stripped log replays into a stripped state. packages/engine/wrapper.tsis the BGS Engine API contract: keep the exported names and signatures in sync with the platform'sapp/types/engine.ts.dist/wrapper.jsmust exist after build (it is the registeredentryPoint).- Production deck data (
src/data.ts) reproduces the published card counts; treat it as rules data, not creative content. See README.md "Data notes / deviations" before changing distributions.
Viewer specifics
- Svelte 5 runes mode only:
$state,$derived,$props,$effect. No legacyexport let, no$:reactive statements. - The viewer must keep working both inside the BGS iframe (postMessage bridge in
src/lib/bgs.svelte.ts) and standalone (dev harness:packages/viewer/index.html+src/dev.ts). Uplink events are emitted on the emitter returned bylaunch()as well as posted towindow.parent, so a local backend can subscribe the same way BGS does. - Keep everything asset-free: cards and tokens are pure CSS. Theme tokens live in
src/lib/theme.css. - The BGS host measures
body.scrollHeight— normal top-down document flow, no vertical centering tricks. wrapper.currentPlayerreturns an array of seats during the simultaneous discard phase; the dev backend (and any future integration) must handle both shapes.
Workflow
pnpm install
pnpm dev # viewer dev server + mock backend harness
pnpm fmt # oxfmt format (tabs, 120 cols)
pnpm lint # oxlint (curly rule)
pnpm tsc # engine tsc + viewer svelte-check
pnpm test # engine tests
pnpm build # engine dist/ + viewer dist/ (iife + css)
pnpm check # fmt:check + lint + tsc + test + build
Run pnpm check before committing. Commit with clear messages; do not create PRs
(this repo has no remote).