Files
usaco/site/CLAUDE.md
T
adamfandClaude Opus 5.5 ccf4e4dd74
Test and publish the site / test (push) Successful in 1m19s
Test and publish the site / publish (push) Successful in 1m31s
Explain concepts on the site, and reuse their code from the CLI
/usaco/concepts is a library of techniques Claude explained: the admin
asks by topic ("help explain fenwick trees") or pastes code they could
not follow, and gets an intuitive explanation with SVG diagrams plus a
C++ snippet in contest style. Given code, the walkthrough traces that
code and the snippet is a general version of it. Anyone can read the
library; generating, rewriting and deleting are admin-only.

Each concept is committed as concepts/<slug>/: concept.md (tags in a
header comment, then a # title), snippet.cpp (first line
"// concept: <slug>") and request.md (the question, for rewrites). The
slug is Claude's to pick, so a new concept's job is keyed by an id and
returns {slug} as its result; a taken slug gets -2, -3... rather than
overwriting. Rewriting starts from the saved question and version plus
a note on what to change. The index reads concepts into Index.Concepts,
with their date from git.

internal/concept shares explain's math and diagram rules, now split out
as explain.MathRules and explain.DiagramRules; the explain prompt is
byte-for-byte unchanged. Code fences in explanations are highlighted
with the same highlight.js setup as CodeBlock (web/src/highlight.js).

`usaco snippet` lists concepts, prints one's snippet, or pastes it into
a solution above main (or class Solution), keeping a .bak and refusing
a concept the file already has. In interactive mode it pastes into the
selection.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-20 12:58:38 +01:00

3.7 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/repo owns the clone and serializes every git command. A sync is fetch + hard reset (the remote wins). Mutate does sync, edit, commit and push, and replays the edit once if the push is rejected. Its onChange callback (Server.Reload) rebuilds the index under the same lock.

  • The index is an immutable snapshot, swapped in through an atomic.Pointer. Handlers read s.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.Forward returns 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 /explain starts a job in explain.Jobs and returns 202; the job calls Claude (internal/claude, streamed, JSON schema) and commits explain.md through Mutate. Tests fake Claude with explain.Asker and the judges with handlers.Fetcher; nothing in go test hits the network.

  • Recording reviews are the same shape. POST /review takes a multipart upload and starts a job in its own explain.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 commit reviews/<id>.md. Reviews are admin-only. Tests fake the transcriber and the store with handlers.Transcriber and handlers.AudioStore.

  • Concepts are the same shape, outside the problems. POST /concepts has Claude explain a technique or pasted code (internal/concept) and commits concepts/<slug>/ (explanation, C++ snippet, the request). The slug is Claude's, so a new concept's job is keyed by an id and returns {slug} as its Result; rewrites are keyed by slug. The index reads them into Index.Concepts, and they are public.

  • Evaluations are the same shape, but commit nothing. POST /evaluate judges 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's Result (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 to cmd/usacorunner through runner.Client; internal/runner/types.go is the contract between them. Tests fake it with handlers.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 Mutate may run twice, so it must locate the problem with findOnDisk, 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, update internal/index.