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]>
588 lines
17 KiB
Vue
588 lines
17 KiB
Vue
<script setup>
|
|
/**
|
|
* 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, 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 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 } });
|
|
|
|
// html: false — notes are rendered as markdown only, never as raw HTML.
|
|
const md = new MarkdownIt({ html: false, linkify: true });
|
|
|
|
const problem = ref(null);
|
|
const admin = ref(false);
|
|
const loading = ref(true);
|
|
const error = ref("");
|
|
const activeFile = ref(0);
|
|
|
|
async function load() {
|
|
loading.value = true;
|
|
error.value = "";
|
|
activeFile.value = 0;
|
|
try {
|
|
const [p, me] = await Promise.all([getProblem(props.name), getMe().catch(() => ({ admin: false }))]);
|
|
problem.value = p;
|
|
admin.value = me.admin;
|
|
if (me.admin) {
|
|
checkExplain();
|
|
checkReview();
|
|
}
|
|
} catch (e) {
|
|
problem.value = null;
|
|
error.value = e.status === 404 ? "No such problem." : e.message;
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
watch(() => props.name, load, { immediate: true });
|
|
|
|
const notesHtml = computed(() => (problem.value?.notes ? md.render(problem.value.notes) : ""));
|
|
const statementHtml = computed(() => (problem.value?.statement ? md.render(problem.value.statement) : ""));
|
|
const file = computed(() => problem.value?.files[activeFile.value]);
|
|
|
|
// ---- admin edits ----
|
|
const saving = ref(false);
|
|
const editError = ref("");
|
|
const editing = ref(false);
|
|
const draftUrl = ref("");
|
|
const draftNotes = ref("");
|
|
const draftStatement = ref("");
|
|
const fetching = ref(false);
|
|
|
|
function startEdit() {
|
|
draftUrl.value = problem.value.url || "";
|
|
draftNotes.value = problem.value.notes || "";
|
|
draftStatement.value = problem.value.statement || "";
|
|
editError.value = "";
|
|
editing.value = true;
|
|
}
|
|
|
|
async function run(action) {
|
|
saving.value = true;
|
|
editError.value = "";
|
|
try {
|
|
problem.value = await action();
|
|
return true;
|
|
} catch (e) {
|
|
editError.value = e.message;
|
|
return false;
|
|
} finally {
|
|
saving.value = false;
|
|
}
|
|
}
|
|
|
|
async function saveMeta() {
|
|
const meta = { url: draftUrl.value, notes: draftNotes.value, statement: draftStatement.value };
|
|
if (await run(() => updateMeta(props.name, meta))) {
|
|
editing.value = false;
|
|
}
|
|
}
|
|
|
|
// Fills the statement box for review; nothing is saved until Save.
|
|
async function fillStatement() {
|
|
fetching.value = true;
|
|
editError.value = "";
|
|
try {
|
|
draftStatement.value = (await fetchStatement(props.name, draftUrl.value)).statement;
|
|
} catch (e) {
|
|
editError.value = e.message;
|
|
} finally {
|
|
fetching.value = false;
|
|
}
|
|
}
|
|
|
|
// ---- explanations ----
|
|
const stuckNote = ref("");
|
|
const includeCode = ref(true);
|
|
const job = ref({ state: "idle" });
|
|
let poll = null;
|
|
|
|
function stopPolling() {
|
|
clearTimeout(poll);
|
|
poll = null;
|
|
}
|
|
onUnmounted(stopPolling);
|
|
watch(() => props.name, stopPolling);
|
|
|
|
async function checkExplain() {
|
|
stopPolling();
|
|
const name = props.name;
|
|
try {
|
|
const s = await explainStatus(name);
|
|
if (name !== props.name) return;
|
|
const finished = job.value.state === "running" && s.state === "done";
|
|
job.value = s;
|
|
if (s.state === "running") {
|
|
poll = setTimeout(checkExplain, 3000);
|
|
} else if (finished) {
|
|
problem.value = await getProblem(name);
|
|
}
|
|
} catch (e) {
|
|
job.value = { state: "error", error: e.message };
|
|
}
|
|
}
|
|
|
|
async function explain() {
|
|
try {
|
|
job.value = await startExplain(props.name, { note: stuckNote.value, includeCode: includeCode.value });
|
|
poll = setTimeout(checkExplain, 3000);
|
|
} catch (e) {
|
|
job.value = { state: "error", error: e.message };
|
|
}
|
|
}
|
|
|
|
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 [
|
|
{ to: "solved", label: "Mark solved" },
|
|
{ to: "skipped", label: "Skip" },
|
|
{ to: "solving", label: "Reopen" },
|
|
].filter((m) => m.to !== s);
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<p v-if="loading" class="muted">Loading…</p>
|
|
<div v-else-if="error">
|
|
<p class="error">{{ error }}</p>
|
|
<RouterLink to="/">Back to the list</RouterLink>
|
|
</div>
|
|
|
|
<article v-else-if="problem" class="page">
|
|
<header class="head">
|
|
<RouterLink to="/" class="back">← All problems</RouterLink>
|
|
<h1>{{ title(problem.name) }}</h1>
|
|
<div class="facts">
|
|
<span class="badge" :class="problem.status">{{ STATUS_LABELS[problem.status] }}</span>
|
|
<a v-if="problem.url" :href="problem.url" target="_blank" rel="noopener noreferrer">
|
|
{{ problem.source || "Problem statement" }} ↗
|
|
</a>
|
|
<span v-if="problem.solvedAt" class="muted">Solved {{ formatDate(problem.solvedAt) }}</span>
|
|
<span v-else-if="problem.firstSeen" class="muted">Started {{ formatDate(problem.firstSeen) }}</span>
|
|
<span v-if="problem.io" class="muted">File I/O: <code>{{ problem.io }}.in</code></span>
|
|
</div>
|
|
</header>
|
|
|
|
<section v-if="admin" class="admin card">
|
|
<div class="admin-row">
|
|
<span class="muted">Admin</span>
|
|
<button v-for="m in moves" :key="m.to" class="btn" :disabled="saving" @click="run(() => setStatus(problem.name, m.to))">
|
|
{{ m.label }}
|
|
</button>
|
|
<button v-if="!editing" class="btn" :disabled="saving" @click="startEdit">Edit link, statement and notes</button>
|
|
<span v-if="saving" class="muted">Saving to git…</span>
|
|
</div>
|
|
<form v-if="editing" class="editor" @submit.prevent="saveMeta">
|
|
<label>
|
|
Problem link
|
|
<input v-model="draftUrl" type="url" placeholder="https://usaco.org/index.php?page=viewproblem2&cpid=…" />
|
|
</label>
|
|
<label>
|
|
<span class="label-row">
|
|
Problem statement (markdown, shown only to you and Claude)
|
|
<button class="btn small" type="button" :disabled="fetching || !draftUrl" @click="fillStatement">
|
|
{{ fetching ? "Fetching…" : "Fetch from link" }}
|
|
</button>
|
|
</span>
|
|
<textarea v-model="draftStatement" rows="8" placeholder="Paste the statement, or fetch it from a LeetCode or USACO link"></textarea>
|
|
</label>
|
|
<label>
|
|
Notes (markdown)
|
|
<textarea v-model="draftNotes" rows="8" placeholder="Approach, complexity, what tripped you up…"></textarea>
|
|
</label>
|
|
<div class="admin-row">
|
|
<button class="btn primary" type="submit" :disabled="saving">Save</button>
|
|
<button class="btn" type="button" :disabled="saving" @click="editing = false">Cancel</button>
|
|
</div>
|
|
</form>
|
|
<p v-if="editError" class="error">{{ editError }}</p>
|
|
</section>
|
|
|
|
<section v-if="admin" class="stuck card">
|
|
<h2>Stuck?</h2>
|
|
<p class="muted">
|
|
Claude writes an intuitive explanation with diagrams, laid out as hints you open one at a time. It takes a
|
|
minute or two and is committed as <code>explain.md</code>.
|
|
</p>
|
|
<textarea v-model="stuckNote" rows="3" placeholder="Optional: what you've tried and where you're stuck"></textarea>
|
|
<div class="admin-row">
|
|
<label class="check"><input v-model="includeCode" type="checkbox" /> Include my current code</label>
|
|
<button class="btn primary" :disabled="job.state === 'running' || !canExplain" @click="explain">
|
|
{{ problem.explanation ? "Explain again" : "Explain" }}
|
|
</button>
|
|
<span v-if="job.state === 'running'" class="muted">Claude is writing it…</span>
|
|
<span v-else-if="!canExplain" class="muted">Add a link or the statement first.</span>
|
|
</div>
|
|
<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">
|
|
<h2>Explanation</h2>
|
|
<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>
|
|
</details>
|
|
|
|
<section>
|
|
<h2>Solution</h2>
|
|
<p v-if="!problem.files.length" class="muted">No solution file yet.</p>
|
|
<template v-else>
|
|
<div v-if="problem.files.length > 1" class="file-tabs" role="tablist">
|
|
<button
|
|
v-for="(f, i) in problem.files"
|
|
:key="f.name"
|
|
role="tab"
|
|
:aria-selected="i === activeFile"
|
|
:class="{ on: i === activeFile }"
|
|
@click="activeFile = i"
|
|
>
|
|
{{ f.name }} <span class="muted">{{ LANG_LABELS[f.lang] || f.lang }}</span>
|
|
</button>
|
|
</div>
|
|
<p v-else class="filename muted">{{ file.name }}</p>
|
|
<CodeBlock :key="file.name" :content="file.content" :lang="file.lang" :truncated="file.truncated" />
|
|
</template>
|
|
</section>
|
|
|
|
<section v-if="problem.sample">
|
|
<h2>Sample input</h2>
|
|
<p class="filename muted">{{ problem.sample.name }}</p>
|
|
<CodeBlock :content="problem.sample.content" :truncated="problem.sample.truncated" />
|
|
</section>
|
|
|
|
<section v-if="problem.testCases.length">
|
|
<h2>Tests</h2>
|
|
<details v-for="t in problem.testCases" :key="t.name" class="test card">
|
|
<summary>Test {{ t.name }}</summary>
|
|
<div class="io">
|
|
<div>
|
|
<p class="filename muted">Input</p>
|
|
<CodeBlock :content="t.input.content" :truncated="t.input.truncated" />
|
|
</div>
|
|
<div>
|
|
<p class="filename muted">Expected output</p>
|
|
<CodeBlock v-if="t.output" :content="t.output.content" :truncated="t.output.truncated" />
|
|
<p v-else class="muted">Not saved.</p>
|
|
</div>
|
|
</div>
|
|
</details>
|
|
</section>
|
|
|
|
<section v-if="problem.history.length">
|
|
<h2>History</h2>
|
|
<ol class="history">
|
|
<li v-for="c in problem.history" :key="c.hash">
|
|
<time :datetime="c.date" class="muted">{{ formatDate(c.date) }}</time>
|
|
<span>{{ c.subject }}</span>
|
|
<code class="muted">{{ c.hash.slice(0, 7) }}</code>
|
|
</li>
|
|
</ol>
|
|
</section>
|
|
</article>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.page {
|
|
display: grid;
|
|
gap: 28px;
|
|
min-width: 0;
|
|
}
|
|
.page > section {
|
|
min-width: 0;
|
|
}
|
|
.back {
|
|
font-size: 0.875rem;
|
|
color: var(--color-ink-muted);
|
|
text-decoration: none;
|
|
}
|
|
.back:hover {
|
|
color: var(--color-ink);
|
|
}
|
|
h1 {
|
|
font-size: 2.75rem;
|
|
margin: 6px 0 10px;
|
|
overflow-wrap: anywhere;
|
|
}
|
|
h2 {
|
|
font-size: 1.6rem;
|
|
margin-bottom: 8px;
|
|
}
|
|
.facts {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
align-items: center;
|
|
gap: 6px 16px;
|
|
font-size: 0.9rem;
|
|
}
|
|
.facts code,
|
|
.history code {
|
|
font-family: var(--font-mono);
|
|
font-size: 0.85em;
|
|
}
|
|
.admin {
|
|
padding: 12px 16px;
|
|
display: grid;
|
|
gap: 12px;
|
|
}
|
|
.admin-row {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
.editor {
|
|
display: grid;
|
|
gap: 12px;
|
|
}
|
|
.editor label {
|
|
display: grid;
|
|
gap: 4px;
|
|
font-size: 0.875rem;
|
|
color: var(--color-ink-muted);
|
|
}
|
|
.editor input,
|
|
.editor textarea {
|
|
padding: 8px 10px;
|
|
border: 1px solid var(--color-line);
|
|
border-radius: 4px;
|
|
font-family: var(--font-mono);
|
|
font-size: 0.85rem;
|
|
color: var(--color-ink);
|
|
background: var(--color-paper);
|
|
}
|
|
.notes {
|
|
padding: 16px 20px;
|
|
}
|
|
.label-row {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
gap: 8px;
|
|
}
|
|
.btn.small {
|
|
padding: 2px 10px;
|
|
font-size: 0.8rem;
|
|
}
|
|
.stuck {
|
|
padding: 12px 16px 16px;
|
|
display: grid;
|
|
gap: 10px;
|
|
}
|
|
.stuck h2 {
|
|
margin: 0;
|
|
}
|
|
.stuck p {
|
|
margin: 0;
|
|
font-size: 0.9rem;
|
|
}
|
|
.stuck code {
|
|
font-family: var(--font-mono);
|
|
font-size: 0.85em;
|
|
}
|
|
.stuck textarea {
|
|
padding: 8px 10px;
|
|
border: 1px solid var(--color-line);
|
|
border-radius: 4px;
|
|
font-size: 0.9rem;
|
|
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;
|
|
gap: 6px;
|
|
font-size: 0.9rem;
|
|
}
|
|
.statement summary {
|
|
padding: 8px 14px;
|
|
cursor: pointer;
|
|
}
|
|
.statement .prose {
|
|
padding: 4px 20px 16px;
|
|
overflow-wrap: anywhere;
|
|
}
|
|
.file-tabs {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 4px;
|
|
margin-bottom: 8px;
|
|
}
|
|
.file-tabs button {
|
|
padding: 4px 12px;
|
|
border: 1px solid var(--color-line-soft);
|
|
border-radius: 4px;
|
|
font-family: var(--font-mono);
|
|
font-size: 0.8rem;
|
|
cursor: pointer;
|
|
}
|
|
.file-tabs button.on {
|
|
border-color: var(--color-ink);
|
|
background: var(--color-paper);
|
|
}
|
|
.filename {
|
|
font-family: var(--font-mono);
|
|
font-size: 0.8rem;
|
|
margin-bottom: 4px;
|
|
}
|
|
.test {
|
|
margin-bottom: 8px;
|
|
}
|
|
.test summary {
|
|
padding: 8px 14px;
|
|
cursor: pointer;
|
|
}
|
|
.io {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
|
|
gap: 12px;
|
|
padding: 0 14px 14px;
|
|
min-width: 0;
|
|
}
|
|
.io > div {
|
|
min-width: 0;
|
|
}
|
|
.history {
|
|
display: grid;
|
|
gap: 4px;
|
|
font-size: 0.9rem;
|
|
}
|
|
.history li {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 4px 12px;
|
|
}
|
|
.history time {
|
|
min-width: 7.5em;
|
|
}
|
|
</style>
|