Skip to content

Latest commit

 

History

History
243 lines (218 loc) · 18.2 KB

CLAUDE.md

File metadata and controls

243 lines (218 loc) · 18.2 KB

Claude Code Instructions

Project guidance for Claude Code (CLI, IDE, and the GitHub Action). The same conventions apply to GitHub Copilot --- see .github/copilot-instructions.md, which is the source of truth for style.

Project context

pds holds the probability prerequisites for the Morrison-Lab data science courses, as Quarto fragments. It renders on its own as a website, and course sites such as mlds link to its pages by URL, so a page's path and its #id anchors are an interface: renaming either breaks those links. The scaffolding came from the UCD-SERG qwt template.

Authoritative style guide: UCD-SERG Lab Manual (source: https://github.com/UCD-SERG/lab-manual).

Repository layout

  • index.qmd, appendix-*.qmd, and the top-level topic pages --- Quarto source pages. The topic pages are listed in reading order in _quarto-website.yml, in a docked sidebar and in matching navbar dropdowns:

    • Foundations: notation.qmd, probability-basics.qmd, random-variables.qmd, independence.qmd
    • Moments: expectation.qmd, entropy.qmd, variance-covariance.qmd
    • Distributions: distributions.qmd, multivariate-gaussian.qmd, limit-theorems.qmd

    The navbar's left menus mirror the sidebar's contents one-for-one, so a page added, renamed, or moved must be edited in both.

  • _notation.qmd, _subfiles/ --- the fragments the topic pages include

  • references.qmd --- standalone reference page; excluded from the default website render (!references.qmd in _quarto-website.yml), so it isn't part of the normal site build

  • _quarto.yml, _quarto-website.yml --- Quarto project + website config

  • pds --- a self-referential symlink (pds -> .), so include paths written as pds/... (the paths a host site that keeps a copy of this repo at its root would use) also resolve when this repo renders standalone. This creates an unbounded pds/pds/pds/... path loop; _quarto-website.yml's !pds/ render exclusion keeps Quarto's own render-list glob from walking into it, but the symlink is not otherwise sandboxed --- avoid recursive/symlink-following operations (find -L, rsync -a --copy-links, unscoped grep -r) rooted at the repo root; scope such commands to real subdirectories instead. lintr cannot be pointed away from it via .lintr.R's exclusions field: lintr::normalize_exclusions() always resolves exclusion paths with normalize_path(), which follows symlinks, so any exclusion naming pds (the directory, or a file under it) collapses onto the exact same absolute path as the real file it aliases and silently excludes that real file too --- there is no exclusions-list syntax that can single out the symlinked duplicate without also matching the original. lint-project.yaml and lint-changed-files.yaml instead rm -f pds right after checkout, before invoking lintr, so its directory walk never sees the symlink at all.

  • _extensions/ --- vendored Quarto extensions

  • latex-macros/ --- git submodule for shortcode/macro definitions (see .gitmodules)

  • R/, man/, DESCRIPTION, NAMESPACE --- the project is also a small R package

  • references.bib --- BibTeX bibliography

  • offwhite.scss, theme-picker.html --- the website's Light / Off-white / Parchment / Dark theme dropdown (saved under lds-theme, with mln-theme read as a legacy fallback, shared with the slides and the other sites on this origin)

  • styles.css --- website styling; styles-reveal.scss, qwt-reveal-toggle.html (the same dropdown for slides), and the revealjs-*.lua filters drive the reveal.js slide output

  • assets/, images/ --- static image and asset files (site pages, docs, CI/PR screenshots)

  • .github/workflows/ --- CI workflow definitions

  • .github/scripts/ --- helper scripts used by workflows

  • .github/instructions/ --- path-scoped Copilot rules that attach by file glob (see .github/copilot-instructions.md)

  • CONTRIBUTING.md --- contributor guide

  • _site/, _freeze/, .quarto/ --- build artifacts (do not edit by hand)

Style conventions

Mirrors .github/copilot-instructions.md. Key points:

  • Lists of 3+ items: use bullet lists rather than comma-separated prose. Always leave a blank line before a markdown bullet list (especially in .qmd files).
  • Code chunks: HTML output folds code by default: _quarto-website.yml sets code-fold: true (with code-tools: true, so readers can show all code at once), as rme does. Keep the default when the output (plot, table) is the point and the code is incidental. Set #| code-fold: false on tutorial code, short examples, code that is the main focus, and chunks where the console output is the main content.
  • R style: respect .lintr.R. Run lintr::lint_dir() before declaring R changes done.
  • No nested calls in R: lint-changed-lines.yaml lints the R code and R chunks that a PR adds or edits, with lms::default_linters(nested_calls = TRUE). Its nested_calls = TRUE setting enforces the lab's no-nested-calls rule. The linters also flag base R functions that have tidyverse replacements. Run the same linters on a file before pushing with lintr::lint("file.qmd", linters = lms::default_linters(nested_calls = TRUE)).
  • Definitions and results: one term per #def- div, aliases ("also called") in the same div, in bold and in the title, and a second new term in its own div that links to the first; one result per theorem-type div. See "Definitions and results" in .github/copilot-instructions.md.
  • Useful resources: a course, book or video that covers a topic pds teaches goes in the Further reading section of the matching page, even when lds already lists it in a directory (Ezra, 2026-10-15). Link the resource, and adapt it with attribution only when its license allows adapting. See track-useful-resources.
  • Quarto chunks: prefer chunk options as YAML-style #| directives, not as inline r, opt = val arguments.

Working in this repo

  • Don't edit generated files: README.md is built from README.Rmd; _site/ and _freeze/ are build outputs.
  • Local preview: quarto preview (live reload). Full build: quarto render. When verifying a single edited page, render just that page (quarto render <file>.qmd --to html) rather than the whole site --- the /render command is for the full build.
  • Submodules: latex-macros/ is the only git submodule (see .gitmodules). Run git submodule update --init --recursive after cloning.
  • Spell check: words go in inst/WORDLIST (see .github/workflows/check-spelling.yaml). Update the wordlist instead of disabling the check.
  • Link check: tuned in lychee.toml; prefer fixing broken links over adding exceptions.
  • Other CI checks: workflows also verify bibliography DOIs (check-bibliography-dois.yml) and flag non-standard characters (check-non-standard-chars.yaml). Fix the flagged source rather than relaxing the check.
  • Dependencies: Dependabot auto-updates the latex-macros submodule and GitHub Actions (see .github/dependabot.yml); don't bump those by hand unless a PR needs it.
  • Rendering in a cloud session: random-variables.qmd needs the qnp package. remotes::install_github("Morrison-Lab/qnp") fails there with "unknown package", so git clone qnp and install it with remotes::install_local(). Install lms the same way, from a clone of Morrison-Lab/psc at the lms-ref in lint-changed-lines.yaml.
  • Moving an example to another page: inline R on the old page that reads the example's variables then fails. Put the shared code in an _*.R file under _subfiles/, show it in the example with #| file: pds/_subfiles/<path>.R, and rerun it on the other page in an #| include: false chunk with the same file option (pds#495).
  • Running the gha checks locally: pds has no local runner. lds's .github/workflows/cluster-checks.yml has one run-check.sh <check> <ENV>=... -- python3 ... line per gha check, which gives each check's environment variables; set the base ref to origin/main and run them in a full (not shallow) clone. Each check's action.yml also names its variables (*_BASE_REF, *_GLOBS, *_FAIL, and TERM_LINKS_TERMS_DIRS pointing at an mds clone), so a short loop over a gha clone's check-*/action.yml that sets them can run every check in one pass (pds#526). Commit first, because the checks diff HEAD. Check out the submodule first (git submodule update --init --depth 1 latex-macros): without it, check-fform-paren, check-macro-expansions and check-tautological-equations skip with a warning instead of running (pds#530). check-links fails in such a loop only because its lychee step is not a Python step; check new links instead by fetching each published page and searching it for id="<anchor>" (pds#535). To run lds's lines unchanged, make .terms-from/Morrison-Lab/ hold clones of mds, sds and mcs and a link to this checkout; .gitignore keeps it out of commits. check-term-links reports only a few findings per run, so re-run it after each fix until it passes (pds#531 took five runs).
  • Cross-page references: pds has no site-xrefs filter, so @id resolves only to an id on the same page. Reference an id on another page with a link, [text](page.qmd#id), and when a div moves to another page, rewrite the old page's @id references to it as links (pds#526). A bare [text](#id) also breaks when the id is on another page. When moving a section, repoint links by id with a script, not by hand: map each page's ids from its include tree, then give every link into or out of the moved subfiles the page that holds its id. Run once on main, the same map found 12 links naming the wrong page (pds#542, pds#543, pds#544). Expect check-term-links and check-restated-results to re-check the moved lines; a solution whose theorem follows later takes <!-- restated-ok: reason -->.
  • Re-running the Claude review: pds has no /review comment trigger, so a /review comment starts nothing. To review an unchanged head again, for example after an anchor it links to goes live, post @claude review or re-run the last Claude Code Review run in full (re-running only the failed jobs reuses the old workflow version) (pds#524).
  • Rendering variance-covariance.qmd also needs reticulate and readr; installing the Imports and Suggests in DESCRIPTION from https://packagemanager.posit.co/cran/__linux__/noble/latest covers them.

Pull request expectations

  • Keep PRs scoped --- bug fixes shouldn't smuggle in refactors.
  • Plan for these slips that cost review rounds on new result and definition divs (pds#409, pds#413, pds#414, 2026-11-10; pds#490, 2026-11-23):
    • The Claude review rule: a new #prp-, #thm-, #lem-, #cor- or #def- div needs a worked #exm- div after it. A remark between them does not count, and the review is NOT_CLEAN without the example.
    • check-avoided-words fails a trailing (@prp-x) crossref. Write "As @prp-x shows, ..." or make the whole claim the link text.
    • check-term-links flags an ordinary word that is also a defined term, such as "terms" in "In practical terms". Reword it rather than link it.
    • The check-term-links opt-out pragma must carry a reason, as in <!-- check-term-links: allow: reason -->. It must also sit on the same line as the term it excuses: on a line of its own it suppresses nothing, and the check fails it as stale-allow (pds#520).
    • check-definite-antecedents fails a bare demonstrative such as "That is why"; name the referent ("This one-variable case is why"). To run it locally, set ODA_BASE_REF=origin/main and ODA_GLOBS='*.qmd', not a CDA_ or DA_ prefix, which it ignores and then skips the run (pds#520).
    • check-equation-labels fails any new display equation without an {#eq-...} label, in examples as well as results (pds#526).
    • check-term-links reads "is positive definite" as one defined phrase: link the whole phrase, [is positive definite](...), not "positive definite" alone (pds#526).
    • check-term-links also reads a bold list label in a solution or proof, such as **Symmetry:**, as a first use of a defined term: link the label, or excuse it with the pragma above (pds#535). "Finite" for a value has no definition to link; write "is a real number" or "is less than $\infty$" instead.
    • The lms linters flag rep(c(...)) inside a data frame (nested calls) and a hardcoded labs(fill = "..."). Build a small table with dplyr::tribble(), and give a column the name its legend should show, such as ~`mass function`. Do not reach for labelled::set_variable_labels(): the preview build does not install packages from Suggests, so the page fails to render (pds#535).
    • check-result-titles needs a result's title to be a declarative sentence, and it reads a verb after "that" as part of a subordinate clause, not as the main verb. "The probability that they all occur is a product ..." fails; "The probability of an intersection is a product ..." passes. Put the main verb in a clause of its own.
  • A mechanical split of a multi-div subfile stays a pure move (Ezra, 2026-11-09, pds#368 and pds#369). A pure movement PR is exempt from the PR size cap, which gha's check-pr-size and ai-config's push hook set at 40 files and 1200 lines, doubled from 20 and 600 (Ezra, 2026-11-28: "double the cap on pr size" and "pure movement prs are exempt from the cap"), and the body still says "mechanical, content-identical" so a reviewer knows to diff the moved text. New content that a check forces (a result div, an example) is not a move and loses the exemption: put it in a small stacked PR, and exempt the moved text from the check with <!-- def-equiv-ok: reason -->, listed in the body. Put that comment below the #### title line, never above it: above it, the div renders with no title. Touching a subfile re-checks its old text, so expect check-term-links and check-definition-equations to flag lines you only moved. check-result-definition-links re-checks a moved result div the same way: exempt it with <!-- check-result-definition-links: allow: reason --> below the title line, and list it in the body.
  • A small edit to a multi-div subfile starts with a split. check-one-div-per-subfile fails any PR that adds a line to a subfile with more than one top-level div (a proof stays with its claim). So a small edit to such a file goes as two stacked PRs, the mechanical split first and the edit on the split files second (the split of _def-pdf-pmf-cdf.qmd in pds#426, then the interval edit in pds#425). Put a > [!IMPORTANT] alert on the second PR naming the first, and merge the first with a merge commit, not a squash, because squashing it gives main different commits from the branch stacked on it. Check that the split is a pure move by rendering the page before and after and diffing the <body> (as in pds#426).
  • Keep main's lines in a merge resolution, and rewrite them in the next commit (pds#524). check-merge-drops runs with fail: true and reads only merge commits. It reports a line main added that the merge drops, unless a new line at least 0.6 word-similar replaces it, and a short line rewritten as a link (as in @def-mahalanobis,) scores below that. So keep the line as is in the merge, then make the rewrite in an ordinary commit whose message says why. A PR that conflicts with main gets no pull_request checks at all (gha#859), so a head with only CodeQL check runs is a sign to run git merge-tree --write-tree origin/main <branch>.
  • Write commit messages and PR descriptions explaining the why, not just the what.
  • Don't bypass CI failures (spell check, link check, lint, bibliography DOIs, non-standard chars) --- fix the underlying issue.
  • Don't commit _site/ or _freeze/ changes unless that is genuinely the intent of the PR.

Shared lab rules

The lab's cross-repository rules live in Morrison-Lab/ai-config, which .claude/settings.json enables as the ai-config@Morrison-Lab plugin. Enabling is not installing: a local session needs claude plugin install ai-config@Morrison-Lab once. When the plugin is not loaded (for example, in a session rooted above this checkout), read the rules from a clone of ai-config before content work, in particular:

  • shared/writing/ --- definitions, derivation steps, fact-checking, cross-references, plain prose
  • shared/coding/ --- R style, ASCII punctuation in source
  • skills/quarto-authoring/references/divs-and-spans.md --- no theorem-type div nested inside another

Relationship to rme

This repository is the canonical home for the probability prerequisites that Morrison-Lab/rme carries as appendices (probability.qmd and sec-CLT.qmd). rme will drop those appendices and point readers here (rme#1204).

  • rme is a good first place to look for content, not an authority on content or style: much of it predates the lab's style rules. Check what you port, fix what is wrong, and bring it up to the current rules.
  • Keep rme's #ids, so rme's links can be repointed by changing only the path.

Things to avoid

  • Reformatting unrelated files.
  • Inventing URLs or citations --- only use sources actually present in references.bib or explicitly provided.

Cross-project agent rules (ai-config)

This repository follows the maintainer's cross-project agent rules in Morrison-Lab/ai-config. If your harness has not already loaded them (Claude Code loads them through the ai-config plugin), read AGENTS.md before starting work, and follow it alongside this file. This file's own instructions add to those rules, and win only where they are more specific.