When stuck, the admin can ask Claude for an intuitive explanation of a problem. It is committed as explain.md and shown as folded sections, so the reader opens only as much as they need: the key observation, hints that get stronger, the approach, a walkthrough with an SVG diagram per step, complexity, pitfalls and a pseudocode sketch. - internal/claude: streamed call with a JSON-schema reply, high effort, the server-side refusal fallback, fixed error messages and logged token usage. CLAUDE_API_KEY and CLAUDE_MODEL (default claude-opus-5-5); without a key only this feature is off. - internal/explain: the prompt, the schema, rendering to markdown, and a per-problem job tracker. The request starts a job and the page polls, since a call outlasts nginx's 120s timeout. - internal/statement: fetches statements from LeetCode's GraphQL API and USACO's problem pages. Others (Codeforces is behind Cloudflare) are pasted. - problem.md holds the statement, editable from the meta editor and shown only to the admin. Diagrams are sanitized with DOMPurify. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2.2 KiB
2.2 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.
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.