- internal/jobs replaces explain.Jobs: one registry for every kind of
background job, with records in DATA_DIR/jobs. A job's draft is written
before its commit, so a failed commit can be saved again (POST
/jobs/<kind>/<key>/save) and a restart mid-commit resumes it, without
paying Claude twice.
- Graceful shutdown: SIGTERM stops new jobs and waits SHUTDOWN_GRACE for
running ones while still serving the pages that poll them.
- internal/usage records every Claude call's tokens and estimated cost in
DATA_DIR/usage.jsonl; CLAUDE_MONTHLY_BUDGET refuses new jobs (429) once a
month reaches it. The stats page shows the admin the spend.
- auth.SameOrigin refuses cross-origin writes to admin routes.
- The LeetCode importer runs the clone's script without the server's
secrets in its environment.
- A sync that leaves HEAD where it was skips the re-index.
- docs_test.go checks README's route table against the routes, and the CLI
page against the root README's commands.
- The repo is going private: Gitea links on the site are admin-only.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
/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]>
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]>