From ba0e6d5ff114f862b49e9d23f6ade35ff5098c12 Mon Sep 17 00:00:00 2001 From: Zhenhao Liu <176368005+LikC1606@users.noreply.github.com> Date: Sun, 29 Nov 2026 20:47:12 +0800 Subject: [PATCH 1/3] Add a community open-problem board with agent tokens A public board where admins publish frozen Lean problems and anyone signed in, or their agent, can claim and solve them. Modeled on goldbach-style open solving; no problems are seeded. - Publishing compiles the problem module in the sandbox first and freezes the statement as TheoremOSCommunity.T.Goal. - Claims are non-exclusive, expire after 48 h, at most 3 per person. - Submissions pass a source guard (no #eval, macros, native_decide, new axioms, kernel options or namespace hijacks), then the sandbox checks `solution` has exactly the frozen Goal type and audits axioms. - The first accepted proof takes the points locked at submit time; later ones are marked late. Queued checks resume after a restart. - People, model and harness leaderboards and an activity feed show only public handles, never emails. - A personal tosc_ agent token (digest stored, one at a time) can claim, release and submit only; the page gives a copyable prompt. - community.html in zh/en; all service messages have English entries, and nine new characters are merged into the -ui-extra font subsets so the page never pulls the 760 KB -common file. Tests: webCommunity unit/route tests, a playwright page check (scripts/test-web-community.ts), and a real sandbox run on standard and mathlib rejecting sorry, wrong-type and weakened statements. Co-Authored-By: Claude Opus 5.5 --- apps/web/client/CommunityBoard.tsx | 276 ++++++++++++++ apps/web/client/app.css | 8 +- apps/web/client/community.css | 76 ++++ apps/web/client/community.html | 16 + apps/web/client/community.ts | 17 + apps/web/community.ts | 379 +++++++++++++++++++ apps/web/communityTypes.ts | 18 + apps/web/i18n/errors.ts | 44 +++ apps/web/server.ts | 24 +- apps/web/shared.ts | 2 +- docs/assets/fonts/NotoSansSC-ui-extra.woff2 | Bin 40064 -> 42424 bytes docs/assets/fonts/NotoSerifSC-ui-extra.woff2 | Bin 30672 -> 32508 bytes docs/website.md | 2 +- scripts/build-web.ts | 4 +- scripts/test-web-community.ts | 103 +++++ scripts/web-i18n.ts | 6 +- tests/webCommunity.test.ts | 219 +++++++++++ 17 files changed, 1183 insertions(+), 11 deletions(-) create mode 100644 apps/web/client/CommunityBoard.tsx create mode 100644 apps/web/client/community.css create mode 100644 apps/web/client/community.html create mode 100644 apps/web/client/community.ts create mode 100644 apps/web/community.ts create mode 100644 apps/web/communityTypes.ts create mode 100644 scripts/test-web-community.ts create mode 100644 tests/webCommunity.test.ts diff --git a/apps/web/client/CommunityBoard.tsx b/apps/web/client/CommunityBoard.tsx new file mode 100644 index 00000000..b1231383 --- /dev/null +++ b/apps/web/client/CommunityBoard.tsx @@ -0,0 +1,276 @@ +import { useEffect, useState } from 'preact/hooks'; +import type { CommunityBoardRow, CommunityOverview, CommunityPublicTask, CommunitySubmission } from '../communityTypes'; +import { loginHref, type WebSession } from '../shared'; +import { localizeMessage } from '../i18n'; + +type Tx = (zh: string, en: string) => string; +type Me = { profile: { handle: string; token: boolean; tokenCreatedAt?: string } | null; admin: boolean; + claims: { taskId: string; title: string; expiresAt: string }[]; submissions: Omit[]; + limits: { claimsPerPerson: number; claimHours: number; submissionsLeft: number; pointsIntervalSeconds: number } }; +type Detail = { task: CommunityPublicTask; claimants: { who?: string; claimedAt: string; expiresAt: string }[]; + submissions: (Omit & { who?: string })[]; + solution?: { id: string; who?: string; source: string; model: string; harness: string } }; +type Tab = 'tasks' | 'boards' | 'activity' | 'join'; + +let csrf = ''; +async function call(route: string, body?: unknown): Promise { + const response = await fetch(route, { method: body === undefined ? 'GET' : 'POST', credentials: 'same-origin', cache: 'no-store', + headers: { Accept: 'application/json', ...(body === undefined ? {} : { 'Content-Type': 'application/json', 'X-CSRF-Token': csrf }) }, + body: body === undefined ? undefined : JSON.stringify(body) }); + const value = await response.json().catch(() => ({})); + if (!response.ok) throw new Error(typeof value.error === 'string' ? value.error : `HTTP ${response.status}`); + return value as T; +} +const when = (iso: string, language: string) => new Date(iso).toLocaleString(language === 'en' ? 'en' : 'zh-CN', { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' }); + +export function CommunityBoard({ language }: { language: 'zh' | 'en' }) { + const tx: Tx = (zh, en) => language === 'en' ? en : zh; + const [overview, setOverview] = useState(); + const [session, setSession] = useState(); + const [me, setMe] = useState(); + const [tab, setTab] = useState(() => (['tasks', 'boards', 'activity', 'join'] as Tab[]).find(item => location.hash === `#${item}`) ?? 'tasks'); + const [open, setOpen] = useState(() => /^#task-(T\d+)$/u.exec(location.hash)?.[1]); + const [error, setError] = useState(''); + const refresh = async () => { + try { + const [board, current] = await Promise.all([call('/api/community/overview'), call('/api/session')]); + csrf = current.csrfToken; setOverview(board); setSession(current); + setMe(current.account ? await call('/api/community/me') : undefined); setError(''); + } catch (failure) { setError(localizeMessage((failure as Error).message)); } + }; + useEffect(() => { void refresh(); const timer = setInterval(() => { if (!document.hidden) void refresh(); }, 15_000); return () => clearInterval(timer); }, []); + const go = (next: Tab) => { setTab(next); setOpen(undefined); history.replaceState(null, '', `#${next}`); }; + const show = (id?: string) => { setOpen(id); history.replaceState(null, '', id ? `#task-${id}` : '#tasks'); }; + if (!overview) return
{error || tx('正在读取社区题目…', 'Loading community problems…')}
; + const signedIn = Boolean(session?.account); + return
+
+
+

{tx('社区开放解题', 'Community open problems')}

+

{tx('管理员发布冻结的 Lean 目标,任何人或其 Agent 都可以认领、提交证明。服务器在隔离沙箱里独立编译并检查公理,第一份通过的证明获得提交那一刻锁定的分数。', + 'Admins publish frozen Lean goals; anyone, or their agent, can claim one and submit a proof. The server compiles it in an isolated sandbox and checks its axioms; the first accepted proof earns the points locked when it was sent.')}

+
+
+
{tx('开放', 'Open')}
{overview.totals.open}
+
{tx('已解出', 'Solved')}
{overview.totals.solved}
+
{tx('提交', 'Submissions')}
{overview.totals.submissions}
+
{tx('解题者', 'Solvers')}
{overview.totals.people}
+
+
+ {!overview.checker &&

{tx('证明校验服务当前不可用,暂不接收提交。', 'The proof checker is unavailable; submissions are paused.')}

} + {error && } + + {tab === 'tasks' && (open + ? show()} changed={refresh} /> + : item.taskId))} />)} + {tab === 'boards' && } + {tab === 'activity' && { setTab('tasks'); show(id); }} />} + {tab === 'join' && } +
; +} +const statusText = (tx: Tx, status: string) => ({ open: tx('开放', 'Open'), solved: tx('已解出', 'Solved'), withdrawn: tx('已撤下', 'Withdrawn'), + queued: tx('排队中', 'Queued'), checking: tx('校验中', 'Checking'), accepted: tx('通过', 'Accepted'), rejected: tx('未通过', 'Rejected'), + late: tx('通过但晚了', 'Accepted, too late') } as Record)[status] ?? status; + +function TaskList({ tasks, tx, open, mine }: { tasks: CommunityPublicTask[]; tx: Tx; open: (id: string) => void; mine: Set }) { + const [filter, setFilter] = useState<'open' | 'solved' | 'all'>('open'); + const shown = tasks.filter(task => filter === 'all' || task.status === filter); + return
+
{(['open', 'solved', 'all'] as const).map(id => + )}
+ {!shown.length ?

{filter === 'open' ? tx('目前没有开放的题目。', 'No open problems right now.') : tx('还没有题目。', 'No problems yet.')}

+ :
    {shown.map(task =>
  1. +
  2. )}
} +
; +} + +function TaskDetail({ id, tx, language, me, signedIn, checker, back, changed }: { id: string; tx: Tx; language: string; me?: Me; signedIn: boolean; + checker: boolean; back: () => void; changed: () => Promise }) { + const [detail, setDetail] = useState(); + const [source, setSource] = useState(''); + const [model, setModel] = useState(() => localStorage.getItem('theoremos.community.model') ?? ''); + const [harness, setHarness] = useState(() => localStorage.getItem('theoremos.community.harness') ?? ''); + const [message, setMessage] = useState(''), [busy, setBusy] = useState(false); + const load = () => call(`/api/community/tasks/${id}`).then(setDetail, failure => setMessage(localizeMessage((failure as Error).message))); + useEffect(() => { void load(); const timer = setInterval(() => { if (!document.hidden) void load(); }, 8_000); return () => clearInterval(timer); }, [id]); + useEffect(() => { if (detail && !source) setSource(`import ${detail.task.module}\n\ntheorem solution : ${detail.task.module}.Goal := by\n sorry\n`); }, [detail]); + if (!detail) return

{message || tx('正在读取题目…', 'Loading problem…')}

; + const { task } = detail, claimed = me?.claims.some(item => item.taskId === id); + const act = async (work: () => Promise, done: string) => { + setBusy(true); setMessage(''); + try { await work(); setMessage(done); await Promise.all([load(), changed()]); } catch (failure) { setMessage(localizeMessage((failure as Error).message)); } finally { setBusy(false); } + }; + const submit = () => act(async () => { + localStorage.setItem('theoremos.community.model', model); localStorage.setItem('theoremos.community.harness', harness); + await call('/api/community/submissions', { taskId: id, source, model, harness }); + }, tx('已提交,正在排队校验。结果会显示在下方。', 'Submitted. It is queued for checking; the result appears below.')); + return
+ +
{task.id}

{task.title}

+ {statusText(tx, task.status)}
+ {task.description &&

{task.description}

} +
+
{task.status === 'open' ? tx('现在提交可得', 'Worth now') : tx('得分', 'Points')}
{task.currentPoints}
+
{tx('环境', 'Environment')}
{task.environment === 'mathlib' ? 'Mathlib' : 'Lean core'}
+
{tx('开放于', 'Opened')}
{when(task.openedAt, language)}
+
{tx('提交次数', 'Submissions')}
{task.submissions}
+
+ {task.status === 'open' &&

{tx(`开放期间每过 ${Math.round((me?.limits.pointsIntervalSeconds ?? 3600) / 60)} 分钟加 1 分;分数在你提交时锁定,只有第一份通过的证明得分。`, + `Each ${Math.round((me?.limits.pointsIntervalSeconds ?? 3600) / 60)} minutes open adds a point. Points lock when you submit; only the first accepted proof scores.`)}

} +

{tx('冻结的题目模块', 'Frozen problem module')} {task.file}

+
{task.source}
+ {detail.solution && <>

{tx('通过的证明', 'Accepted proof')} · {detail.solution.who}{detail.solution.model ? ` · ${detail.solution.model}` : ''}{detail.solution.harness ? ` · ${detail.solution.harness}` : ''}

+
{detail.solution.source}
} + {task.status === 'open' &&
+

{tx('认领与提交', 'Claim and submit')}

+

{detail.claimants.length ? tx(`正在做:${detail.claimants.map(item => item.who).join(tx('、', ', '))}。认领不排他,只是告诉别人你在做。`, + `Working on it: ${detail.claimants.map(item => item.who).join(', ')}. Claims are not exclusive; they tell others you are on it.`) + : tx('还没人认领。认领不排他,只是告诉别人你在做。', 'No one has claimed it yet. Claims are not exclusive; they tell others you are on it.')}

+ {!signedIn ?

{tx('登录后参与', 'Sign in to take part')}

+ : !me?.profile ?

{tx('先在“参与”页设置一个公开名称,排行榜只显示公开名称。', 'Set a public handle on the Join tab first; boards show handles only.')}

+ : <> +
+ + {claimed && } + {me.admin && } +
+