From bd8be4d10df9d8fd4191bc7704abd048d4c36e94 Mon Sep 17 00:00:00 2001 From: Owen Rees Date: Fri, 6 Nov 2026 13:56:20 +0100 Subject: [PATCH] Privacy and terms pages with config-driven branding (#91) * comment out begin with basics until lessons are on the way * route to footer link dead views * proposed >7 piece engame processing * basic privacy and terms pages with default text * add branding to config and reference across the site * disclose guest puzzle limit in privacy policy (#87) --- assets/css/app.css | 1 + assets/css/pages/_legal.css | 72 +++++++++ config/config.exs | 9 ++ docs/adr/0011-engine-corridor-endgames.md | 55 +++++++ lib/chesstrainer/accounts/user_notifier.ex | 3 +- lib/chesstrainer/branding.ex | 39 +++++ lib/chesstrainer_web.ex | 1 + lib/chesstrainer_web/components/layouts.ex | 14 +- .../components/layouts/root.html.heex | 10 +- .../controllers/page_controller.ex | 26 +++- .../controllers/page_html/home.html.heex | 4 +- .../controllers/page_html/privacy.html.heex | 137 ++++++++++++++++++ .../page_html/terms_conditions.html.heex | 118 +++++++++++++++ lib/chesstrainer_web/router.ex | 2 + .../controllers/page_controller_test.exs | 80 +++++++++- 15 files changed, 548 insertions(+), 23 deletions(-) create mode 100644 assets/css/pages/_legal.css create mode 100644 docs/adr/0011-engine-corridor-endgames.md create mode 100644 lib/chesstrainer/branding.ex create mode 100644 lib/chesstrainer_web/controllers/page_html/privacy.html.heex create mode 100644 lib/chesstrainer_web/controllers/page_html/terms_conditions.html.heex diff --git a/assets/css/app.css b/assets/css/app.css index a939198..38997b9 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -22,6 +22,7 @@ @import "./components/_learning-strip.css"; @import "./components/_board.css"; @import "./components/_promotion.css"; +@import "./pages/_legal.css"; @source "../css"; @source "../js"; diff --git a/assets/css/pages/_legal.css b/assets/css/pages/_legal.css new file mode 100644 index 0000000..323e432 --- /dev/null +++ b/assets/css/pages/_legal.css @@ -0,0 +1,72 @@ +.legal { + width: min(760px, calc(100% - 48px)); + margin: 0 auto; + padding: 84px 0 120px; +} + +.legal h1 { + max-width: none; + font-size: clamp(42px, 5vw, 62px); + line-height: 1.02; +} + +.legal-meta { + margin-top: 14px; + color: var(--color-muted); + font-size: 13px; +} + +.legal h2 { + margin: 42px 0 12px; + font-size: 26px; + line-height: 1.15; +} + +.legal p, +.legal li { + color: var(--color-muted); + font-size: 15px; + line-height: 1.75; +} + +.legal p + p { + margin-top: 12px; +} + +.legal ul { + display: grid; + gap: 8px; + margin: 12px 0 0 20px; + list-style: disc; +} + +.legal strong { + color: var(--color-body); + font-weight: 600; +} + +.legal a { + color: var(--color-coral-text); + text-decoration: underline; + text-underline-offset: 2px; +} + +.legal a:hover { + opacity: 0.75; +} + +@media (max-width: 650px) { + .legal { + width: calc(100% - 36px); + padding: 56px 0 84px; + } + + .legal h1 { + font-size: clamp(34px, 11vw, 44px); + } + + .legal h2 { + margin-top: 34px; + font-size: 23px; + } +} diff --git a/config/config.exs b/config/config.exs index 435185d..e896047 100644 --- a/config/config.exs +++ b/config/config.exs @@ -7,6 +7,15 @@ # General application configuration import Config +# Public-facing branding. Change these values to rename the site without +# touching templates. The OTP app (`:chesstrainer`) and module namespaces are +# identity, not branding, and stay as they are. +config :chesstrainer, :branding, + name: "Lucid Chess", + wordmark: "LUCID", + tagline: "Endgame Trainer", + support_email: "support@lucidchess.app" + config :chesstrainer, :scopes, user: [ default: true, diff --git a/docs/adr/0011-engine-corridor-endgames.md b/docs/adr/0011-engine-corridor-endgames.md new file mode 100644 index 0000000..ba750cb --- /dev/null +++ b/docs/adr/0011-engine-corridor-endgames.md @@ -0,0 +1,55 @@ +# Eight-or-more-piece endgames are trained from engine-sourced corridors that hand off to the tablebase at seven + +_Status: proposed. Extends ADR-0005: the ≤7-piece source split stands; this adds a source for 8+._ + +Syzygy stops at seven pieces and there is no tablebase for eight or more. To +train such endgames without pretending to a completeness they lack, each 8+ +endgame is backed by a **corridor**: one or two winning lines, generated offline +with a chess engine (Stockfish), that stay clearly winning at every step. The +corridor is stored as solved positions keyed by position key and served by a new +tablebase backend, so the play loop and grading are unchanged. + +The corridor ends at the first capture that brings the board to seven pieces or +fewer. From that position the existing router answers from Syzygy (≤5, local) or +Lichess (6–7), so the tail of every puzzle is tablebase-optimal. Generation +verifies the handoff: it probes the ≤7 position and asserts it is still a win for +the winning side. A promotion does not end the corridor, because it does not +reduce the piece count; only a capture does. + +A second line is stored only when both lines are clearly winning — the engine's +evaluation stays above the winning threshold throughout. A line that dips is +discarded rather than shipped as a dubious alternative. + +## Grading + +Inside the corridor grading is binary: a move on a stored line passes, a move +off the lines fails. The stored move list is deliberately incomplete, so it +cannot support the "any winning move passes" rule the tablebase enables; the +user must find the technique the corridor encodes. Once the position reaches +seven pieces, grading returns to the existing optimal/winning/losing model. + +## Why not the alternatives + +- **Engine at runtime.** Removes the offline step but adds per-move latency, a + rate limit if it is a remote service, and non-determinism in what counts as + "winning". The corridor is deterministic and free at play time. +- **Hand-authored book.** The same shape without an engine to generate it: + fragile, narrow, and prone to grading a move as losing only because nobody + wrote it down. +- **Solving the whole 8+ region.** Infeasible. The corridor trades completeness + for a short, verified path to a position the tablebase can finish. + +## Consequences + +- Endgames gain an `oracle` (`:tablebase` or `:corridor`). The changeset admits + 8+ FENs only for corridor endgames. +- A corridor-position store (keyed by position key) and a tree backend join the + existing Fathom/Lichess backends. Eight-plus positions without a corridor are + still rejected. +- Generation depends on a Stockfish binary at build/curation time, not at + runtime. +- The corridor is engine-best, not proven-optimal. Honest wording ("engine-best + defence") is required in player-facing copy, and GLOSSARY's *optimal move* and + *winning move* need a corridor-aware distinction. +- An off-corridor legal move fails the attempt; this is a deliberate departure + from tablebase grading and must be reflected in the play surface. diff --git a/lib/chesstrainer/accounts/user_notifier.ex b/lib/chesstrainer/accounts/user_notifier.ex index 2220cb8..a1c530e 100644 --- a/lib/chesstrainer/accounts/user_notifier.ex +++ b/lib/chesstrainer/accounts/user_notifier.ex @@ -1,6 +1,7 @@ defmodule Chesstrainer.Accounts.UserNotifier do import Swoosh.Email + alias Chesstrainer.Branding alias Chesstrainer.Mailer # Delivers the email using the application mailer. @@ -8,7 +9,7 @@ defmodule Chesstrainer.Accounts.UserNotifier do email = new() |> to(recipient) - |> from({"Chesstrainer", "contact@example.com"}) + |> from({Branding.name(), Branding.support_email()}) |> subject(subject) |> text_body(body) diff --git a/lib/chesstrainer/branding.ex b/lib/chesstrainer/branding.ex new file mode 100644 index 0000000..3a7e4bd --- /dev/null +++ b/lib/chesstrainer/branding.ex @@ -0,0 +1,39 @@ +defmodule Chesstrainer.Branding do + @moduledoc """ + Public-facing branding, read from `config :chesstrainer, :branding`. + + Keeps display names out of templates and controllers so the site can be + renamed in one place. Values are read at runtime, so a deploy can override + them without recompiling. + """ + + @defaults [ + name: "Lucid Chess", + wordmark: "LUCID", + tagline: "Endgame Trainer", + support_email: "support@lucidchess.app" + ] + + @doc "The display name, e.g. `\"Lucid Chess\"`." + def name, do: get(:name) + + @doc "The short wordmark used in the navbar and footer." + def wordmark, do: get(:wordmark) + + @doc "The tagline appended to the home title, e.g. `\"Endgame Trainer\"`." + def tagline, do: get(:tagline) + + @doc "The address shown in legal pages and used as the mailer `from`." + def support_email, do: get(:support_email) + + @doc "The home-page title, e.g. `\"Lucid Chess — Endgame Trainer\"`." + def home_title, do: "#{name()} — #{tagline()}" + + @doc "Builds a page title, e.g. `title(\"Privacy Policy\")`." + def title(page), do: "#{page} — #{name()}" + + defp get(key) do + config = Application.get_env(:chesstrainer, :branding) || [] + Keyword.get(config, key, Keyword.fetch!(@defaults, key)) + end +end diff --git a/lib/chesstrainer_web.ex b/lib/chesstrainer_web.ex index 520d431..6e4f174 100644 --- a/lib/chesstrainer_web.ex +++ b/lib/chesstrainer_web.ex @@ -91,6 +91,7 @@ defmodule ChesstrainerWeb do # Common modules used in templates alias Phoenix.LiveView.JS + alias Chesstrainer.Branding alias ChesstrainerWeb.Layouts # Routes generation with the ~p sigil diff --git a/lib/chesstrainer_web/components/layouts.ex b/lib/chesstrainer_web/components/layouts.ex index 7006dd6..1866a6b 100644 --- a/lib/chesstrainer_web/components/layouts.ex +++ b/lib/chesstrainer_web/components/layouts.ex @@ -70,9 +70,9 @@ defmodule ChesstrainerWeb.Layouts do ~H"""