History: AI-driven alternate-history simulator

Pax Historia-style sim where the LLM is the world engine.

- React 19 + Vite 6 + Tailwind v4 + shadcn/ui frontend
- Express single-port backend (/api + /sse + built client + SPA fallback)
- SQLite (better-sqlite3) persistence, one row per game
- MapLibre choropleth map (OpenFreeMap dark + ISO_A3 regions)
- Defensive turn loop: strip fences, balanced-{} extract, parse, clamp 0-100,
  retry-once nudge, generic 'unclear' fallback; never crashes on bad output
- 5 seed presets (wwii-1939, coldwar-1955, modern-2025, no-wwii-1940, aegis-2400)
- LLM client over native fetch w/ injectable transport (mesh-bot pattern);
  LLM_STUB=1 deterministic transport for tests/e2e
- Unit (vitest, 19) + deterministic Playwright e2e
- Multi-stage node:22-slim Docker + Traefik (history.dev.kkhost.pl:4321)

Co-Authored-By: OpenCode <opencode@users.noreply.github.com>
This commit is contained in:
2026-10-10 21:20:23 +00:00
co-authored by OpenCode
commit e2936e85bb
65 changed files with 14257 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
# syntax=docker/dockerfile:1
# ---------------------------------------------------------------------------
# Build stage: full dependency install (incl. dev toolchain) + production build.
# Produces the Vite client bundle (dist/) and the tsup server bundle (server/dist/).
# ---------------------------------------------------------------------------
FROM node:22-slim AS build
WORKDIR /app
# Install from the lockfile (full install — we need vite/tsup/typescript/tsx to build).
COPY package.json package-lock.json ./
RUN npm ci
# Copy the source tree and build the client and the server.
COPY . .
RUN npm run build
# ---------------------------------------------------------------------------
# Runtime stage: only production deps + the built artifacts. The server bundle
# (tsup) inlines everything except better-sqlite3, so the only runtime native
# module that must be present is better-sqlite3 (a prebuilt is fetched on npm ci).
# ---------------------------------------------------------------------------
FROM node:22-slim
ENV NODE_ENV=production
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --omit=dev
# Built client (serves index.html, assets, and countries.geo.json) …
COPY --from=build /app/dist ./dist
# … the compiled server bundle …
COPY --from=build /app/server/dist ./server/dist
# … and the scenario presets (loaded from disk at runtime; see findRoot()).
COPY --from=build /app/presets ./presets
# The server persists games to ./data/history.db (WAL). Kept on a volume in compose.
RUN mkdir -p ./data
# Single internal port; the client, /api, and /sse all share it.
ENV PORT=4321
EXPOSE 4321
CMD ["node", "server/dist/index.js"]