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
4 changes: 2 additions & 2 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ jobs:
strategy:
fail-fast: false
matrix:
lean: ['4.33.0', '4.34.1']
lean: ['4.34.1', '4.36.0']
env:
THEOREMOS_TEST_LEAN_VERSION: ${{ matrix.lean }}
# Mocked project fixtures also probe elan; use the installed matrix release.
Expand Down Expand Up @@ -160,7 +160,7 @@ jobs:
- name: Verify dependency snapshots and receipt cache bindings
run: bunx vitest run --maxWorkers=4 tests/verifierSealedEnvironmentCache.test.ts tests/mathProofEnvironment.test.ts tests/leanProbeSnapshot.test.ts
- name: Verify sealed roles, native team sessions and historical inspection without models
if: matrix.lean == '4.33.0'
if: matrix.lean == '4.36.0'
run: bunx vitest run --maxWorkers=1 tests/formalizationSandbox.test.ts tests/formalizationAudit.test.ts tests/agentSessionPlan.test.ts tests/codexSession.test.ts tests/skillRunInspection.test.ts tests/workflowHarness.test.ts tests/agentTeamTransportFallback.test.ts tests/codexSessionAgentControl.test.ts
- name: Verify projected proof contracts and retained source contexts
run: bunx vitest run --maxWorkers=4 tests/taskTypeContract.test.ts tests/projectionNotation.test.ts tests/taskSourceImplicitInstances.test.ts tests/taskSourceMacroProjection.test.ts tests/taskSourceNotationHints.test.ts tests/taskSourceNotationContext.test.ts
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<a href="https://westlakenlp.com/"><img alt="WestlakeNLP Lab" src="https://img.shields.io/badge/Lab-WestlakeNLP-1e3a5f?style=flat&amp;labelColor=292524"></a>
<a href="./docs/releases/v0.1.0.md"><img alt="Release v0.1.0" src="https://img.shields.io/badge/release-v0.1.0-57534e?style=flat&amp;labelColor=292524"></a>
<a href="https://github.com/HuggingMath/theorem-os/actions/workflows/verify.yml"><img alt="Verify TheoremOS CI" src="https://img.shields.io/github/actions/workflow/status/HuggingMath/theorem-os/verify.yml?branch=main&amp;style=flat&amp;labelColor=292524&amp;label=CI"></a>
<a href="./examples/getting-started/README.md"><img alt="Lean 4.33.0" src="https://img.shields.io/badge/Lean-4.33.0-2f6f56?style=flat&amp;labelColor=292524"></a>
<a href="./examples/getting-started/README.md"><img alt="Lean 4.36.0" src="https://img.shields.io/badge/Lean-4.36.0-2f6f56?style=flat&amp;labelColor=292524"></a>
<a href="./LICENSE"><img alt="License AGPL-3.0-only" src="https://img.shields.io/badge/license-AGPL--3.0--only-c95633?style=flat&amp;labelColor=292524"></a>
</p>
<br>
Expand Down Expand Up @@ -65,7 +65,7 @@ https://github.com/user-attachments/assets/57562769-aa15-474c-87ff-73265f097ec8

| 你想做什么 | 推荐入口 | 需要准备 |
| --- | --- | --- |
| **免密钥体验独立 Lean 验收闭环** | [小题示例与回放](./examples/getting-started/README.md) | Linux、Bun 1.2+、Lean 4.33.0(无需模型 API Key) |
| **免密钥体验独立 Lean 验收闭环** | [小题示例与回放](./examples/getting-started/README.md) | Linux、Bun 1.2+、Lean 4.36.0(无需模型 API Key) |
| **使用在线云端工作台** | [在线工作台](https://app.theoremos.top/) · [申请内测](https://github.com/HuggingMath/TheoremOS/issues/new?template=early-access.yml) | 白名单邮箱与支持 Responses API 的模型 Key |
| **本地 Docker Compose 自部署网页工作台** | [工作台部署指南](./docs/web-workbench.md) · [`compose.yml`](./apps/web/compose.yml) | Linux、Docker Compose、`/dev/fuse`(完整 Mathlib 环境) |
| **替换 M1–M5 研究策略并跑基准对比** | [组件替换示例](./examples/components/README.md) · [IMO2026 示例](./examples/imo2026/README.md) | Codex CLI、Elan/Lean、Bubblewrap 与 FUSE |
Expand All @@ -77,7 +77,7 @@ https://github.com/user-attachments/assets/57562769-aa15-474c-87ff-73265f097ec8
```bash
git clone https://github.com/HuggingMath/theorem-os.git && cd theorem-os
bun install --frozen-lockfile
elan toolchain install leanprover/lean4:v4.33.0
elan toolchain install leanprover/lean4:v4.36.0

export THEOREMOS_REPLAY="$PWD/../theorem-os-runs/first-replay"
bun run math doctor --lean-only
Expand Down
6 changes: 3 additions & 3 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<a href="https://westlakenlp.com/"><img alt="WestlakeNLP Lab" src="https://img.shields.io/badge/Lab-WestlakeNLP-1e3a5f?style=flat&amp;labelColor=292524"></a>
<a href="./docs/releases/v0.1.0.md"><img alt="Release v0.1.0" src="https://img.shields.io/badge/release-v0.1.0-57534e?style=flat&amp;labelColor=292524"></a>
<a href="https://github.com/HuggingMath/theorem-os/actions/workflows/verify.yml"><img alt="Verify TheoremOS CI" src="https://img.shields.io/github/actions/workflow/status/HuggingMath/theorem-os/verify.yml?branch=main&amp;style=flat&amp;labelColor=292524&amp;label=CI"></a>
<a href="./examples/getting-started/README.md"><img alt="Lean 4.33.0" src="https://img.shields.io/badge/Lean-4.33.0-2f6f56?style=flat&amp;labelColor=292524"></a>
<a href="./examples/getting-started/README.md"><img alt="Lean 4.36.0" src="https://img.shields.io/badge/Lean-4.36.0-2f6f56?style=flat&amp;labelColor=292524"></a>
<a href="./LICENSE"><img alt="License AGPL-3.0-only" src="https://img.shields.io/badge/license-AGPL--3.0--only-c95633?style=flat&amp;labelColor=292524"></a>
</p>
<br>
Expand Down Expand Up @@ -66,7 +66,7 @@ https://github.com/user-attachments/assets/57562769-aa15-474c-87ff-73265f097ec8

| What you want to do | Where to start | Requirements |
| --- | --- | --- |
| **Replay local Lean verification (no API key)** | [Getting-Started Example](./examples/getting-started/README.md) | Linux, Bun 1.2+, Lean 4.33.0 (stdlib only; zero LLM calls) |
| **Replay local Lean verification (no API key)** | [Getting-Started Example](./examples/getting-started/README.md) | Linux, Bun 1.2+, Lean 4.36.0 (stdlib only; zero LLM calls) |
| **Try the hosted cloud workbench** | [Cloud Workbench](https://app.theoremos.top/) · [Request Access](https://github.com/HuggingMath/TheoremOS/issues/new?template=early-access.yml) | Allowlisted email &amp; Responses API key |
| **Self-host the workbench via Docker Compose** | [Workbench Deployment Guide](./docs/web-workbench.md) · [`compose.yml`](./apps/web/compose.yml) | Linux, Docker Compose, `/dev/fuse` (full Mathlib image) |
| **Swap M1–M5 research policies &amp; benchmark** | [Component Example](./examples/components/README.md) · [IMO2026 Guide](./examples/imo2026/README.md) | Codex CLI, Elan/Lean, Bubblewrap &amp; FUSE |
Expand All @@ -78,7 +78,7 @@ Run the standalone standard-library example on your host (no Mathlib download or
```bash
git clone https://github.com/HuggingMath/theorem-os.git && cd theorem-os
bun install --frozen-lockfile
elan toolchain install leanprover/lean4:v4.33.0
elan toolchain install leanprover/lean4:v4.36.0

export THEOREMOS_REPLAY="$PWD/../theorem-os-runs/first-replay"
bun run math doctor --lean-only
Expand Down
9 changes: 5 additions & 4 deletions apps/web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ENV ELAN_HOME=/opt/elan \
COPY scripts/install-elan.sh ./scripts/install-elan.sh
RUN npm install --global @openai/codex@0.172.0 \
&& sh scripts/install-elan.sh \
&& elan toolchain install leanprover/lean4:v4.33.0 \
&& elan toolchain install leanprover/lean4:v4.36.0 \
&& chmod -R a+rX /opt/elan \
&& mkdir -p /work && chown 10001:10001 /work \
&& install -d -o 10001 -g 10001 -m 0700 /var/theoremos-proof
Expand All @@ -73,17 +73,18 @@ RUN apt-get -o Acquire::Retries=3 update && apt-get install -y --no-install-reco
&& rm -rf /var/lib/apt/lists/*
COPY resources/mathlib/environment.json ./resources/mathlib/environment.json
COPY scripts/prepare-web-mathlib.ts ./scripts/prepare-web-mathlib.ts
RUN --mount=type=cache,id=theoremos-mathlib-v4.33.0,target=/var/cache/theoremos-mathlib,sharing=locked \
RUN --mount=type=cache,id=theoremos-mathlib-v4.36.0,target=/var/cache/theoremos-mathlib,sharing=locked \
MATHLIB_CACHE_DIR=/var/cache/theoremos-mathlib bun scripts/prepare-web-mathlib.ts \
&& chmod -R a+rX /opt/theoremos-mathlib \
&& chown 10001:10001 /var/tmp && chmod 0700 /var/tmp
COPY scripts/build-pantograph.ts ./scripts/build-pantograph.ts
COPY scripts/pantograph/ ./scripts/pantograph/
RUN bun scripts/build-pantograph.ts /opt/theoremos-pantograph

FROM worker-mathlib AS worker
ENV TMPDIR=/tmp \
PATH=/opt/elan/toolchains/leanprover--lean4---v4.33.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin \
DEEPSCIENTIST_MATH_TRUSTED_ELAN_ROOTS=/opt/elan/toolchains/leanprover--lean4---v4.33.0 \
PATH=/opt/elan/toolchains/leanprover--lean4---v4.36.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin \
DEEPSCIENTIST_MATH_TRUSTED_ELAN_ROOTS=/opt/elan/toolchains/leanprover--lean4---v4.36.0 \
DEEPSCIENTIST_MATH_TRUSTED_CACHE_ROOTS=/opt/theoremos-mathlib/.lake/packages
COPY --from=source /opt/theorem-os /opt/theorem-os
RUN bun scripts/prepare-web-library.ts \
Expand Down
7 changes: 5 additions & 2 deletions apps/web/formalizationReport.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { formalizationDigest, type FormalizationEvidence } from '../../src/math/formalization';
import { collapsed, count, identifierChar, lineEnds, offsetSpans, type SourceOffsets } from '../../src/math/informalizationAlignment';
import { inspectLeanDeclarationRegions, inspectScopedLeanDeclarations } from '../../src/math/leanSource';
import { getLeanTaskEnvironment } from '../../src/math/leanTaskEnvironment';
import { recordedLeanTaskEnvironment } from '../../src/math/leanTaskEnvironment';
import { maskLeanComments } from '../../src/math/leanSyntax';
import { webFormalizationAspects, webFormalizationRelationRank, type WebExplanationSpan, type WebFormalizationCorrespondence, type WebFormalizationReport } from './shared';

Expand Down Expand Up @@ -114,7 +114,10 @@ export function formalizationCorrespondences(evidence: FormalizationEvidence, so

/** The comparison page preserves whether a statement was independently reviewed or only compiled. */
export function formalizationReport(evidence: FormalizationEvidence): WebFormalizationReport {
const statement = lineEnds(evidence.candidate.source), environment = getLeanTaskEnvironment(evidence.request.environment);
const statement = lineEnds(evidence.candidate.source);
// The report names the Lean and Mathlib the evidence was checked in, not today's pins.
const environment = recordedLeanTaskEnvironment(evidence.request.environment, evidence.request.environmentDigest);
if (!environment) throw new Error('formalization_request_environment_unknown');
const masked = maskLeanComments(statement), regions = inspectLeanDeclarationRegions(masked);
const declarations = inspectScopedLeanDeclarations(masked), original = evidence.request.statement;
const targets = evidence.targets.map(target => {
Expand Down
37 changes: 23 additions & 14 deletions apps/web/formalizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { assertFormalizationCompiledCandidate, assertFormalizationEvidence, form
type FormalizationCompiledCandidate, type FormalizationEvidence, type FormalizationRequest } from '../../src/math/formalization';
import { assertFormalizationAuditResult } from '../../src/math/formalizationAudit';
import { reportedTotalTokens } from '../../src/solver/usageBudget';
import { getLeanTaskEnvironment } from '../../src/math/leanTaskEnvironment';
import { getLeanTaskEnvironment, recordedLeanTaskEnvironment } from '../../src/math/leanTaskEnvironment';
import { canonicalMathJson, mathDigest } from '../../src/math/mathRuntimeIo';
import { LEAN_STATEMENT_CONTEXT_PROTOCOL } from '../../src/math/leanStatementSemantic';
import { webLimits } from './config';
Expand Down Expand Up @@ -40,32 +40,34 @@ const recordPath = (owner: string, id: string) => {
return [...directory(owner), id];
};

/** Bound evidence is checked on generation, reading, confirmation and handoff to research. */
export function verifyWebFormalizationEvidence(value: unknown, formalization: WebFormalization): FormalizationEvidence {
/** Bound evidence is checked on generation, reading, confirmation and handoff to research.
* Saved evidence is read in the environment its request recorded; `current` requires today's pins (new work and handoff). */
export function verifyWebFormalizationEvidence(value: unknown, formalization: WebFormalization, current = true): FormalizationEvidence {
const evidence = formalizationEvidenceSchema.parse(value);
if (Buffer.byteLength(evidence.candidate.source) > webLimits.maxSourceBytes) throw new Error('formalization_source_too_large');
assertFormalizationEvidence(evidence);
verifyWebFormalizationRequest(evidence.request, formalization);
verifyWebFormalizationRequest(evidence.request, formalization, current);
if (evidence.execution !== 'model' || !evidence.modelInvoked ||
(formalization.reviewMode === 'direct') !== (evidence.schema === 'theorem-os.formalization-evidence.v4'))
throw new Error('formalization_binding_mismatch');
return evidence;
}
export function verifyWebCompiledCandidate(value: unknown, formalization: WebFormalization): FormalizationCompiledCandidate {
export function verifyWebCompiledCandidate(value: unknown, formalization: WebFormalization, current = true): FormalizationCompiledCandidate {
const compiled = formalizationCompiledCandidateSchema.parse(value);
if (Buffer.byteLength(compiled.candidate.source) > webLimits.maxSourceBytes) throw new Error('formalization_source_too_large');
assertFormalizationCompiledCandidate(compiled);
verifyWebFormalizationRequest(compiled.request, formalization);
verifyWebFormalizationRequest(compiled.request, formalization, current);
return compiled;
}
function verifyWebFormalizationRequest(request: FormalizationRequest, formalization: WebFormalization): void {
function verifyWebFormalizationRequest(request: FormalizationRequest, formalization: WebFormalization, current: boolean): void {
const workflow = request.workflow;
const contextProtocol = formalization.contextProtocol ?? 'kernel-v2';
if (request.schema !== 'theorem-os.formalization-request.v3' || request.contextProtocol !== contextProtocol ||
!readableContextProtocols.includes(contextProtocol) ||
request.reviewMode !== formalization.reviewMode || request.problemId !== formalization.id || request.statement !== formalization.original ||
request.statementSha256 !== mathDigest(formalization.original) || request.environment !== formalization.environment ||
request.environmentDigest !== getLeanTaskEnvironment(formalization.environment).dependencyDigest ||
(current ? request.environmentDigest !== getLeanTaskEnvironment(formalization.environment).dependencyDigest
: !recordedLeanTaskEnvironment(formalization.environment, request.environmentDigest)) ||
request.model !== formalization.model || request.effort !== formalization.effort ||
request.execution !== 'model' ||
request.maxRounds !== (formalization.maxRounds ?? 3) || request.maxRunSeconds !== (formalization.maxRunSeconds ?? 1800) ||
Expand Down Expand Up @@ -143,12 +145,19 @@ export class WebFormalizations {
if (!record || record.owner !== owner) throw new WebStorageError(404, '形式化任务不存在或不属于当前会话。');
return record;
}
private evidence(record: Record) {
/** Reading and confirming accept a recorded older environment; `current` is for handing the evidence to new research. */
private evidence(record: Record, current = false) {
try {
const evidence = verifyWebFormalizationEvidence(this.storage.getRecord([...recordPath(record.owner, record.formalization.id), 'evidence.json']), record.formalization);
const evidence = verifyWebFormalizationEvidence(this.storage.getRecord([...recordPath(record.owner, record.formalization.id), 'evidence.json']),
record.formalization, false);
if (current && evidence.request.environmentDigest !== getLeanTaskEnvironment(evidence.request.environment).dependencyDigest)
throw new WebStorageError(409, '这份形式化来自旧版 Lean 环境,可以查看,但不能用于新的证明,请重新形式化。');
if (formalizationDigest(evidence) !== record.evidenceSha256) throw new Error('formalization_evidence_changed');
return evidence;
} catch { throw new WebStorageError(409, '形式化证据无效或已改变,请重新生成。'); }
} catch (error) {
if (error instanceof WebStorageError) throw error;
throw new WebStorageError(409, '形式化证据无效或已改变,请重新生成。');
}
}
read(owner: string, id: string): WebFormalization {
const record = this.required(owner, id), value = record.formalization;
Expand Down Expand Up @@ -196,7 +205,7 @@ export class WebFormalizations {
confirmed(owner: string, id: string): { formalization: WebFormalization; evidence: FormalizationEvidence } {
const record = this.required(owner, id);
if (record.formalization.status !== 'confirmed') throw new WebStorageError(409, '请先确认原题与 Lean 声明的对应关系。');
const evidence = this.evidence(record);
const evidence = this.evidence(record, true);
return { formalization: this.withReport(record), evidence };
}
/** Starts or retries research from confirmed frozen evidence; it never calls the formalizer again. */
Expand All @@ -207,7 +216,7 @@ export class WebFormalizations {
if (item.status !== 'confirmed' || item.workflow !== 'solve') throw new WebStorageError(409, '请先完成原题形式化。');
if (provider.id !== (item.providerId ?? 'sub2api') || record.provider && record.provider.baseUrl !== provider.baseUrl)
throw new WebStorageError(409, '模型服务地址已改变,请创建新任务。');
const evidence = this.evidence(record);
const evidence = this.evidence(record, true);
const input: WorkerFormalizationInput = { id, original: item.original, environment: item.environment, model: item.model,
effort: item.effort, apiKey, provider, maxRunSeconds: item.maxRunSeconds ?? 1800,
contextProtocol: evidence.request.contextProtocol,
Expand Down Expand Up @@ -334,7 +343,7 @@ export class WebFormalizations {
const metadata = record.formalization.compiled;
if (!metadata) return;
const candidate = verifyWebCompiledCandidate(this.storage.getRecord([
...recordPath(record.owner, record.formalization.id), 'compiled', `${metadata.digest}.json`]), record.formalization);
...recordPath(record.owner, record.formalization.id), 'compiled', `${metadata.digest}.json`]), record.formalization, false);
if (formalizationCompiledCandidateDigest(candidate) !== metadata.digest || metadata.source !== candidate.candidate.source ||
metadata.sourceSha256 !== candidate.sourceSha256) throw new Error('formalization_binding_mismatch');
return candidate;
Expand Down
1 change: 1 addition & 0 deletions apps/web/i18n/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export const errors: Record<string, string> = {
"这次提交对应的形式化已删除,请发起新研究。": "The formalization for this submission was deleted. Start a new research task.",
"自动证明运行环境尚未就绪。": "The automatic proof service is not ready yet.",
"Lean 原题或环境已改变,请重新形式化确认,或作为普通 Lean 题目创建。": "The Lean problem or environment has changed. Formalize and confirm it again, or create a regular Lean problem.",
'这份形式化来自旧版 Lean 环境,可以查看,但不能用于新的证明,请重新形式化。': 'This formalization comes from an older Lean environment. You can view it, but it cannot be used for a new proof. Formalize it again.',
"继续研究必须保留原运行的形式化来源。": "Continuing research must keep the original run's formalization source.",
"已有研究使用这份原题,请先删除相关研究记录。": "Research runs use this original problem. Delete those run records first.",
"请提供当前核对版本。": "Provide the current version being reviewed.",
Expand Down
Loading
Loading