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
+21 -2
View File
@@ -21,6 +21,7 @@ There is no database. The CLI's layout is the data model (see the root README.md
- `notes.md` for notes
- `problem.md` for the statement (shown only to the admin, and sent to Claude)
- `explain.md` for a Claude-written explanation
- `reviews/<id>.md` for feedback on a recording of the admin explaining their solution (admin only)
The server keeps a clone of adamf/usaco in `$DATA_DIR/repo` and indexes it into memory.
@@ -31,7 +32,7 @@ The server keeps a clone of adamf/usaco in `$DATA_DIR/repo` and indexes it into
3. commit as `GIT_AUTHOR_NAME`
4. push
The commit subjects match the CLI's: "Solve <name>", "Skip <name>", "Reopen <name>" and "Update <name>". An explanation commits as "Explain <name>". If someone pushed in between and the push is rejected, the edit is replayed once on the new tip. A second rejection returns 409.
The commit subjects match the CLI's: "Solve <name>", "Skip <name>", "Reopen <name>" and "Update <name>". An explanation commits as "Explain <name>", a review as "Review <name>" and its deletion as "Remove review <name>". If someone pushed in between and the push is rejected, the edit is replayed once on the new tip. A second rejection returns 409.
- **Dates come from git, not mtimes.** A problem's solve date is the commit that moved it into `solved/`. Its first and last dates are its first and last commits.
The site commits, so the laptop must pull before pushing. `usaco sync` does `pull --rebase --autostash` and then `push`.
@@ -46,6 +47,9 @@ internal/index/ reads the clone into memory: problems, files, tests, git dat
internal/handlers/ REST API, Gitea webhook, SPA file server
internal/claude/ the Claude client: streamed call, JSON-schema reply, fixed error messages
internal/explain/ the explanation prompt and schema, explain.md rendering, the job tracker
internal/transcribe/ OpenAI-compatible speech-to-text client, and pace/pause/filler metrics
internal/review/ the review prompt and schema, reviews/<id>.md rendering
internal/audiostore/ optional S3 bucket (Garage) that keeps review recordings for playback
internal/statement/ fetches statements from LeetCode (GraphQL) and USACO (the problem page)
web/ Vue 3 + Vite SPA, built for base /usaco/
```
@@ -64,6 +68,10 @@ Everything is served under `BASE_PATH` (`/usaco`). nginx proxies the prefix thro
| `GET /usaco/api/problems/<name>/statement/fetch?url=` | admin | the statement behind `url` (default: the saved link) as markdown, for review; saves nothing. 422 for a judge it can't read |
| `POST /usaco/api/problems/<name>/explain` | admin | `{note?, includeCode?}`: starts an explanation and answers 202; 409 if one is running, 503 without `CLAUDE_API_KEY` |
| `GET /usaco/api/problems/<name>/explain` | admin | the latest job: `{state: idle\|running\|done\|error, error?}` |
| `POST /usaco/api/problems/<name>/review` | admin | multipart `audio` (mp3, m4a, wav, webm, ogg, flac; at most 25 MB), `note?`, `includeCode?`: starts a review and answers 202; 409 if one is running, 413 if too big, 503 without `CLAUDE_API_KEY` or `TRANSCRIBE_API_KEY` |
| `GET /usaco/api/problems/<name>/review` | admin | the latest review job, shaped like the explain one |
| `GET /usaco/api/problems/<name>/reviews/<id>/audio` | admin | the review's recording, with range support; 404 if it was not kept |
| `DELETE /usaco/api/problems/<name>/reviews/<id>` | admin | removes the review and its recording |
| `POST /usaco/api/problems/<name>/status` | admin | `{to: solving\|solved\|skipped}`: moves the directory |
| `POST /usaco/api/hooks/gitea` | HMAC (`X-Gitea-Signature`) | queue a pull |
| `GET /usaco/api/health` | open | 200 once the clone is indexed |
@@ -145,10 +153,21 @@ The Explain panel on a problem page (admin only) asks Claude for an intuitive ex
- **The call.** `CLAUDE_MODEL` (default `claude-opus-5-5`) at high effort, streamed, with the server-side refusal fallback on. It takes a minute or two and costs roughly $0.10 to $0.60. The request only starts a background job, because nginx gives up after 120 seconds; the page polls. Token usage is logged as `[claude]` lines.
- **Statements.** LeetCode and USACO can be fetched. Codeforces sits behind a Cloudflare challenge, and other judges are unknown, so paste those.
## Recording reviews
The "Review my explanation" panel (admin only) takes a recording of the admin explaining a solution out loud, as to an interviewer, and commits feedback on it as `reviews/<id>.md`. The id is the UTC time it started (`2026-10-20-153000`), so each attempt is its own file and the page lists them newest first.
- **Transcription.** Claude cannot take audio, so the recording goes first to an OpenAI-compatible `/v1/audio/transcriptions` endpoint: `TRANSCRIBE_URL` (default the OpenAI API) with `TRANSCRIBE_MODEL` (default `whisper-1`, about $0.006 a minute). It asks for word and segment timestamps, and for a verbatim transcript, because Whisper otherwise drops the fillers. A self-hosted faster-whisper server works by changing the URL.
- **Metrics.** Pace (words per minute), pauses of 2 seconds or more, filler-word counts and when complexity was first mentioned are measured from the timestamps (`transcribe.Metrics`), since Claude never hears the recording. It is told so, and judges delivery from the words and these numbers only, not tone.
- **Review.** The statement, examples, optionally the main solution file, the admin's note, the metrics and the timestamped transcript go to Claude with a JSON schema (`internal/review` `Schema`): a verdict (correct, partly correct, incorrect, incomplete), a restatement, an assessment of the approach and complexities, missed edge cases, delivery feedback quoting `[mm:ss]`, 1 to 5 scores in five areas, strengths and things to work on. The markdown ends with the metrics and the full transcript. Its first line is a `<!-- review verdict=… audio=… -->` comment the index reads.
- **The recording.** It is too big for git. With all five `S3_*` variables set it is kept in that bucket as `<name>/<id>.<ext>` and the page gets a player; otherwise it is thrown away once transcribed. In web_server that is a private Garage bucket, never the public `uploads` one. A recording whose review fails is deleted again.
- **Privacy.** A review is a transcript of the admin talking, so reviews and their count are blanked for everyone else, even on solved problems.
## Things that are easy to get wrong
- **`BASE_PATH` and Vite's `base` must agree.** The SPA's asset URLs and router base are fixed at build time.
- **Edits must decide from disk, not the index.** `repo.Mutate` may run an edit twice, the second time on a newer tip. The handlers re-locate the problem in the clone each time with `findOnDisk`.
- **`problem.md` is the judge's text.** `GET /problems/<name>` blanks it for non-admins, so the public site links to the judge instead of republishing it.
- **An explanation job lives in memory.** A restart mid-job loses it, and nothing is committed. Start it again.
- **An explanation or review job lives in memory.** A restart mid-job loses it, and nothing is committed. Start it again (a review needs the recording uploaded again).
- **Uploads are capped at 25 MB**, the OpenAI API's limit. nginx's server-wide `client_max_body_size 50M` is above it; lowering that below 25M would turn big recordings into nginx 413s.
- **`tests/*.out` used to be gitignored** by the root `*.out` rule. The root `.gitignore` now re-includes `**/tests/*.out`. A test whose expected output is shown as "Not saved." predates that change or never had one.