Ai slop
Some checks failed
Build and Deploy Nuxt / build (push) Failing after 41s

This commit is contained in:
2026-10-03 14:13:08 +02:00
parent 68b74eb60b
commit 6df7950161
45 changed files with 4594 additions and 125 deletions

70
lean/Dockerfile Normal file
View File

@@ -0,0 +1,70 @@
# Mathew — the Lean editor server
#
# Builds lean4web (https://github.com/leanprover-community/lean4web) from its
# upstream source and runs its production server: one port serves the editor
# client and the Lean sessions, which is what the wiki frames at /lean.
#
# Lean4web runs a real Lean process per session, so upstream asks for a
# dedicated server — this image carries the editor and Mathlib, the machine
# carries the load.
#
# docker build -t mathew-lean ./lean
# docker run -p 8080:8080 mathew-lean # → http://localhost:8080
#
# The build is heavy by nature (Mathlib is fetched and its precompiled
# cache unpacked); expect a long build and an image of several GB.
FROM node:24-bookworm
# lake fetches dependencies over git/curl, drives clang to link, and elan
# (Lean's toolchain manager) installs the toolchains each project pins
RUN apt-get update && apt-get install -y --no-install-recommends \
bash curl git ca-certificates unzip rsync \
build-essential clang pkg-config libssl-dev \
&& rm -rf /var/lib/apt/lists/*
# elan, with no default toolchain — every project pins its own in its
# lean-toolchain file, and elan installs that one when asked
RUN curl -sSfL https://elan.lean-lang.org/elan-init.sh | bash -s -- -y --default-toolchain none
ENV PATH="/root/.elan/bin:${PATH}"
# The lean4web source. Pass a tag or branch to pin a build:
# docker build --build-arg LEAN4WEB_REF=v0.2.2 ./lean
ARG LEAN4WEB_REF=main
RUN git clone --depth 1 --branch "${LEAN4WEB_REF}" \
https://github.com/leanprover-community/lean4web.git /opt/lean4web
WORKDIR /opt/lean4web
RUN npm install
# Build the Lean projects under Projects/ (MathlibDemo pulls Mathlib and
# unpacks its precompiled cache — the slow part of the image) and then the
# editor client, which the server serves alongside its websocket
RUN npm run build:projects
# Mathew's theme layer: the wiki's font, stylesheet, and theme handshake
# join the client's public/ so they ship in the built bundle, and a sed
# wires them into index.html (and renames the tab). The wiki opens the
# frame as ?theme=light|dark and the editor opens matching the page
# around it — lean/theme/mathew.css explains how the skin attaches.
COPY theme/mathew.css theme/theme-init.js ./client/public/
COPY theme/fonts/. ./client/public/fonts/
RUN sed -i \
-e 's#<link rel="stylesheet" href="src/css/index.css" />#<script src="/theme-init.js"></script>\n <link rel="stylesheet" href="src/css/index.css" />\n <link rel="stylesheet" href="/mathew.css" />#' \
-e 's#<title>Lean Web</title>#<title>Lean · Mathew</title>#' \
client/index.html
RUN npm run build:client
# Bubblewrap cannot sandbox inside a container (no nested user namespaces by
# default) — Docker itself is the isolation here, so the server runs Lean
# directly. PORT 8080 is lean4web's production default: editor + websocket.
ENV NODE_ENV=production \
NO_BWRAP=true \
PORT=8080
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=5s --start-period=90s --retries=3 \
CMD curl -sf http://localhost:8080/health || exit 1
CMD ["npm", "run", "prod"]

138
lean/README.md Normal file
View File

@@ -0,0 +1,138 @@
# lean/ — the Lean server
This folder builds [lean4web](https://github.com/leanprover-community/lean4web) —
whose server runs a real Lean process (with Mathlib) for every session — as a
Docker image serving websocket sessions on port `8080`. That is why it does not
live in the backend or the frontend: upstream asks for **a dedicated machine**.
The wiki's `/lean` page talks to this server **itself**: `frontend/app/utils/lean/`
implements a Lean language client (JSON-RPC over the websocket), and the page's
Monaco editor, Goals and Messages panes (`LeanWorkbench.vue`) are the wiki's own —
styled by the wiki, themed live. lean4web's bundled client is still built and
served at the port's root (dressed in the wiki's skin, see below); the editor's
status bar links to it for features the wiki client does not chase — live
collaboration and interactive widgets.
## Build & run
```bash
docker compose build lean # long: fetches Mathlib and unpacks its cache
docker compose up -d lean # → http://localhost:8080 (and the wiki's /lean)
docker compose logs -f lean
# or plain docker
docker build -t mathew-lean ./lean
docker run --rm -p 8080:8080 mathew-lean
```
`GET http://localhost:8080/health` answers when the server is up — the image
carries a `HEALTHCHECK` for it. The frontend finds the server at
`NUXT_PUBLIC_LEAN_URL` (default `http://localhost:8080`, dev included), so out
of the box there is nothing else to configure.
To build against a fixed lean4web release rather than its `main`:
```bash
docker build --build-arg LEAN4WEB_REF=v0.2.2 -t mathew-lean ./lean
```
(any branch or tag; the clone is shallow, so commit SHAs are not offered.)
## The protocol the wiki's client speaks
The websocket endpoint is `/websocket/<project>` (project names come from
`GET /api/projects`, answered only same-origin — the REST endpoints carry no
CORS headers, so the wiki falls back to `MathlibDemo` when reaching the
server across origins; the websocket itself is CORS-free).
One JSON-RPC message per frame — the Lean 4 language
server protocol, which the server forwards raw to a per-session `lake serve`.
What `frontend/app/utils/lean/lsp.ts` + `useLeanSession.ts` do with it:
1. `initialize` — and Lean is strict here: `rootUri` must be a **string** (the
server's URI rewriter throws on `null` and the message vanishes silently),
`window.showDocument` must be `{ support: … }`, `insertTextFormat` must be
`{ valueSet: [...] }`; the Lean watchdog exits the session on anything it
cannot parse. Positions negotiate as `utf-16`, which matches Monaco.
2. `initialized`, then `textDocument/didOpen` a single document named
`<project>/Main.lean`; edits go as debounced whole-document `didChange`s.
3. Goals: the custom request `$/lean/plainGoal` at the cursor answers
`{ goals: string[], rendered }`. (`$/lean/plainMessages` no longer exists —
Lean puts `#check`-style output in **severity-3 `publishDiagnostics`**,
which is what the wiki's Messages pane reads; elaboration busy-state comes
from `$/lean/fileProgress`.)
4. Server→client requests (`client/registerCapability`, `*/refresh`,
`workspace/configuration`) get automatic `null` acknowledgements — a
single-document client must still answer, or Lean waits.
## The skinned classic client
Reaching the server's own address (the wiki editor's status-bar link, or a
direct visit) opens lean4web's bundled client — and the image builds it
**wearing the wiki**. `theme/` holds the layer: `mathew.css` redefines the
`--vscode-*` custom properties lean4web itself paints with (top bar, menus,
modals, its Monaco editor) in Mathew's tokens — Computer Modern for the
chrome, the paper/slate surfaces, the violet accent — and bundles the CMU
fonts (with their SIL license); `theme-init.js` records the theme on
`<html data-mathew-theme>` before the first paint, taking `?theme=light|dark`
or the browser's preference. The `Dockerfile` copies both into the client's
`public/`, links them from `index.html`, and retitles the tab.
To re-skin or extend: edit `theme/mathew.css` and rebuild — the patch lands
after the cached Mathlib steps, so it is only a client rebuild.
## The server's own knobs
lean4web reads these from the environment — pass them with `-e` / compose
`environment` if you change them:
| Variable | Default here | Meaning |
| --- | --- | --- |
| `PORT` | `8080` | The one port for the editor client **and** its websocket |
| `NO_BWRAP` | `true` | Run Lean without bubblewrap — see Security below |
| `SSL_CRT_FILE` / `SSL_KEY_FILE` | unset | Serve HTTPS directly (the server also redirects :80 → https) |
| `PROJECTS_BASE_PATH` | `Projects` | Where the Lean projects live, relative to the repo root |
| `VITE_COLLAB` | `true` | lean4web's collaboration feature (set at build time) |
## Security
Upstream wraps each Lean session in [Bubblewrap](https://github.com/containers/bubblewrap);
that needs nested user namespaces, which a plain container does not have — so
this image sets `NO_BWRAP=true` and lets **Docker itself be the sandbox**. The
consequence to keep in mind: whoever can reach port `8080` can run Lean code
on this machine, inside the container. Keep the port on the LAN / VPN, or put
it behind a proxy with authentication, before exposing it past your network.
**TLS matters to the wiki page too**: if Mathew is served over HTTPS, the
browser will refuse the editor's `ws://` connection to an `http://` server
(mixed content). Serve the
Lean server over HTTPS — either its own `SSL_CRT_FILE`/`SSL_KEY_FILE`, or a
reverse proxy in front (websocket upgrade on the same path) — and point
`NUXT_PUBLIC_LEAN_URL` at the `https://` address.
## Updating
The image clones lean4web at build time, so a rebuild is an update:
```bash
docker compose build --pull lean && docker compose up -d lean
```
Rebuilding also re-runs `Projects/*/leanweb-build.sh` — the demo projects are
rebuilt and Mathlib's cache re-fetched, so treat this like the heavy build it
is (several GB of image; run it on the machine that hosts the editor).
## Adding Lean projects
Anything under `Projects/` of the *image source* becomes a selectable project
(`#project=<name>`). To ship one with the image, build a custom image that
copies it in before the project build step:
```dockerfile
FROM mathew-lean AS base # or edit lean/Dockerfile directly
COPY MyProject /opt/lean4web/Projects/MyProject
WORKDIR /opt/lean4web/Projects/MyProject
RUN lake build
```
See upstream's [Adding Projects](https://github.com/leanprover-community/lean4web/blob/main/doc/Projects.md)
for the `leanweb-config.json` each project needs.

View File

@@ -0,0 +1,55 @@
Copyright (C) Authors of original metafont fonts:
Donald Ervin Knuth (cm, concrete fonts)
1995, 1996, 1997 J"org Knappen, 1990, 1992 Norbert Schwarz (ec fonts)
1992-2006 A.Khodulev, O.Lapko, A.Berdnikov, V.Volovich (lh fonts)
1997-2005 Claudio Beccari (cb greek fonts)
2002 FUKUI Rei (tipa fonts)
2003-2005 Han The Thanh (Vietnamese fonts)
1996-2005 Walter Schmidt (cmbright fonts)
Copyright (C) 2003-2009, Andrey V. Panov (panov@canopus.iacp.dvo.ru),
with Reserved Font Family Name "Computer Modern Unicode fonts".
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the copyright statement(s).
"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.

BIN
lean/theme/fonts/cmunbi.ttf Normal file

Binary file not shown.

BIN
lean/theme/fonts/cmunbx.ttf Normal file

Binary file not shown.

BIN
lean/theme/fonts/cmunrm.ttf Normal file

Binary file not shown.

BIN
lean/theme/fonts/cmunti.ttf Normal file

Binary file not shown.

215
lean/theme/mathew.css Normal file
View File

@@ -0,0 +1,215 @@
/* ==================================================================
Mathew — the wiki's skin for lean4web.
Lean4web paints its whole interface — the top bar, menus, modals and
the Monaco editor itself — with the CSS custom properties its VS Code
theme defines (`--vscode-*`), and its app root carries the
`monaco-editor` class so those variables reach every corner of the
page. This layer therefore does not fight the editor's styling: it
redefines that same vocabulary with the wiki's tokens — Computer
Modern for the chrome, the wiki's paper-and-slate surfaces, its
violet for focus, selection and links.
The wiki opens the frame as ?theme=light|dark and the companion
theme-init.js records that on <html data-mathew-theme> before the
first paint; with no parameter (a direct visit) the browser's
preference decides, exactly as lean4web's own default does. The
editor thus opens matching the page around it; the wiki's own theme
switch takes effect on the frame's next mount, not mid-edit — a live
swap would tear down a running Lean session.
The rules that target elements directly (rather than through the
--vscode variables) carry an `html[data-mathew-theme]` prefix: the
client bundles its own stylesheets through JavaScript, which can land
after this link, so specificity, not source order, is what holds.
================================================================== */
/* ---------- the wiki's typeface ---------- */
/* Computer Modern, the wiki's reading face. CMU ships only two weights,
so intermediate weights map onto real faces the way the wiki's own
stylesheet does. */
@font-face {
font-family: 'Computer Modern';
src: url('/fonts/cmunrm.ttf') format('truetype');
font-weight: 100 550;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: 'Computer Modern';
src: url('/fonts/cmunti.ttf') format('truetype');
font-weight: 100 550;
font-style: italic;
font-display: swap;
}
@font-face {
font-family: 'Computer Modern';
src: url('/fonts/cmunbx.ttf') format('truetype');
font-weight: 551 900;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: 'Computer Modern';
src: url('/fonts/cmunbi.ttf') format('truetype');
font-weight: 551 900;
font-style: italic;
font-display: swap;
}
/* ---------- the wiki's palette, as the editor knows it ---------- */
html[data-mathew-theme='light'], html:not([data-mathew-theme]) {
color-scheme: light;
--mw-bg: #f7f8fb;
--mw-bg-elev: #ffffff;
--mw-surface: #ffffff;
--mw-surface-2: #eef1f7;
--mw-input-bg: #ffffff;
--mw-border: #e2e6ef;
--mw-text: #1b2130;
--mw-muted: #5b6478;
--mw-accent: #4f5fe8;
--mw-accent-strong: #3d4dd6;
--mw-on-accent: #ffffff;
--mw-danger: #d1344b;
--mw-warning: #d97706;
--mw-shadow: 0 4px 12px rgb(16 24 40 / 8%), 0 16px 40px -12px rgb(16 24 40 / 18%);
}
html[data-mathew-theme='dark'] {
color-scheme: dark;
--mw-bg: #0a0c12;
--mw-bg-elev: #10131c;
--mw-surface: #141826;
--mw-surface-2: #1a2030;
--mw-input-bg: #0c0f16;
--mw-border: #232a3c;
--mw-text: #e7eaf3;
--mw-muted: #99a1b5;
--mw-accent: #7c8cff;
--mw-accent-strong: #99a5ff;
--mw-on-accent: #0a0c12;
--mw-danger: #f47085;
--mw-warning: #f5a83c;
--mw-shadow: 0 4px 16px rgb(0 0 0 / 40%), 0 24px 48px -16px rgb(0 0 0 / 55%);
}
/* ---------- the same vocabulary, in Mathew's colours ----------
The app root (`.app.monaco-editor`) is where the editor's theme
service publishes --vscode-*; redefining the same names on it, with
an attribute selector for company, outranks the generated rules and
the whole interface — editor included — follows the wiki instead. */
html[data-mathew-theme] body,
html[data-mathew-theme] .monaco-editor {
/* the editor paper */
--vscode-editor-background: var(--mw-surface);
--vscode-editor-foreground: var(--mw-text);
--vscode-editor-selectionBackground: color-mix(in srgb, var(--mw-accent) 26%, transparent);
--vscode-editorCursor-foreground: var(--mw-accent);
--vscode-editorLineNumber-activeForeground: var(--mw-accent);
--vscode-editorGutter-background: var(--mw-surface);
/* chrome: the top bar, menus, popups, hover */
--vscode-menu-background: var(--mw-bg-elev);
--vscode-menu-foreground: var(--mw-text);
--vscode-menu-separatorBackground: var(--mw-border);
--vscode-menu-selectionBackground: var(--mw-surface-2);
--vscode-menu-selectionForeground: var(--mw-text);
--vscode-panel-border: var(--mw-border);
--vscode-widget-shadow: var(--mw-shadow);
/* hovers and suggestions the editor paints */
--vscode-editorWidget-border: var(--mw-border);
--vscode-editorHoverWidget-background: var(--mw-bg-elev);
--vscode-editorHoverWidget-foreground: var(--mw-text);
--vscode-editorHoverWidget-border: var(--mw-border);
/* form controls, buttons, links */
--vscode-input-background: var(--mw-input-bg);
--vscode-input-foreground: var(--mw-text);
--vscode-inputOption-activeForeground: var(--mw-accent);
--vscode-button-background: var(--mw-accent);
--vscode-button-hoverBackground: var(--mw-accent-strong);
--vscode-button-foreground: var(--mw-on-accent);
--vscode-button-border: transparent;
--vscode-textLink-foreground: var(--mw-accent-strong);
--vscode-focusBorder: var(--mw-accent);
/* lists (the file and project pickers) */
--vscode-list-hoverBackground: var(--mw-surface-2);
--vscode-list-dropBackground: color-mix(in srgb, var(--mw-accent) 12%, transparent);
/* the editor draws its own scrollbars — same subtle wash as the wiki's */
--vscode-scrollbarSlider-background: color-mix(in srgb, var(--mw-text) 18%, transparent);
--vscode-scrollbarSlider-hoverBackground: color-mix(in srgb, var(--mw-text) 30%, transparent);
--vscode-scrollbarSlider-activeBackground: color-mix(in srgb, var(--mw-text) 40%, transparent);
/* messages and marks, in the wiki's reds and ambers */
--vscode-notifications-background: var(--mw-bg-elev);
--vscode-notificationsErrorIcon-foreground: var(--mw-danger);
--vscode-editorError-foreground: var(--mw-danger);
--vscode-editorWarning-foreground: var(--mw-warning);
--vscode-editorWarning-background: color-mix(in srgb, var(--mw-warning) 14%, transparent);
--vscode-editorOverviewRuler-warningForeground: var(--mw-warning);
/* inline code, as the wiki sets it */
--vscode-textPreformat-background: var(--mw-surface-2);
--vscode-textPreformat-foreground: var(--mw-text);
}
/* ---------- the chrome, wearing the wiki ---------- */
/* The body: index.css paints it #2b2b2b / white by media query; the
wiki's own ground wins that tie by specificity. */
html[data-mathew-theme] body {
margin: 0;
font-family: 'Computer Modern', 'CMU Serif', Georgia, 'Times New Roman', serif;
background: var(--mw-bg);
color: var(--mw-text);
}
/* Form controls answer to the system font unless told; the editor keeps
its monospace (the wiki sets its own code the same way). */
html[data-mathew-theme] button,
html[data-mathew-theme] input,
html[data-mathew-theme] select,
html[data-mathew-theme] textarea {
font-family: inherit;
}
/* The top bar: the wiki's hairline, and its menu row rounded to a chip */
html[data-mathew-theme] nav {
border-bottom: 1px solid var(--mw-border);
}
html[data-mathew-theme] nav .nav-link,
html[data-mathew-theme] nav select {
border-radius: 8px;
}
/* Syntax errors and warnings read in the wiki's danger red / amber */
html[data-mathew-theme] .loading-ring:after {
border-color: var(--mw-accent) transparent var(--mw-accent) transparent;
}
/* Selection, like the wiki's — accent wash, not system blue */
html[data-mathew-theme] ::selection {
background: color-mix(in srgb, var(--mw-accent) 30%, transparent);
}
/* Scrollbars, the wiki's subtle shape (mirrors its _base.scss) */
html[data-mathew-theme] ::-webkit-scrollbar {
width: 11px;
height: 10px;
}
html[data-mathew-theme] ::-webkit-scrollbar-thumb {
background: color-mix(in srgb, var(--mw-text) 18%, transparent);
border-radius: 8px;
border: 3px solid transparent;
background-clip: content-box;
}
html[data-mathew-theme] ::-webkit-scrollbar-thumb:hover {
background: color-mix(in srgb, var(--mw-text) 30%, transparent);
background-clip: content-box;
}
html[data-mathew-theme] ::-webkit-scrollbar-track {
background: transparent;
}

24
lean/theme/theme-init.js Normal file
View File

@@ -0,0 +1,24 @@
/* Mathew's theme handshake with the wiki (see mathew.css, its stylesheet).
*
* The wiki opens this frame as ?theme=light|dark — the editor cannot see
* the page around it (another origin), but it can at least open wearing
* the same mood. Without the parameter — a direct visit — the browser's
* preference decides, the same rule lean4web follows for its own default.
*
* Runs synchronously in <head>, before the first paint, so the page never
* flashes the wrong palette; <html data-mathew-theme> is the hook the
* stylesheet's overrides hang on. */
(function () {
var param = null
try {
param = new URLSearchParams(window.location.search).get('theme')
} catch (e) {
/* an engine without URLSearchParams gets the fallback below */
}
var theme = param === 'light' || param === 'dark'
? param
: window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
? 'dark'
: 'light'
document.documentElement.setAttribute('data-mathew-theme', theme)
})()