feat: Batch aus der Oberfläche starten

Tauri-Befehle start_batch, cancel_batch, batch_results. Fortschritt läuft
als Ereignis batch-event. Datenbank coding-bench.sqlite im Datenordner.
Oberfläche: Aufgaben wählen, Modelle und Wiederholungen angeben, starten,
abbrechen, Live-Log und Ergebnistabelle. Ollama-URL in config.toml.
40 Unit-Tests grün, svelte-check ohne Fehler. Im Fenster nicht geprüft.
lib.rs wurde vor meiner Änderung auf der Platte zurückgesetzt (ohne
runner/store); ich habe auf dem aktuellen Stand aufgebaut.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-06 19:46:04 +01:00
parent c8290aeb94
commit d49e4cfd05
5 changed files with 392 additions and 13 deletions

View File

@ -1,6 +1,7 @@
<script lang="ts">
import { onMount } from "svelte";
import { onMount, onDestroy } from "svelte";
import { invoke } from "@tauri-apps/api/core";
import { listen, type UnlistenFn } from "@tauri-apps/api/event";
type Paths = {
config_file: string;
@ -12,11 +13,41 @@
type TaskError = { dir: string; message: string };
type LoadReport = { tasks: TaskInfo[]; errors: TaskError[] };
type BatchEvent =
| { kind: "run_started"; model: string; task: string; repeat: number }
| { kind: "run_finished"; model: string; task: string; repeat: number; class: string; score: number }
| { kind: "run_skipped"; model: string; task: string; repeat: number }
| { kind: "model_unavailable"; model: string; reason: string }
| { kind: "progress"; done: number; total: number };
type RunRow = {
model: string;
task_id: string;
repeat_idx: number;
error_class: string;
score: number;
steps: number;
duration_ms: number;
tps: number | null;
};
let paths = $state<Paths | null>(null);
let error = $state("");
let report = $state<LoadReport | null>(null);
let taskError = $state("");
let modelsText = $state("qwen3:0.6b");
let selected = $state<string[]>([]);
let repeats = $state(1);
let running = $state(false);
let log = $state<string[]>([]);
let progress = $state<{ done: number; total: number } | null>(null);
let batchId = $state<number | null>(null);
let rows = $state<RunRow[]>([]);
let batchError = $state("");
let unlisten: UnlistenFn | null = null;
onMount(async () => {
try {
paths = await invoke<Paths>("get_paths");
@ -28,7 +59,69 @@
} catch (e) {
taskError = String(e);
}
unlisten = await listen<BatchEvent>("batch-event", (ev) => onEvent(ev.payload));
});
onDestroy(() => {
if (unlisten) unlisten();
});
function onEvent(e: BatchEvent) {
if (e.kind === "progress") {
progress = { done: e.done, total: e.total };
return;
}
if (e.kind === "model_unavailable") {
log = [...log, `Modell ${e.model} nicht nutzbar: ${e.reason}`];
return;
}
const label = `${e.model} · ${e.task} · Wdh. ${e.repeat}`;
if (e.kind === "run_started") log = [...log, `läuft: ${label}`];
if (e.kind === "run_skipped") log = [...log, `übersprungen: ${label}`];
if (e.kind === "run_finished")
log = [...log, `fertig: ${label} → ${e.class}, Score ${e.score.toFixed(2)}`];
}
function toggleTask(id: string) {
selected = selected.includes(id)
? selected.filter((x) => x !== id)
: [...selected, id];
}
function parseModels(): string[] {
return modelsText
.split(/[\n,]/)
.map((m) => m.trim())
.filter((m) => m.length > 0);
}
async function start() {
batchError = "";
rows = [];
log = [];
progress = null;
batchId = null;
running = true;
try {
const summary = await invoke<{ batch_id: number; cancelled: boolean }>("start_batch", {
models: parseModels(),
taskIds: selected,
repeats,
note: "",
});
batchId = summary.batch_id;
rows = await invoke<RunRow[]>("batch_results", { batchId: summary.batch_id });
if (summary.cancelled) log = [...log, "Batch abgebrochen."];
} catch (e) {
batchError = String(e);
} finally {
running = false;
}
}
async function cancel() {
await invoke<boolean>("cancel_batch");
}
</script>
<main class="container">
@ -58,9 +151,19 @@
<p class="fehler">Fehler: {taskError}</p>
{:else if report}
<p>{report.tasks.length} gültig, {report.errors.length} mit Fehlern.</p>
<ul>
<ul class="tasks">
{#each report.tasks as t (t.dir)}
<li><strong>{t.id}</strong> · {t.title} <span class="gruppe">Gruppe {t.group}</span></li>
<li>
<label>
<input
type="checkbox"
checked={selected.includes(t.id)}
onchange={() => toggleTask(t.id)}
disabled={running}
/>
<strong>{t.id}</strong> · {t.title} <span class="gruppe">Gruppe {t.group}</span>
</label>
</li>
{/each}
</ul>
{#if report.errors.length > 0}
@ -75,6 +178,70 @@
<p>Lade Aufgaben …</p>
{/if}
</section>
<section>
<h2>Batch starten</h2>
<label class="feld">
Modelle (Komma oder Zeilenumbruch)
<textarea rows="2" bind:value={modelsText} disabled={running}></textarea>
</label>
<label class="feld">
Wiederholungen
<input type="number" min="1" max="20" bind:value={repeats} disabled={running} />
</label>
<div class="knöpfe">
<button onclick={start} disabled={running || selected.length === 0 || parseModels().length === 0}>
Starten
</button>
<button onclick={cancel} disabled={!running}>Abbrechen</button>
</div>
{#if progress}
<p>Fortschritt: {progress.done} von {progress.total}</p>
{/if}
{#if batchError}
<p class="fehler">Fehler: {batchError}</p>
{/if}
{#if log.length > 0}
<ul class="log">
{#each log as line, i (i)}
<li>{line}</li>
{/each}
</ul>
{/if}
</section>
{#if batchId !== null && rows.length > 0}
<section>
<h2>Ergebnisse, Batch {batchId}</h2>
<table>
<thead>
<tr>
<th>Modell</th>
<th>Aufgabe</th>
<th>Wdh.</th>
<th>Klasse</th>
<th>Score</th>
<th>Schritte</th>
<th>Dauer</th>
</tr>
</thead>
<tbody>
{#each rows as r (`${r.model}|${r.task_id}|${r.repeat_idx}`)}
<tr>
<td>{r.model}</td>
<td>{r.task_id}</td>
<td>{r.repeat_idx}</td>
<td>{r.error_class}</td>
<td>{r.score.toFixed(2)}</td>
<td>{r.steps}</td>
<td>{(r.duration_ms / 1000).toFixed(1)} s</td>
</tr>
{/each}
</tbody>
</table>
</section>
{/if}
</main>
<style>
@ -100,6 +267,10 @@
max-width: 48rem;
}
section {
margin-bottom: 2rem;
}
dl {
display: grid;
grid-template-columns: max-content 1fr;
@ -115,6 +286,43 @@
overflow-wrap: anywhere;
}
.tasks {
list-style: none;
padding: 0;
}
.feld {
display: flex;
flex-direction: column;
gap: 0.3rem;
margin-bottom: 0.8rem;
}
.knöpfe {
display: flex;
gap: 0.6rem;
margin-bottom: 0.8rem;
}
.log {
max-height: 16rem;
overflow-y: auto;
font-family: monospace;
font-size: 0.85rem;
}
table {
width: 100%;
border-collapse: collapse;
}
th,
td {
text-align: left;
padding: 0.3rem 0.5rem;
border-bottom: 1px solid #8884;
}
.fehler {
color: #c62828;
}