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
2 changes: 1 addition & 1 deletion apps/web/client/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ function selectedProblemLibraries() {
}
function renderAccountProblemDraft() {
const session = state.session;
const show = Boolean(session && draftReady && researchEntry === 'lean' && state.composing && !currentRun() && problemDraftTarget);
const show = Boolean(session && (session.account || problemDraftTarget) && draftReady && researchEntry === 'lean' && state.composing && !currentRun());
problemDraftHost.hidden = !show;
renderProblemDraftPanel(problemDraftHost, show && session ? {
owner: ownerOfSession(session), account: Boolean(session.account), value: leanProblemDraft(captureDraft(), selectedProblemLibraries()),
Expand Down
2 changes: 2 additions & 0 deletions apps/web/client/draftRecovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ function copyDraft(draft: TaskDraft): TaskDraft {
maxTurns: draft.maxTurns, maxRunSeconds: draft.maxRunSeconds, workers: draft.workers,
...(draft.maxTotalTokens !== undefined ? { maxTotalTokens: draft.maxTotalTokens } : {}),
effort: draft.effort, environment: draft.environment, coordination: draft.coordination, templateId: draft.templateId,
...(draft.autoExplain !== undefined ? { autoExplain: draft.autoExplain } : {}),
...(draft.explanationLanguage !== undefined ? { explanationLanguage: draft.explanationLanguage } : {}),
...(draft.researchMode ? { researchMode: draft.researchMode } : {}),
...(draft.skillLoading ? { skillLoading: draft.skillLoading } : {}),
...(draft.nativeTeamCapacity ? { nativeTeamCapacity: draft.nativeTeamCapacity } : {}),
Expand Down
5 changes: 4 additions & 1 deletion apps/web/client/problemDrafts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,15 @@ export function ProblemDraftPanel(props: ProblemDraftPanelProps) {
rememberBinding(props.owner, item.version.value.mode, next, true);
});
if (mounted.current && item.version.value.mode === props.value.mode) {
setOpen(false); setShowArchived(false);
setNotice(submitted ? tx('已复制为新题,原提交记录和归档版本会保留。请先保存这份新草稿。', 'Copied into a new problem. The original submission and archived version remain. Save this new draft first.') : tx('已恢复到编辑器,核对后即可提交。', 'Restored in the editor. Review it before submitting.')); void load(); }
} catch (cause) { if (mounted.current) notify(cause); }
finally { lock.current = false; if (mounted.current) setBusy(false); }
};
const visible = items.map(item => ({ ...item, versions: item.versions.filter(version => showArchived || (version.status ?? 'open') === 'open') })).filter(item => item.versions.length);
return <details class="problem-account-drafts" data-problem-account-drafts open={open} onToggle={event => setOpen(event.currentTarget.open)}>
const original = props.value.mode === 'natural' ? props.value.text : props.value.draft.source;
return <details class="problem-account-drafts" data-problem-account-drafts hidden={!props.target && (!props.account || !original.trim())}
open={open} onToggle={event => setOpen(event.currentTarget.open)}>
<summary>{tx('保存与恢复原题草稿', 'Save and restore problem drafts')}</summary>
<p>{tx('保存到账号后可跨设备恢复;不保存 API Key。', 'Save to your account to restore on another device. API keys are excluded.')}</p>
{!props.account ? <p>{tx('当前草稿只在此标签页保留。登录账号后可跨设备保存。', 'This draft stays in this tab. Sign in to save across devices.')}</p> : <>
Expand Down
4 changes: 2 additions & 2 deletions apps/web/client/solutionRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ export function recordedSolutionRoute(input: RecordedSolutionRouteInput): Soluti
...(delivery ? deliverySections(delivery) : step.kind === 'attempt' ? section(t('提交说明'), step.note) : []),
...section(t('提交版本'), version?.commit, true),
...section(t('检查回执'), strings(check?.receiptIds), true),
...section(t('上一版'), step.kind === 'attempt' ? step.previous?.commit : undefined, true),
...section(t('上一版'), step.kind === 'attempt' ? step.previous?.version.commit : undefined, true),
],
...(version ? { source: { name: version.file ?? 'Submission.lean', commit: version.commit, sha256: delivery?.sourceDigest }, action: recordAction(index, version.source !== undefined) } : {}),
...(version ? { source: { name: check?.file ?? version.file ?? 'Submission.lean', commit: version.commit, sha256: delivery?.sourceDigest }, action: recordAction(index, version.source !== undefined) } : {}),
}, proof ? 'proof' : taskId(step.taskId));
} else if (step.kind === 'plan' || step.kind === 'edit') {
const plan = step.plan;
Expand Down
51 changes: 28 additions & 23 deletions apps/web/client/trajectory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { WebEvent, WebRunStatus } from '../shared';
import type { WebEvent, WebEventDetails, WebRunStatus } from '../shared';
import {
trajectoryLimits, type TrajectoryCheck, type TrajectoryContext, type TrajectoryDelivery, type TrajectoryEdit, type TrajectoryGuidance,
type TrajectoryIndex, type TrajectoryPage, type TrajectoryPlan, type TrajectoryPlanItem, type TrajectoryVersion,
Expand Down Expand Up @@ -45,7 +45,7 @@ export type TrajectoryStep = { at: number } & (
| { kind: 'problem'; targets: string[] }
| { kind: 'plan'; plan: TrajectoryPlan; first: boolean; workerId?: string }
| { kind: 'attempt'; taskId: string; workerId?: string; number: number; outcome: TrajectoryOutcome; ref?: TrajectoryRef;
reused: boolean; integrated: boolean; previous?: TrajectoryVersion; note?: string }
reused: boolean; integrated: boolean; previous?: TrajectoryRef; note?: string }
| { kind: 'proof'; assembled: boolean; workerId?: string; number: number; outcome: TrajectoryOutcome; ref?: TrajectoryRef }
| { kind: 'recheck'; results: RecheckResult[] }
| { kind: 'edit'; edit: TrajectoryEdit; plan?: TrajectoryPlan; results: RecheckResult[] }
Expand Down Expand Up @@ -106,8 +106,8 @@ export function proofDeliveryLookup(deliveries: Iterable<TrajectoryDelivery>) {
/**
* The run as mathematical steps, oldest first: reading the problem, the plan and its revisions, each Agent's attempt at
* each task with its Lean outcome and the version it checked, human edits and guidance, reviews, the assembled proof
* and the final acceptance. Outcomes come from the events; checks are matched to them by task and time to find the
* code, and checked versions no event accounts for become attempts of their own.
* and the final acceptance. Outcomes come from the events; checks match the recorded commit when available.
* The time window distinguishes repeated checks and supports older events without a commit.
*/
export function buildTrajectory(input: TrajectoryInput): TrajectoryStep[] {
const { data } = input, targets = data.context.targets;
Expand All @@ -127,10 +127,11 @@ export function buildTrajectory(input: TrajectoryInput): TrajectoryStep[] {
return found;
};
/** Match the batch outcome and prefer a receipt that explains why it passed or failed. */
const claimAssembly = (at: number, passed: boolean) => {
const found = claim(at, slot => slot.check.originalProblemPassed === passed && slot.check.passed === passed) ??
claim(at, slot => slot.check.originalProblemPassed === passed) ??
claim(at, slot => slot.check.originalProblemPassed === undefined && slot.check.passed === passed &&
const atCommit = (slot: Slot, commit?: string) => commit === undefined || slot.version.commit === commit;
const claimAssembly = (at: number, passed: boolean, commit?: string) => {
const found = claim(at, slot => atCommit(slot, commit) && slot.check.originalProblemPassed === passed && slot.check.passed === passed) ??
claim(at, slot => atCommit(slot, commit) && slot.check.originalProblemPassed === passed) ??
claim(at, slot => atCommit(slot, commit) && slot.check.originalProblemPassed === undefined && slot.check.passed === passed &&
(!targets.length || targets.every(name => slot.check.theorems.includes(name))));
// Older pages may still have a complete copy of the same batch under each goal.
if (found && found.check.originalProblemPassed === undefined) {
Expand All @@ -141,10 +142,12 @@ export function buildTrajectory(input: TrajectoryInput): TrajectoryStep[] {
}
return found;
};
const forTask = (slot: Slot, taskId: string, passed?: boolean) => slot.version.taskId === taskId &&
const forTask = (taskId: string, details: WebEventDetails, passed?: boolean) => (slot: Slot) =>
slot.version.taskId === taskId && atCommit(slot, details.commit) &&
(details.taskDigest === undefined || slot.check.taskVersion === details.taskDigest) &&
slot.check.originalProblemPassed === undefined && (passed === undefined || slot.check.passed === passed);
const latestCheck = (taskId: string, at: number) => {
for (let position = firstAt(at + 1) - 1; position >= 0; position--) if (forTask(slots[position]!, taskId)) return slots[position];
const latestCheck = (at: number, accept: (slot: Slot) => boolean) => {
for (let position = firstAt(at + 1) - 1; position >= 0; position--) if (accept(slots[position]!)) return slots[position];
};
const refOf = (slot: Slot | undefined): TrajectoryRef | undefined => slot && { version: slot.version, check: slot.check };
const deliveryFor = proofDeliveryLookup(data.deliveries.values());
Expand All @@ -167,10 +170,11 @@ export function buildTrajectory(input: TrajectoryInput): TrajectoryStep[] {
const reused = event.type !== 'task_checked';
let passed = details.passed, slot: Slot | undefined;
if (reused) {
// A reused check is the latest recorded one of the task; it is not claimed again.
slot = latestCheck(taskId, at);
passed ??= event.type === 'task_failure_check_reused' ? false : slot?.check.passed;
} else slot = claim(at, item => forTask(item, taskId, passed));
// A reused check refers to an earlier receipt without consuming it again.
if (event.type === 'task_failure_check_reused') passed ??= false;
slot = latestCheck(at, forTask(taskId, details, passed));
passed ??= slot?.check.passed;
} else slot = claim(at, forTask(taskId, details, passed));
if (passed === undefined) return;
const ref = refOf(slot), outcome: TrajectoryOutcome = passed ? details.conditional ? 'conditional' : 'passed' : 'failed';
const previous = lastAttempt.get(taskId);
Expand All @@ -179,17 +183,17 @@ export function buildTrajectory(input: TrajectoryInput): TrajectoryStep[] {
outcome, ref, reused, integrated: false, note: noteOf(taskId, ref) }));
};
const integrated = (event: WebEvent, at: number) => {
const taskId = event.details?.taskId;
const details = event.details ?? {}, taskId = details.taskId;
if (!taskId) return;
// Integrating checks the task on the main line; that check belongs to this step, not to a new attempt.
claim(at, item => forTask(item, taskId, true));
claim(at, forTask(taskId, details, true));
const step = lastAttempt.get(taskId);
if (step) step.integrated = true;
};
const recheck = (event: WebEvent, at: number) => {
const taskId = event.details?.taskId, passed = event.details?.passed;
const details = event.details ?? {}, { taskId, passed } = details;
if (!taskId) return;
const slot = claim(at, item => forTask(item, taskId, passed));
const slot = claim(at, forTask(taskId, details, passed));
const result: RecheckResult = { taskId, passed: passed ?? slot?.check.passed ?? false, ref: refOf(slot),
...(event.type === 'task_conditional_recheck_finished' ? { conditional: true } : {}) };
const last = steps.at(-1);
Expand All @@ -204,7 +208,7 @@ export function buildTrajectory(input: TrajectoryInput): TrajectoryStep[] {
// Rechecking an unchanged candidate repeats the last outcome; only a different result is a step.
if (event.details?.reused && (!lastProof || lastProof.outcome === outcome)) { assembly = undefined; return; }
lastProof = add<StepOf<'proof'>>({ kind: 'proof', at, assembled: assembly !== undefined, workerId: event.details?.workerId ?? assembly?.workerId,
number: 0, outcome, ref: refOf(claimAssembly(at, passed)) });
number: 0, outcome, ref: refOf(claimAssembly(at, passed, event.details?.commit)) });
assembly = undefined;
};
const evaluate = (event: WebEvent, at: number) => {
Expand Down Expand Up @@ -272,14 +276,15 @@ export function buildTrajectory(input: TrajectoryInput): TrajectoryStep[] {
}

const ordered = steps.map((step, position) => ({ step, position })).sort((a, b) => a.step.at - b.step.at || a.position - b.position).map(item => item.step);
const attempts = new Map<string, number>(), versions = new Map<string, TrajectoryVersion>();
const attempts = new Map<string, number>(), versions = new Map<string, TrajectoryRef>();
let proofs = 0;
for (const step of ordered) {
if (step.kind === 'attempt') {
step.number = (attempts.get(step.taskId) ?? 0) + 1; attempts.set(step.taskId, step.number);
const previous = versions.get(step.taskId);
if (step.ref && previous && previous.commit !== step.ref.version.commit) step.previous = previous;
if (step.ref) versions.set(step.taskId, step.ref.version);
if (step.ref && previous && (previous.version.commit !== step.ref.version.commit ||
previous.check?.taskVersion !== step.ref.check?.taskVersion)) step.previous = previous;
if (step.ref) versions.set(step.taskId, step.ref);
} else if (step.kind === 'proof' && !step.assembled) step.number = ++proofs;
}

Expand Down
Loading
Loading