The problem page's Explain and recording-review forms took most of the first screen, above the solution. They now fold into the admin bar with the editor, one open at a time; a running job is reported in the bar, so a form can be closed while it works. The problem list is grouped by month when sorted by recency, as one card per month with divided rows, laid out on a fixed grid so rows line up on a phone. Empty status tabs are hidden. Rust solutions are now highlighted, the file picker is styled like the other buttons, header links no longer break mid-word on a phone, and keyboard focus is visible. Markdown everywhere now goes through one renderer that typesets $...$, $$...$$ and ```math with KaTeX. The explanation prompt asked for $...$ only when the statement used it, so formulas came out as inline code; it now asks for LaTeX for math and code spans for code, and the review prompt does the same for complexities. Co-Authored-By: Claude Opus 5.5 <[email protected]>
USACO site
The public face of this repo, served at /usaco/ on adam-french.co.uk. It shows the solved problems: each solution, its sample input, saved tests and notes, and its git history, plus a stats page with a solve calendar and a guide to the ./usaco CLI. When the site's admin is logged in, it also shows problems in solving/ and skipped/, and lets them:
- mark a problem solved, skipped or back in progress
- set its link
- save the problem statement (pasted, or fetched from a LeetCode or USACO link)
- write notes
- have Claude write an explanation for a problem they are stuck on
It is one Go binary that serves a REST API and the built Vue SPA. It runs as one container behind the site's nginx and borrows the site's login, the same arrangement as job-tracker (adamf/job-tracker), which it is modelled on.
Git is the store
There is no database. The CLI's layout is the data model (see the root README.md):
solving/,solved/andskipped/<name>/, each holding the solution files<io>.infor the sample inputtests/N.inandN.out.urlfor the problem linknotes.mdfor notesproblem.mdfor the statement (shown only to the admin, and sent to Claude)explain.mdfor a Claude-written explanationreviews/<id>.mdfor 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.
-
Reading. A Gitea push webhook triggers a fetch and hard reset, then a re-index, so a
usaco done && usaco syncis live in seconds. A pull everyPULL_INTERVAL(10m) catches missed hooks. The clone is a cache: the remote always wins. -
Writing. An admin edit runs under one lock:
- sync
- change the files
- commit as
GIT_AUTHOR_NAME - push
The commit subjects match the CLI's: "Solve ", "Skip ", "Reopen " and "Update ". An explanation commits as "Explain ", a review as "Review " and its deletion as "Remove review ". 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.
Layout
cmd/usacosite/ main: reads the environment, wires everything, registers routes
internal/auth/ is this request the admin? (asks the site backend; copied from job-tracker)
internal/repo/ the clone: sync, and edit-commit-push with one replay on rejection
internal/index/ reads the clone into memory: problems, files, tests, git dates
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/
Routes
Everything is served under BASE_PATH (/usaco). nginx proxies the prefix through unchanged.
| Path | Auth | What |
|---|---|---|
/usaco/, /usaco/p/<name>, /usaco/stats, /usaco/cli |
none | SPA |
GET /usaco/api/problems |
open; the admin also gets unsolved problems | the list |
GET /usaco/api/problems/<name> |
open for solved problems; 404 for others unless admin | one problem, with files, tests and history |
GET /usaco/api/me |
open | {admin}, so the SPA knows whether to show the edit controls |
PUT /usaco/api/problems/<name>/meta |
admin | {url?, notes?, statement?}: writes .url, notes.md and problem.md (blank removes the file) |
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 |
Auth works as in job-tracker:
internal/authforwards the browser's cookies to the site backend's/auth/validate-admin.- A "yes" is cached for 30 seconds.
- A refused admin action sends the browser to
/admin/login?redirect=….
Development
make check # go vet + go test, and a vite build
make dev # docker compose up --build: this checkout's problems, no login
Then open http://localhost:8080/usaco/.
make dev. The dev compose clones the repo root, mounted read-only, and sets GIT_PUSH=false. Edits made in the browser become commits in the container's clone and nowhere else. Only committed work shows up.
Hot reload. Run the server with make dev, then run cd web && npm run dev. Vite proxies /usaco/api to localhost:8080.
Without Docker:
go build -o /tmp/usacosite ./cmd/usacosite && (cd web && npx vite build)
DEV_MODE=true AUTH_MODE=dev GIT_PUSH=false GIT_REMOTE_URL=file://$PWD/.. \
DATA_DIR=/tmp/usaco-data STATIC_DIR=$PWD/web/dist /tmp/usacosite
Every variable is listed and explained in .env.example.
Running inside web_server
The site's docker-compose.yml runs the published image as service usaco, with an explicit environment: list. The site's nginx routes /usaco/ to it. ./usaco-data is mounted at /data and holds only the clone, so deleting it is safe: the next start re-clones. The container runs as uid 1000, so run chown 1000 usaco-data on the host.
Deploying
A push to main that touches site/ or .gitea/workflows/ runs .gitea/workflows/ci.yaml at the repo root. It does the following:
- Tests.
- Builds the image from
site/and pushes it asadam-french.co.uk/adamf/usaco:<sha>and:latest. - Rolls the site onto the new image and waits for the healthcheck.
Problem commits don't match the path filter, so they never rebuild the image. The webhook brings them in.
By hand on the host:
cd ~/deploy/web_server && docker compose pull usaco && docker compose up -d --no-deps usaco
To pin a version, set USACO_IMAGE_TAG=<sha> in the site's .env.
One-off setup
The registry setup is shared with job-tracker (see its README, "One-off: registry setup"). The host is already logged in, and the same REGISTRY_USER and REGISTRY_TOKEN work here.
-
CI secrets. In this repo's Settings → Actions → Secrets, add
REGISTRY_USERandREGISTRY_TOKEN. Use the same values as job-tracker. -
A git token for the server. In Gitea, go to Settings → Applications and create a token with repository: read and write. Put it in the site's
.envasUSACO_GIT_TOKEN. -
The data directory. On the host, in
~/deploy/web_server, runmkdir usaco-data && sudo chown 1000:1000 usaco-data. -
A webhook secret. Generate one, for example with
openssl rand -hex 32, and put it in the site's.envasUSACO_WEBHOOK_SECRET. -
Deploy web_server with the
usacoservice and the/usaco/route. Then push this repo, so CI publishes the first image. -
The webhook. In this repo's Settings → Webhooks → Add webhook → Gitea, set:
- Target URL:
http://usaco:8080/usaco/api/hooks/gitea - Method: POST
- Content type: application/json
- Secret: the value of
USACO_WEBHOOK_SECRET - Trigger: push events
Gitea only delivers to Docker-network hosts that are on
[webhook] ALLOWED_HOST_LIST. web_server's compose sets that toexternal,usaco. Use "Test delivery": the response should be202, anddocker logs usacoshould show a new[index]line. - Target URL:
Explanations
The Explain panel on a problem page (admin only) asks Claude for an intuitive explanation and commits it as explain.md.
- Input. The statement (
problem.md; when it is missing, it is fetched from the link and saved too), up to three saved tests with outputs or the sample input, optionally the main solution file, and the admin's "where I'm stuck" note. - Output. A JSON-schema reply (
internal/explainSchema): the key observation, 2 to 4 hints, the approach, a walkthrough whose steps each carry an SVG diagram, complexity, pitfalls and a pseudocode sketch. It is stored as markdown with one##section each, and the page shows every section folded so the reader opens only as much as they need. Diagrams are```svgfences, sanitized with DOMPurify before they are inserted. - The call.
CLAUDE_MODEL(defaultclaude-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/transcriptionsendpoint:TRANSCRIBE_URL(default the OpenAI API) withTRANSCRIBE_MODEL(defaultwhisper-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/reviewSchema): 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 publicuploadsone. 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_PATHand Vite'sbasemust agree. The SPA's asset URLs and router base are fixed at build time.- Edits must decide from disk, not the index.
repo.Mutatemay run an edit twice, the second time on a newer tip. The handlers re-locate the problem in the clone each time withfindOnDisk. problem.mdis 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 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 50Mis above it; lowering that below 25M would turn big recordings into nginx 413s. tests/*.outused to be gitignored by the root*.outrule. The root.gitignorenow re-includes**/tests/*.out. A test whose expected output is shown as "Not saved." predates that change or never had one.