Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 81 additions & 13 deletions apps/web/client/CommunityBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ export function CommunityBoard({ language }: { language: 'zh' | 'en' }) {
event.preventDefault(); go(names[next]![0]); buttons[next]?.focus();
};
if (!overview) return <div class="community-loading" role="status">{error || tx('正在读取社区题目…', 'Loading community problems…')}</div>;
const signedIn = Boolean(session?.account);
const signedIn = Boolean(session?.account), { totals } = overview;
const latest = overview.activity.find(item => item.kind === 'accepted' || item.kind === 'rejected' || item.kind === 'late');
const browse = () => { setFilter('open'); location.hash = 'tasks'; };
return <div class="community" data-community>
<header class="community-head">
<div>
Expand All @@ -94,6 +96,17 @@ export function CommunityBoard({ language }: { language: 'zh' | 'en' }) {
<div><dt>{tx('解题者', 'Solvers')}</dt><dd>{overview.totals.people}</dd></div>
</dl>
</header>
<div class="community-pulse">
<div class="community-progress"><label for="community-progress">{tx('已解出', 'Solved')}</label>
<progress id="community-progress" max={Math.max(1, totals.tasks)} value={totals.solved} /><output for="community-progress">{totals.solved} / {totals.tasks}</output></div>
<span class="community-live"><i aria-hidden="true" class={totals.working ? 'is-on' : ''} />{tx(`${totals.working} 人在做`, `${totals.working} working now`)}</span>
{latest && <button class="community-latest" onClick={() => show(latest.taskId)}>
<strong>{tx('最新核验', 'Latest check')}</strong>
<span class={`community-status is-${latest.kind}`}>{statusText(tx, latest.kind)}</span>
<span>{latest.taskId}{latest.who ? ` · ${localizeMessage(latest.who)}` : ''} · <time dateTime={latest.at}>{when(latest.at, language)}</time></span>
<span aria-hidden="true">→</span></button>}
</div>
<Steps tx={tx} signedIn={signedIn} browse={browse} />
{!overview.checker && <p class="community-notice">{tx('证明校验服务当前不可用,暂不接收提交。', 'The proof checker is unavailable; submissions are paused.')}</p>}
{error && <p class="community-notice" role="alert">{error}</p>}
<div class="community-tabs" role="tablist" aria-label={tx('社区栏目', 'Community sections')} ref={tabs as never} onKeyDown={keys}>
Expand All @@ -104,7 +117,7 @@ export function CommunityBoard({ language }: { language: 'zh' | 'en' }) {
{tab === 'tasks' && (open
? <TaskDetail key={open} id={open} focus={moved.current} tx={tx} language={language} me={me} signedIn={signedIn} checker={overview.checker} back={() => show()} changed={refresh} />
: <TaskList tasks={overview.tasks} tx={tx} open={show} filter={filter} setFilter={setFilter} mine={new Set(me?.claims.map(item => item.taskId))} />)}
{tab === 'boards' && <Boards overview={overview} tx={tx} />}
{tab === 'boards' && <Boards overview={overview} tx={tx} minutes={Math.round((me?.limits.pointsIntervalSeconds ?? 3600) / 60)} browse={browse} />}
{tab === 'activity' && <ActivityFeed overview={overview} tx={tx} language={language} open={show} />}
{tab === 'join' && <Join tx={tx} me={me} signedIn={signedIn} changed={refresh} language={language} />}
</div>
Expand Down Expand Up @@ -223,24 +236,79 @@ function Board({ title, rows, tx }: { title: string; rows: CommunityBoardRow[];
<tbody>{rows.map((row, index) => <tr key={row.unnamed ? "\u0000" : row.name} class={index < 3 ? 'is-top' : ''}><td>{index + 1}</td><td class={row.unnamed ? 'community-muted' : ''}>{localizeMessage(row.name)}</td><td>{row.solved}</td><td>{row.points}</td></tr>)}</tbody></table>}
</section>;
}
function Boards({ overview, tx }: { overview: CommunityOverview; tx: Tx }) {
return <div class="community-boards">
<Board title={tx('解题者', 'Solvers')} rows={overview.people} tx={tx} />
<Board title={tx('模型(自报)', 'Models (self-reported)')} rows={overview.models} tx={tx} />
<Board title={tx('工具链(自报)', 'Harnesses (self-reported)')} rows={overview.harnesses} tx={tx} />
</div>;
function Boards({ overview, tx, minutes, browse }: { overview: CommunityOverview; tx: Tx; minutes: number; browse: () => void }) {
const [span, setSpan] = useState<'all' | 'week'>('all');
const boards = span === 'all' ? overview : overview.week;
return <section aria-label={tx('排行榜', 'Leaderboards')}>
<div class="community-filter" role="group" aria-label={tx('统计时段', 'Period')}>{(['all', 'week'] as const).map(id =>
<button key={id} class={span === id ? 'is-on' : ''} aria-pressed={span === id} onClick={() => setSpan(id)}>{id === 'all' ? tx('累计', 'All time') : tx('最近 7 天', 'Last 7 days')}</button>)}</div>
<p class="community-hint community-rules">{tx(`每题有基础分,开放期间每满 ${minutes} 分钟加 1 分。分数在提交时锁定,只有第一份通过校验的证明得分。模型和工具链由提交者自报,榜单不是模型能力评测。`,
`Each problem starts at its base points and gains 1 point every ${minutes} minutes it stays open. Points lock at submission, and only the first accepted proof scores. Models and harnesses are self-reported, so these boards are not a model benchmark.`)}</p>
<div class="community-boards">
<Board title={tx('解题者', 'Solvers')} rows={boards.people} tx={tx} />
<Board title={tx('模型(自报)', 'Models (self-reported)')} rows={boards.models} tx={tx} />
<Board title={tx('工具链(自报)', 'Harnesses (self-reported)')} rows={boards.harnesses} tx={tx} />
</div>
<div class="community-candidate">
<span class="community-rank">#{boards.people.length + 1}</span>
<div><strong>{tx('下一个上榜的可以是你', 'The next name here could be yours')}</strong>
<p class="community-hint">{tx('第一份通过校验的证明就会记入榜单。', 'Your first accepted proof puts you on the board.')}</p></div>
<button class="button" onClick={browse}>{tx('看开放题', 'See open problems')}</button>
</div>
</section>;
}

const activityPage = 20;
function ActivityFeed({ overview, tx, language, open }: { overview: CommunityOverview; tx: Tx; language: string; open: (id: string) => void }) {
const [only, setOnly] = useState<'all' | 'checks'>('all'), [page, setPage] = useState(0);
const verb = (kind: string, points?: number) => ({ published: tx('发布了', 'published'), claimed: tx('认领了', 'claimed'), released: tx('放弃了', 'released'),
submitted: tx('提交了', 'submitted to'), accepted: tx(`解出了(+${points ?? 0} 分)`, `solved (+${points ?? 0} pts)`),
rejected: tx('的提交未通过:', 'had a rejected submission on'), late: tx('也证出了,但晚了一步:', 'also proved, too late:') } as Record<string, string>)[kind] ?? kind;
if (!overview.activity.length) return <p class="community-empty">{tx('还没有动态。', 'Nothing has happened yet.')}</p>;
return <ol class="community-activity">{overview.activity.map((item, index) => <li key={`${item.at}-${index}`} class={`is-${item.kind}`}>
<time dateTime={item.at}>{when(item.at, language)}</time>
<span><strong class={item.who ? '' : 'community-muted'}>{item.who ? localizeMessage(item.who) : tx('管理员', 'Admin')}</strong> {verb(item.kind, item.points)} <button class="community-link" onClick={() => open(item.taskId)}>{item.taskId}</button>
{item.model ? <small> · {item.model}</small> : null}</span>
</li>)}</ol>;
const checks = overview.activity.filter(item => item.kind === 'accepted' || item.kind === 'rejected' || item.kind === 'late');
const items = only === 'all' ? overview.activity : checks, pages = Math.max(1, Math.ceil(items.length / activityPage)), at = Math.min(page, pages - 1);
const pick = (next: 'all' | 'checks') => { setOnly(next); setPage(0); };
return <section aria-label={tx('动态', 'Activity')}>
<div class="community-filter" role="group" aria-label={tx('动态类型', 'Activity type')}>{(['all', 'checks'] as const).map(id =>
<button key={id} class={only === id ? 'is-on' : ''} aria-pressed={only === id} onClick={() => pick(id)}>
{id === 'all' ? tx('全部', 'All') : tx('核验结果', 'Check results')}<span>{(id === 'all' ? overview.activity : checks).length}</span></button>)}</div>
{!items.length ? <p class="community-empty">{tx('还没有核验结果。', 'No check results yet.')}</p>
: <ol class="community-activity">{items.slice(at * activityPage, (at + 1) * activityPage).map((item, index) => <li key={`${item.at}-${index}`} class={`is-${item.kind}`}>
<time dateTime={item.at}>{when(item.at, language)}</time>
<span><strong class={item.who ? '' : 'community-muted'}>{item.who ? localizeMessage(item.who) : tx('管理员', 'Admin')}</strong> {verb(item.kind, item.points)} <button class="community-link" onClick={() => open(item.taskId)}>{item.taskId}</button>
{item.model ? <small> · {item.model}</small> : null}</span>
</li>)}</ol>}
{pages > 1 && <nav class="community-pager" aria-label={tx('动态分页', 'Activity pages')}>
<button disabled={at === 0} aria-label={tx('首页', 'First page')} onClick={() => setPage(0)}>«</button>
<button disabled={at === 0} aria-label={tx('上一页', 'Previous page')} onClick={() => setPage(at - 1)}>‹</button>
<span aria-live="polite">{at + 1} / {pages}</span>
<button disabled={at === pages - 1} aria-label={tx('下一页', 'Next page')} onClick={() => setPage(at + 1)}>›</button>
<button disabled={at === pages - 1} aria-label={tx('末页', 'Last page')} onClick={() => setPage(pages - 1)}>»</button>
</nav>}
</section>;
}

function Steps({ tx, signedIn, browse }: { tx: Tx; signedIn: boolean; browse: () => void }) {
const [note, setNote] = useState('');
const copy = () => navigator.clipboard?.writeText(agentPrompt(location.origin, tx)).then(() => setNote(tx('已复制。', 'Copied.')),
() => setNote(tx('复制失败,请在“参与”页手动选中复制。', 'Copy failed; select it by hand on the Join tab.')));
// Open for visitors on wide screens; on a phone the three cards would push the problem list below the fold.
const [wide] = useState(() => matchMedia('(min-width: 821px)').matches);
return <details class="community-guide" open={!signedIn && wide}>
<summary>{tx('三步参与', 'Join in three steps')}</summary>
<ol class="community-steps">
<li><strong>{tx('选一道开放题', 'Pick an open problem')}</strong>
<p class="community-hint">{tx('看冻结的 Lean 命题、当前分数和谁在做。浏览不需要登录。', 'Read the frozen Lean goal, its current points and who is working on it. Browsing needs no account.')}</p>
<div class="community-step-actions"><button class="button" onClick={browse}>{tx('看开放题', 'See open problems')}</button></div></li>
<li><strong>{tx('生成 Agent 令牌', 'Issue an agent token')}</strong>
<p class="community-hint">{tx('登录并设置公开名称后,在“参与”页生成。令牌只能认领、放弃和提交。', 'Sign in and set a public handle, then issue one on the Join tab. A token can only claim, release and submit.')}</p>
<div class="community-step-actions"><a class="button" href="#join">{signedIn ? tx('去生成令牌', 'Issue a token') : tx('登录后生成', 'Sign in to issue one')}</a></div></li>
<li><strong>{tx('把说明交给 Agent', 'Hand the instructions to your agent')}</strong>
<p class="community-hint">{tx('粘贴到 Codex、Claude Code 或 Cursor,由 Agent 认领题目、提交证明并跟踪校验结果。', 'Paste them into Codex, Claude Code or Cursor; the agent claims a problem, submits a proof and follows the check.')}</p>
<div class="community-step-actions"><button class="button" onClick={copy}>{tx('复制说明', 'Copy instructions')}</button>
<span class="community-hint" role="status">{note}</span></div></li>
</ol>
</details>;
}

function agentPrompt(origin: string, tx: Tx) {
Expand Down
34 changes: 34 additions & 0 deletions apps/web/client/community.css
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,43 @@
.community-token{display:flex;align-items:center;gap:12px;margin-top:12px;padding:12px 14px;background:var(--gray-50);border:1px dashed var(--gray-300);border-radius:var(--radius-sm)}
.community-token code{flex:1;font-size:13px;word-break:break-all}
.community-publish{margin-top:36px;padding-top:8px;border-top:1px solid var(--gray-200)}
.community-pulse{display:flex;flex-wrap:wrap;align-items:center;gap:10px 28px;margin-top:22px;padding:12px 0;border-block:1px solid var(--gray-200);font-size:14px}
.community-progress{display:flex;align-items:center;gap:10px;color:var(--gray-700)}
.community-progress progress{appearance:none;width:160px;height:6px;border:0;border-radius:9999px;background:var(--gray-100);overflow:hidden}
.community-progress progress::-webkit-progress-bar{background:var(--gray-100);border-radius:9999px}
.community-progress progress::-webkit-progress-value{background:var(--green-600);border-radius:9999px}
.community-progress progress::-moz-progress-bar{background:var(--green-600);border-radius:9999px}
.community-progress output{font-variant-numeric:tabular-nums;color:var(--gray-900)}
.community-live{display:inline-flex;align-items:center;gap:8px;color:var(--gray-700)}
.community-live i{width:8px;height:8px;border-radius:50%;background:var(--gray-300)}
.community-live i.is-on{background:var(--green-600);box-shadow:0 0 0 3px var(--green-50)}
.community-latest{display:inline-flex;flex-wrap:wrap;align-items:center;gap:4px 10px;margin-left:auto;border:0;background:none;font:inherit;font-size:14px;color:var(--gray-700);padding:4px 0;cursor:pointer;text-align:left;min-height:32px}
.community-latest strong{color:var(--gray-900);font-weight:600}
.community-latest:hover span:last-child{color:var(--blue-600)}
.community-guide{margin-top:16px;border:1px solid var(--gray-200);border-radius:var(--radius-md);background:var(--card)}
.community-guide summary{cursor:pointer;padding:12px 18px;font-weight:600;color:var(--gray-900);min-height:44px}
.community-steps{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:0;margin:0;padding:0 0 4px;list-style:none;counter-reset:step;border-top:1px solid var(--gray-200)}
.community-steps li{display:flex;flex-direction:column;align-items:flex-start;gap:8px;padding:16px 18px;counter-increment:step;min-width:0}
.community-steps li+li{border-left:1px solid var(--gray-200)}
.community-steps strong::before{content:counter(step);display:inline-grid;place-items:center;width:22px;height:22px;margin-right:8px;border-radius:50%;background:var(--gray-900);color:var(--paper);font-size:12px;font-weight:600}
.community-steps .community-hint{margin-top:0!important}
.community-step-actions{display:flex;align-items:center;gap:12px;margin-top:auto;padding-top:4px}
.community-progress label{font-size:14px}
.community-steps .button{text-decoration:none}
.community-rules{margin:0 0 16px!important}
.community-candidate{display:flex;align-items:center;gap:16px;margin-top:20px;padding:14px 18px;border:1px dashed var(--gray-300);border-radius:var(--radius-md)}
.community-candidate>div{flex:1;min-width:0}
.community-candidate .community-hint{margin-top:2px!important}
.community-rank{font-size:20px;font-variant-numeric:tabular-nums;color:var(--gray-500);min-width:2.5em}
.community-pager{display:flex;align-items:center;justify-content:center;gap:6px;margin-top:16px;font-variant-numeric:tabular-nums;color:var(--gray-700)}
.community-pager button{min-width:36px;min-height:36px;border:1px solid var(--gray-200);background:var(--card);border-radius:var(--radius-sm);font:inherit;color:var(--gray-800);cursor:pointer}
.community-pager button:disabled{opacity:.4;cursor:default}
.community-pager span{padding:0 10px}
@media(max-width:820px){.community-head{flex-direction:column;gap:20px}.community-boards{grid-template-columns:1fr}.community-tasks button{grid-template-columns:40px minmax(0,1fr) 56px;gap:8px 12px;padding:14px 16px}.community-tasks .community-side{grid-row:2;grid-column:2/4;flex-direction:row;flex-wrap:wrap;align-items:center;gap:4px 10px}.community-tasks .community-points{grid-row:1;grid-column:3}.community-tasks .community-id{align-self:start;padding-top:2px}}
@media(max-width:520px){.community h1{font-size:26px}.community-totals{grid-template-columns:repeat(4,minmax(0,1fr));gap:4px 12px;width:100%}.community-totals dt{font-size:11px}.community-totals dd{font-size:20px}.community-tasks button{grid-template-columns:minmax(0,1fr) 52px}.community-tasks .community-id{display:none}.community-tasks .community-title{grid-column:1}.community-tasks .community-points{grid-column:2}.community-tasks .community-side{grid-column:1/3}.community-facts{gap:12px 28px}.community-activity li{grid-template-columns:1fr;gap:2px}.community-work{padding:4px 16px 16px}}
.community-detail h2:focus:not(:focus-visible){outline:none}
.community-field textarea[wrap=off]{white-space:pre;overflow-x:auto}
@media(max-width:520px){.community-tabs{gap:0}.community-tabs button{padding:10px 11px;font-size:14px}.community-facts{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px 20px}}
@media(max-width:820px){.community-steps{grid-template-columns:1fr}.community-steps li+li{border-left:0;border-top:1px solid var(--gray-200)}.community-latest{margin-left:0}}
@media(max-width:520px){.community-candidate{flex-wrap:wrap}.community-progress progress{width:110px}}
@media(max-width:360px){.community-totals{grid-template-columns:repeat(2,minmax(0,1fr))}.community-tabs button{padding:10px 8px;font-size:13px}}
Loading
Loading