Review recorded explanations of a solution on the site
Test and publish the site / test (push) Successful in 2m4s
Test and publish the site / publish (push) Successful in 1m44s

The admin can upload a recording of themselves explaining a problem's
solution out loud (mp3, m4a, wav, webm, ogg or flac, up to 25 MB) and
get interview-style feedback, committed as reviews/<id>.md so every
attempt is kept.

Claude can't take audio, so the recording is transcribed first by an
OpenAI-compatible endpoint (whisper-1 by default; TRANSCRIBE_API_KEY,
with TRANSCRIBE_URL for a self-hosted server). Pace, pauses, filler
words and when complexity first comes up are measured from the word
timestamps and given to Claude with the timestamped transcript, the
statement and optionally the code. The reply covers the verdict, scores
in five areas, the approach and its complexity, missed edge cases,
delivery and what to work on.

Recordings are kept for playback in an S3 bucket (Garage) when the
S3_* settings are given, and are thrown away otherwise. Reviews are
admin-only. The job runs in the background like Explain, and the
statement fetch and save-error handling are now shared between the two.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-20 01:56:55 +01:00
co-authored by Claude Opus 5.5
parent 33027429c5
commit 63608f130c
25 changed files with 2381 additions and 54 deletions
+15 -3
View File
@@ -1,5 +1,6 @@
/**
* The server's REST API (internal/handlers). Every call goes through
* The server's REST API (internal/handlers). Every call but the audio
* player's goes through
* request(), which turns an error response into a thrown Error carrying the
* server's message, and sends a refused admin action to the site's login.
*/
@@ -15,12 +16,14 @@ export class ApiError extends Error {
}
}
// A FormData body is sent as multipart, with the boundary the browser picks.
async function request(method, path, body) {
const form = body instanceof FormData;
const res = await fetch(BASE + path, {
method,
credentials: "same-origin",
headers: body === undefined ? {} : { "Content-Type": "application/json" },
body: body === undefined ? undefined : JSON.stringify(body),
headers: body === undefined || form ? {} : { "Content-Type": "application/json" },
body: body === undefined || form ? body : JSON.stringify(body),
});
const data = await res.json().catch(() => ({}));
if (!res.ok) {
@@ -39,3 +42,12 @@ export const fetchStatement = (name, url) =>
request("GET", `/problems/${encodeURIComponent(name)}/statement/fetch?url=${encodeURIComponent(url || "")}`);
export const startExplain = (name, body) => request("POST", `/problems/${encodeURIComponent(name)}/explain`, body);
export const explainStatus = (name) => request("GET", `/problems/${encodeURIComponent(name)}/explain`);
// form: FormData with audio (the file), note and includeCode ("true").
export const startReview = (name, form) => request("POST", `/problems/${encodeURIComponent(name)}/review`, form);
export const reviewStatus = (name) => request("GET", `/problems/${encodeURIComponent(name)}/review`);
export const deleteReview = (name, id) =>
request("DELETE", `/problems/${encodeURIComponent(name)}/reviews/${encodeURIComponent(id)}`);
// For an <audio> src: the browser fetches it, with ranges for seeking.
export const reviewAudioUrl = (name, id) =>
`${BASE}/problems/${encodeURIComponent(name)}/reviews/${encodeURIComponent(id)}/audio`;
+7 -3
View File
@@ -3,7 +3,8 @@
* explain.md, laid out as the ladder it was written to be: every "## "
* section folded away so the reader opens only as much as they need (the
* observation, then one hint at a time, ...). The line above the first
* section (who wrote it, when) stays visible.
* section (who wrote it, when) stays visible. Reviews use it too, with the
* sections worth reading at once named in open.
*
* Markdown is rendered with html: false like the notes. The one exception
* is ```svg fences, the walkthrough's diagrams: they are inserted as SVG
@@ -15,7 +16,10 @@ import { computed } from "vue";
import MarkdownIt from "markdown-it";
import DOMPurify from "dompurify";
const props = defineProps({ source: { type: String, required: true } });
const props = defineProps({
source: { type: String, required: true },
open: { type: Array, default: () => [] },
});
const md = new MarkdownIt({ html: false, linkify: true });
const fence = md.renderer.rules.fence;
@@ -49,7 +53,7 @@ const parts = computed(() => {
<template>
<div class="explanation">
<div v-if="parts.intro.trim()" class="intro muted prose" v-html="parts.intro"></div>
<details v-for="(s, i) in parts.sections" :key="i + s.title" class="step card">
<details v-for="(s, i) in parts.sections" :key="i + s.title" class="step card" :open="open.includes(s.title)">
<summary>{{ s.title }}</summary>
<div class="body prose" v-html="s.html"></div>
</details>
+139
View File
@@ -0,0 +1,139 @@
<script setup>
/**
* The problem's recording reviews (reviews/<id>.md), newest first and open,
* the rest folded to a date and verdict so progress reads down the list.
* Each is laid out by Explanation with its verdict, scores and to-do list
* open, and gets a player when its recording was kept. Admin-only, like the
* reviews themselves.
*/
import { ref } from "vue";
import Explanation from "@/components/Explanation.vue";
import { deleteReview, reviewAudioUrl } from "@/api";
const props = defineProps({
name: { type: String, required: true },
reviews: { type: Array, required: true },
});
const emit = defineEmits(["changed"]);
const VERDICTS = {
correct: "Correct",
partially_correct: "Partly correct",
incorrect: "Incorrect",
incomplete: "Incomplete",
};
const OPEN = ["Verdict", "Scores", "To work on"];
// The id is the UTC time the review was started: 2026-10-20-153000.
function when(id) {
const m = /^(\d{4})-(\d{2})-(\d{2})-(\d{2})(\d{2})(\d{2})$/.exec(id);
if (!m) return id;
const d = new Date(Date.UTC(+m[1], m[2] - 1, +m[3], +m[4], +m[5], +m[6]));
return d.toLocaleString(undefined, { day: "numeric", month: "short", year: "numeric", hour: "2-digit", minute: "2-digit" });
}
const busy = ref("");
const error = ref("");
async function remove(id) {
if (!confirm(`Delete the review from ${when(id)}? Its recording goes too.`)) return;
busy.value = id;
error.value = "";
try {
emit("changed", await deleteReview(props.name, id));
} catch (e) {
error.value = e.message;
} finally {
busy.value = "";
}
}
</script>
<template>
<div class="reviews">
<p v-if="error" class="error">{{ error }}</p>
<details v-for="(r, i) in reviews" :key="r.id" class="review card" :open="i === 0">
<summary>
<span>{{ when(r.id) }}</span>
<span v-if="r.verdict" class="badge" :class="'v-' + r.verdict">{{ VERDICTS[r.verdict] || r.verdict }}</span>
</summary>
<div class="body">
<audio v-if="r.hasAudio" controls preload="none" :src="reviewAudioUrl(name, r.id)"></audio>
<Explanation :source="r.content" :open="OPEN" />
<div class="actions">
<button class="btn small" :disabled="busy === r.id" @click="remove(r.id)">
{{ busy === r.id ? "Deleting…" : "Delete review" }}
</button>
</div>
</div>
</details>
</div>
</template>
<style scoped>
.reviews {
display: grid;
gap: 8px;
min-width: 0;
}
.review > summary {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px 12px;
padding: 8px 14px;
cursor: pointer;
font-weight: bold;
}
.review[open] > summary {
border-bottom: 1px solid var(--color-line-soft);
}
.body {
display: grid;
gap: 10px;
padding: 12px 14px 14px;
min-width: 0;
}
audio {
width: 100%;
}
.v-correct {
color: var(--color-solved);
}
.v-partially_correct {
color: var(--color-solving);
}
.v-incorrect {
color: var(--color-ink-danger);
}
.v-incomplete {
color: var(--color-skipped);
}
.actions {
display: flex;
justify-content: flex-end;
}
.btn.small {
padding: 2px 10px;
font-size: 0.8rem;
}
/* The Scores table. The prose styles have none: no other markdown here
has one. It scrolls inside its card rather than widening the page. */
.body :deep(table) {
display: block;
overflow-x: auto;
border-collapse: collapse;
font-size: 0.9rem;
}
.body :deep(th),
.body :deep(td) {
padding: 4px 10px;
border-bottom: 1px solid var(--color-line-soft);
text-align: left;
vertical-align: top;
}
.body :deep(td:nth-child(2)) {
white-space: nowrap;
font-family: var(--font-mono);
}
</style>
+1
View File
@@ -108,6 +108,7 @@ const shown = computed(() => {
<template v-if="p.langs.length">{{ p.langs.map((l) => LANG_LABELS[l] || l).join(", ") }}</template>
<template v-if="p.tests"> · {{ p.tests }} test{{ p.tests === 1 ? "" : "s" }}</template>
<template v-if="p.hasNotes"> · notes</template>
<template v-if="p.reviewCount"> · {{ p.reviewCount }} review{{ p.reviewCount === 1 ? "" : "s" }}</template>
</span>
</div>
<div class="side">
+120 -6
View File
@@ -2,17 +2,29 @@
/**
* One problem: its solution files, sample input, saved tests, notes,
* explanation and git history. The admin also gets the status buttons, the
* link/statement/notes editor and the Explain panel; each edit is a commit
* the server pushes, and the response is the problem as it is afterwards, so
* the page just takes it. An explanation takes minutes, so starting one only
* queues it and the page polls until it is committed.
* link/statement/notes editor, the Explain panel and recording reviews; each
* edit is a commit the server pushes, and the response is the problem as it
* is afterwards, so the page just takes it. An explanation or a review takes
* minutes, so starting one only queues it and the page polls until it is
* committed.
*/
import { computed, onUnmounted, ref, watch } from "vue";
import { RouterLink } from "vue-router";
import MarkdownIt from "markdown-it";
import CodeBlock from "@/components/CodeBlock.vue";
import Explanation from "@/components/Explanation.vue";
import { explainStatus, fetchStatement, getMe, getProblem, setStatus, startExplain, updateMeta } from "@/api";
import ReviewList from "@/components/ReviewList.vue";
import {
explainStatus,
fetchStatement,
getMe,
getProblem,
reviewStatus,
setStatus,
startExplain,
startReview,
updateMeta,
} from "@/api";
import { LANG_LABELS, STATUS_LABELS, formatDate, title } from "@/format";
const props = defineProps({ name: { type: String, required: true } });
@@ -34,7 +46,10 @@ async function load() {
const [p, me] = await Promise.all([getProblem(props.name), getMe().catch(() => ({ admin: false }))]);
problem.value = p;
admin.value = me.admin;
if (me.admin) checkExplain();
if (me.admin) {
checkExplain();
checkReview();
}
} catch (e) {
problem.value = null;
error.value = e.status === 404 ? "No such problem." : e.message;
@@ -141,6 +156,77 @@ async function explain() {
const canExplain = computed(() => !!(problem.value?.statement || problem.value?.url));
// ---- recording reviews ----
// The same shape as explanations, with its own job and timer: both can run
// at once.
const recording = ref(null);
const recordingInput = ref(null);
const reviewNote = ref("");
const reviewCode = ref(true);
const reviewJob = ref({ state: "idle" });
let reviewPoll = null;
function stopReviewPolling() {
clearTimeout(reviewPoll);
reviewPoll = null;
}
onUnmounted(stopReviewPolling);
watch(() => props.name, stopReviewPolling);
// 25 MB is the transcriber's limit; checking here saves uploading it first.
const MAX_RECORDING = 25 << 20;
function pickRecording(e) {
recording.value = e.target.files[0] || null;
if (recording.value && recording.value.size > MAX_RECORDING) {
reviewJob.value = { state: "error", error: "That recording is over 25 MB; export it at a lower bitrate." };
} else if (reviewJob.value.state === "error") {
reviewJob.value = { state: "idle" };
}
}
async function checkReview() {
stopReviewPolling();
const name = props.name;
try {
const s = await reviewStatus(name);
if (name !== props.name) return;
const finished = reviewJob.value.state === "running" && s.state === "done";
reviewJob.value = s;
if (s.state === "running") {
reviewPoll = setTimeout(checkReview, 3000);
} else if (finished) {
problem.value = await getProblem(name);
}
} catch (e) {
reviewJob.value = { state: "error", error: e.message };
}
}
async function submitReview() {
const form = new FormData();
form.append("audio", recording.value);
form.append("note", reviewNote.value);
form.append("includeCode", String(reviewCode.value));
reviewJob.value = { state: "uploading" };
try {
reviewJob.value = await startReview(props.name, form);
recording.value = null;
if (recordingInput.value) recordingInput.value.value = "";
reviewPoll = setTimeout(checkReview, 3000);
} catch (e) {
reviewJob.value = { state: "error", error: e.message };
}
}
const canReview = computed(
() =>
canExplain.value &&
!!recording.value &&
recording.value.size <= MAX_RECORDING &&
!["uploading", "running"].includes(reviewJob.value.state),
);
const moves = computed(() => {
const s = problem.value?.status;
return [
@@ -226,6 +312,25 @@ const moves = computed(() => {
<p v-if="job.state === 'error'" class="error">{{ job.error }}</p>
</section>
<section v-if="admin" class="stuck card">
<h2>Review my explanation</h2>
<p class="muted">
Record yourself explaining your solution as you would to an interviewer, then upload it (mp3, m4a, wav,
webm, ogg or flac, up to 25 MB). It is transcribed, and Claude gives feedback on the approach and on your
delivery. Each review is committed under <code>reviews/</code>.
</p>
<input ref="recordingInput" type="file" accept="audio/*,.mp3,.m4a,.wav,.webm,.ogg,.flac" @change="pickRecording" />
<textarea v-model="reviewNote" rows="2" placeholder="Optional context: a mock interview, a time limit, what to focus on"></textarea>
<div class="admin-row">
<label class="check"><input v-model="reviewCode" type="checkbox" /> Include my code</label>
<button class="btn primary" :disabled="!canReview" @click="submitReview">Review</button>
<span v-if="reviewJob.state === 'uploading'" class="muted">Uploading…</span>
<span v-else-if="reviewJob.state === 'running'" class="muted">Transcribing and reviewing… this takes a minute or two.</span>
<span v-else-if="!canExplain" class="muted">Add a link or the statement first.</span>
</div>
<p v-if="reviewJob.state === 'error'" class="error">{{ reviewJob.error }}</p>
</section>
<section v-if="notesHtml" class="notes card prose" v-html="notesHtml"></section>
<section v-if="problem.explanation">
@@ -233,6 +338,11 @@ const moves = computed(() => {
<Explanation :source="problem.explanation" />
</section>
<section v-if="admin && problem.reviews.length">
<h2>Reviews</h2>
<ReviewList :name="problem.name" :reviews="problem.reviews" @changed="(p) => (problem = p)" />
</section>
<details v-if="admin && statementHtml" class="statement card">
<summary>Problem statement</summary>
<div class="prose" v-html="statementHtml"></div>
@@ -403,6 +513,10 @@ h2 {
color: var(--color-ink);
background: var(--color-paper);
}
.stuck input[type="file"] {
font-size: 0.9rem;
max-width: 100%;
}
.check {
display: flex;
align-items: center;