Explain concepts on the site, and reuse their code from the CLI
Test and publish the site / test (push) Successful in 1m19s
Test and publish the site / publish (push) Successful in 1m31s

/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]>
This commit is contained in:
2026-10-20 12:58:38 +01:00
co-authored by Claude Opus 5.5
parent d4849859df
commit ccf4e4dd74
25 changed files with 1750 additions and 33 deletions
+21 -1
View File
@@ -7,6 +7,7 @@ The public face of this repo, served at `/usaco/` on adam-french.co.uk. It shows
- 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
- have Claude explain a technique ("help explain fenwick trees") or a piece of code, saved to a public library of concepts with a C++ snippet to reuse
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.
@@ -22,6 +23,7 @@ There is no database. The CLI's layout is the data model (see the root README.md
- `problem.md` for the statement (shown only to the admin, and sent to Claude)
- `explain.md` for a Claude-written explanation
- `reviews/<id>.md` for feedback on a recording of the admin explaining their solution (admin only)
- `concepts/<slug>/` for a concept: `concept.md`, `snippet.cpp` and `request.md`
The server keeps a clone of adamf/usaco in `$DATA_DIR/repo` and indexes it into memory.
@@ -49,6 +51,7 @@ internal/index/ reads the clone into memory: problems, files, tests, git dat
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/concept/ the concept prompt and schema, concepts/<slug>/ rendering
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/evaluate/ the solve page's evaluation: prompt, schema and the run's verdicts for Claude
@@ -64,7 +67,7 @@ Everything is served under `BASE_PATH` (`/usaco`). nginx proxies the prefix thro
| Path | Auth | What |
|---|---|---|
| `/usaco/`, `/usaco/p/<name>`, `/usaco/stats`, `/usaco/cli` | none | SPA |
| `/usaco/`, `/usaco/p/<name>`, `/usaco/concepts`, `/usaco/c/<slug>`, `/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 |
@@ -84,6 +87,13 @@ Everything is served under `BASE_PATH` (`/usaco`). nginx proxies the prefix thro
| `GET /usaco/api/problems/<name>/evaluate` | admin | the latest evaluation job, shaped like the explain one, with the evaluation as `result` once it is done |
| `PUT /usaco/api/problems/<name>/code` | admin | `{lang, source}`: commits `main.cpp`, or `main.py` (`sol.py` where that is the existing file), as "Edit <name>" |
| `POST /usaco/api/leetcode/daily` | admin | imports today's LeetCode daily question into `solving/` with the CLI's `lib/leetcode.py` and commits it as "Start <slug>", or finds it if it is already a problem; answers `{name, created}`. 502 if LeetCode or the import fails |
| `GET /usaco/api/concepts` | open | the concept library, newest first, without content or snippets |
| `GET /usaco/api/concepts/<slug>` | open | one concept: `{slug, title, summary, tags, content, snippet, updated}` |
| `POST /usaco/api/concepts` | admin | `{topic, code?}`: starts explaining a new concept and answers 202 `{id, status}`. 503 without `CLAUDE_API_KEY` |
| `GET /usaco/api/concept-jobs/<id>` | admin | that job, shaped like the explain one, with `result: {slug}` once it is saved |
| `POST /usaco/api/concepts/<slug>/explain` | admin | `{note?}`: rewrites the concept in place and answers 202; 409 if a rewrite is running |
| `GET /usaco/api/concepts/<slug>/explain` | admin | the latest rewrite job |
| `DELETE /usaco/api/concepts/<slug>` | admin | removes `concepts/<slug>/`, committed as "Forget concept <slug>" |
| `POST /usaco/api/hooks/gitea` | HMAC (`X-Gitea-Signature`) | queue a pull |
| `GET /usaco/api/health` | open | 200 once the clone is indexed |
@@ -164,6 +174,16 @@ The Explain panel on a problem page (admin only) asks Claude for an intuitive ex
- **The call.** `CLAUDE_MODEL` (default `claude-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.
## Concepts
`/usaco/concepts` is a library of techniques Claude explained, each with a C++ snippet to reuse. Anyone can read it; the admin asks for new ones there, by topic ("help explain fenwick trees") or by pasting code they could not follow.
- **Output.** A JSON-schema reply (`internal/concept` `Schema`): a slug, title, one-line summary and tags, then the intuition, how it works, a walkthrough with SVG diagrams, complexity, when to reach for it, pitfalls, variations, the snippet and a usage example. Given code, the walkthrough traces that code and the snippet is a general version of it. It shares the explanation prompt's math and diagram rules (`explain.MathRules`, `explain.DiagramRules`), so the page renders it with the same `Explanation` component.
- **Storage.** `concepts/<slug>/concept.md` (first line `<!-- concept tags=… -->`, then a `# ` title), `snippet.cpp` (first line `// concept: <slug>`) and `request.md` (the question, so the concept can be rewritten from it). Committed as "Explain concept <slug>".
- **Slugs.** Claude names the concept and is shown the saved ones. A new question never overwrites a saved concept: a taken slug gets `-2`, `-3`… Rewriting one (with a note on what to change) is its own button on the concept's page.
- **Reuse.** The page has a copy button, and `usaco snippet <slug> <problem>` pastes the snippet into a solution above `main`.
- **The call.** As for explanations: a background job the page polls, a minute or two, a similar cost.
## 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.