The editor's completion popup was on but empty for C++, since @codemirror/lang-cpp has no completion source. web/src/completions.js adds one: keywords, the STL, every name in the file (the template's macros show their expansion, typedefs what they alias), members after . and ->, and snippets for the loops and lambdas typed over and over. Python gains the contest standard library and members after ., on top of lang-python's builtins and local names. Nothing knows types, so members are the common ones plus those already used in the file. Evaluate (POST/GET /problems/<name>/evaluate) has Claude judge the editor's code as a strong competitive programmer would before submitting. It runs the saved tests on the runner first, as Submit does, and gives Claude the verdicts and up to three failing cases. The reply is a verdict, correctness, complexity against the constraints, line-anchored issues and a traced counterexample (internal/evaluate). The page shows it in an Evaluation tab of the results panel, marks the issues in the editor beside the lint's for as long as their lines are unchanged, and can load the counterexample as the custom input. It is a background job the page polls, like explanations, but it commits nothing: the code is a draft. explain.Jobs.StartWith keeps a finished job's answer in memory until the next one or a restart. Co-Authored-By: Claude Opus 5.5 <[email protected]>
3.3 KiB
CLAUDE.md
Guidance for Claude Code in site/. README.md has the full picture (routes, git sync, deployment).
Commands
make check # go vet ./... && go test ./..., then a vite build of web/ into a temp dir
make dev # docker compose up --build: this checkout's problems, AUTH_MODE=dev, GIT_PUSH=false
cd web && npm run dev # SPA hot reload; proxies /usaco/api to localhost:8080
Architecture
One Go binary (cmd/usacosite) that serves a REST API and the built Vue SPA, all under /usaco. It is deployed as one container inside the web_server stack, behind its nginx. It has the same shape as ../job-tracker, from which internal/auth and handlers.SPA were copied.
-
Git is the only store.
internal/repoowns the clone and serializes every git command. A sync is fetch + hard reset (the remote wins).Mutatedoes sync, edit, commit and push, and replays the edit once if the push is rejected. ItsonChangecallback (Server.Reload) rebuilds the index under the same lock. -
The index is an immutable snapshot, swapped in through an
atomic.Pointer. Handlers reads.Index()once per request. -
Visibility is decided server-side. Non-admins see only
solved/, and an unsolved problem is a 404, not a 403.auth.Forwardreturns false for a request with no cookies without a network call.problem.md(the judge's statement) is admin-only even on solved problems. -
Explanations run in the background.
POST /explainstarts a job inexplain.Jobsand returns 202; the job calls Claude (internal/claude, streamed, JSON schema) and commitsexplain.mdthroughMutate. Tests fake Claude withexplain.Askerand the judges withhandlers.Fetcher; nothing ingo testhits the network. -
Recording reviews are the same shape.
POST /reviewtakes a multipart upload and starts a job in its ownexplain.Jobs: transcribe (internal/transcribe, OpenAI-compatible, raw HTTP), measure (Transcript.Metrics), optionally keep the audio (internal/audiostore, S3), have Claude review it (internal/review) and commitreviews/<id>.md. Reviews are admin-only. Tests fake the transcriber and the store withhandlers.Transcriberandhandlers.AudioStore. -
Evaluations are the same shape, but commit nothing.
POST /evaluatejudges the solve page's draft: it runs the saved tests on the runner, then asks Claude (internal/evaluate). It keeps the answer in memory as the job'sResult(explain.Jobs.StartWith), and the page polls for it. -
Code runs in a separate service, never in the site. The solve page's run/lint handlers (
handlers/run.go) read the problem from the clone (Server.Dir, not the index, which truncates) and post tocmd/usacorunnerthroughrunner.Client;internal/runner/types.gois the contract between them. Tests fake it withhandlers.Runner. The runner's own tests run real g++/python3/clang-tidy/ruff and skip whichever is missing.
Conventions
- Comments explain why, not what. Preserve them, and update them when behaviour changes.
- Edits look at the disk. An edit func passed to
Mutatemay run twice, so it must locate the problem withfindOnDisk, never from the index. - Commit subjects match the CLI's (
lib/cmd/done.sh): "Solve " and so on. - The problem layout belongs to the CLI in the repo root (
lib/). When the CLI's layout changes, updateinternal/index.