Review recorded explanations of a solution on the site
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:
@@ -4,8 +4,9 @@
|
||||
// The layout is the CLI's (README.md at the repo root): solving/, solved/
|
||||
// and skipped/<name>/, each with a solution (main.cpp, sol.py...), an <io>.in
|
||||
// the CLI wires up, tests/N.in + N.out, and optionally a .url, notes.md,
|
||||
// problem.md (the statement, pasted or fetched from the judge by the site)
|
||||
// and explain.md (an explanation the site had Claude write). The repo is
|
||||
// problem.md (the statement, pasted or fetched from the judge by the site),
|
||||
// explain.md (an explanation the site had Claude write) and reviews/<id>.md
|
||||
// (feedback on a recording of the admin explaining it). The repo is
|
||||
// small, so everything, file contents included, is read on each rebuild,
|
||||
// and a rebuild only happens when the clone changes.
|
||||
package index
|
||||
@@ -19,6 +20,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -71,6 +73,7 @@ type Summary struct {
|
||||
Tests int `json:"tests"`
|
||||
HasNotes bool `json:"hasNotes"`
|
||||
HasExplanation bool `json:"hasExplanation"`
|
||||
ReviewCount int `json:"reviewCount"`
|
||||
FirstSeen *time.Time `json:"firstSeen,omitempty"`
|
||||
SolvedAt *time.Time `json:"solvedAt,omitempty"`
|
||||
LastTouched *time.Time `json:"lastTouched,omitempty"`
|
||||
@@ -83,12 +86,28 @@ type Problem struct {
|
||||
Notes string `json:"notes"`
|
||||
// Statement is the judge's text, so the handlers send it to the admin
|
||||
// only: the site should not republish it.
|
||||
Statement string `json:"statement,omitempty"`
|
||||
Explanation string `json:"explanation"`
|
||||
Files []File `json:"files"`
|
||||
Sample *File `json:"sample,omitempty"`
|
||||
TestSet []Test `json:"testCases"`
|
||||
History []Commit `json:"history"`
|
||||
Statement string `json:"statement,omitempty"`
|
||||
Explanation string `json:"explanation"`
|
||||
// Reviews are newest first, and admin-only like Statement: they are a
|
||||
// transcript of the admin talking.
|
||||
Reviews []Review `json:"reviews"`
|
||||
Files []File `json:"files"`
|
||||
Sample *File `json:"sample,omitempty"`
|
||||
TestSet []Test `json:"testCases"`
|
||||
History []Commit `json:"history"`
|
||||
}
|
||||
|
||||
// Review is one reviews/<id>.md. The site writes the id as the UTC time of
|
||||
// the recording, so ids sort by age.
|
||||
type Review struct {
|
||||
ID string `json:"id"`
|
||||
Verdict string `json:"verdict,omitempty"`
|
||||
// Audio is the recording's key in the audio store; the page only needs
|
||||
// to know there is one.
|
||||
Audio string `json:"-"`
|
||||
HasAudio bool `json:"hasAudio"`
|
||||
// Content is the markdown without its header comment.
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
// Index is one snapshot of the clone.
|
||||
@@ -145,7 +164,7 @@ var langs = map[string]string{
|
||||
}
|
||||
|
||||
func readProblem(pdir, status string) (*Problem, error) {
|
||||
p := &Problem{Summary: Summary{Name: filepath.Base(pdir), Status: status, Langs: []string{}}, Files: []File{}, TestSet: []Test{}, History: []Commit{}}
|
||||
p := &Problem{Summary: Summary{Name: filepath.Base(pdir), Status: status, Langs: []string{}}, Reviews: []Review{}, Files: []File{}, TestSet: []Test{}, History: []Commit{}}
|
||||
|
||||
entries, err := os.ReadDir(pdir)
|
||||
if err != nil {
|
||||
@@ -208,6 +227,10 @@ func readProblem(pdir, status string) (*Problem, error) {
|
||||
}
|
||||
p.TestSet = tests
|
||||
p.Tests = len(tests)
|
||||
if p.Reviews, err = readReviews(filepath.Join(pdir, "reviews")); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p.ReviewCount = len(p.Reviews)
|
||||
p.HasNotes = strings.TrimSpace(p.Notes) != ""
|
||||
p.HasExplanation = strings.TrimSpace(p.Explanation) != ""
|
||||
p.Source = Source(p.URL)
|
||||
@@ -251,6 +274,38 @@ func readTests(tdir string) ([]Test, error) {
|
||||
return tests, nil
|
||||
}
|
||||
|
||||
// reviewHead is the comment internal/review writes as a review's first line.
|
||||
var reviewHead = regexp.MustCompile(`^<!-- review verdict=(\S+)(?: audio=(\S+))? -->\r?\n`)
|
||||
|
||||
func readReviews(rdir string) ([]Review, error) {
|
||||
entries, err := os.ReadDir(rdir)
|
||||
if os.IsNotExist(err) {
|
||||
return []Review{}, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := []Review{}
|
||||
for _, e := range entries {
|
||||
id, ok := strings.CutSuffix(e.Name(), ".md")
|
||||
if !ok || e.IsDir() {
|
||||
continue
|
||||
}
|
||||
f, err := readFile(filepath.Join(rdir, e.Name()), "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r := Review{ID: id, Content: f.Content}
|
||||
if m := reviewHead.FindStringSubmatch(f.Content); m != nil {
|
||||
r.Verdict, r.Audio, r.HasAudio = m[1], m[2], m[2] != ""
|
||||
r.Content = f.Content[len(m[0]):]
|
||||
}
|
||||
out = append(out, r)
|
||||
}
|
||||
sort.Slice(out, func(i, j int) bool { return out[i].ID > out[j].ID })
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func readFile(path, lang string) (File, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user