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
+28
View File
@@ -4,6 +4,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"time"
)
@@ -76,6 +77,13 @@ func fixture(t *testing.T) string {
write("solved/moocast/reviews/2026-09-04-100000.md", "<!-- review verdict=correct audio=moocast/2026-09-04-100000.mp3 -->\n_Reviewed by m._\n")
write("solved/moocast/reviews/notes.md", "hand-written\n")
commit(4, "Add a test")
write("concepts/fenwick-tree/concept.md", "<!-- concept tags=range-query,prefix-sums -->\n# Fenwick tree\n\n_Prefix sums with updates in O(log n)._\n\n_Explained by m on 5 September 2026._\n\n## Intuition\n\nLowbits.\n")
write("concepts/fenwick-tree/snippet.cpp", "// concept: fenwick-tree\nstruct BIT {};\n")
write("concepts/fenwick-tree/request.md", "help explain fenwick trees\n")
write("concepts/hand-made/snippet.cpp", "int f();\n")
write("concepts/empty/notes.txt", "nothing to show\n")
commit(5, "Explain concept fenwick-tree")
return dir
}
@@ -139,6 +147,26 @@ func TestBuild(t *testing.T) {
t.Fatalf("moocast history = %+v, want 3 commits newest first", m.History)
}
if len(m.History) != 3 {
t.Fatalf("a concept's commit touched moocast: %+v", m.History)
}
if len(idx.Concepts) != 2 {
t.Fatalf("concepts = %v, want fenwick-tree and hand-made (empty has nothing to show)", idx.Concepts)
}
f := idx.Concepts["fenwick-tree"]
if f.Title != "Fenwick tree" || f.Summary != "Prefix sums with updates in O(log n)." || len(f.Tags) != 2 || f.Tags[1] != "prefix-sums" {
t.Fatalf("fenwick-tree = %+v", f)
}
if !strings.HasPrefix(f.Content, "_Prefix sums") || strings.Contains(f.Content, "# Fenwick") || strings.Contains(f.Content, "<!--") {
t.Fatalf("fenwick-tree content keeps its header or title: %q", f.Content)
}
if f.Snippet == nil || f.Snippet.Lang != "cpp" || f.Request != "help explain fenwick trees\n" || f.Updated == nil || !f.Updated.Equal(day(5)) {
t.Fatalf("fenwick-tree snippet/request/updated = %+v / %q / %v", f.Snippet, f.Request, f.Updated)
}
if h := idx.Concepts["hand-made"]; h.Title != "hand-made" || h.Content != "" || h.Snippet == nil || len(h.Tags) != 0 {
t.Fatalf("hand-made = %+v, want the slug as title and only a snippet", h)
}
w := idx.Problems["watermelon"]
if w.Status != Skipped || w.SolvedAt != nil || w.Sample != nil {
t.Fatalf("watermelon = %+v, want skipped, unsolved, no sample (empty .in)", w.Summary)