# Formula Cards: instructions for AI-assisted course authors

Start with the [authoring workflow](api.md), shared by the website and machine-readable manifest.
This document expands on content writing; it is not a separate submission workflow.

These instructions are for **course/deck authors using existing card types**.
You do not need to write Gleam, Gargamelle definitions, decoders or application code.
To contribute a new interaction or grading implementation, follow the separate
[card-type implementation guide](implementing-card-types.md).

Produce a UTF-8 JSON course using `equation-editor-v1` for equations only,
or `mixed-cards-v1` for any combination of the [supported authoring types](card-types.md). Start from
[the complete example](example.json) and validate against
[the JSON Schema](../course.schema.json). Use the [content reference](content-reference.html)
for field descriptions. These are relative links on the same site.
Also read [supported notation](notation.md), [troubleshooting](troubleshooting.md),
and the [three worked examples](worked-examples.json).
Do not generate application code, HTML, scripts, authentication tokens, or editor node IDs.

Supply course content and the supported configuration fields only. The app handles
attempt results, history, progress counts, and synchronization where available;
do not include those records or implement that machinery in your course JSON.
Local drafts remain device-local, as described below.

## Existing course data

The [static course index](../courses/index.html) and its [JSON manifest](../courses/index.json)
are readable without a browser or JavaScript. The published
[Differential Geometry equation/computation JSON](../courses/differential-geometry.json)
is a full-size example of this import schema, including palettes, accepted answers
and explanations. It includes retired definitions explicitly marked `retired`.
Use a new course ID when adapting it; the published ID cannot be replaced.
The index also links separate recall content and translations. Those files use
internal formats and are not standalone imports. The equation JSON alone does
not contain the entire course. Do not crawl rendered card previews for source data.

## Workflow

1. Ask the course owner for sources, intended audience, and the desired deck outline.
   If sources are unavailable, label any invented material as placeholder content.
   Never attribute invented examples to a lecturer.
2. Create a small course first: one deck and two or three cards. Give the course a
   stable ID and each deck/card an ID unique within that course.
3. Choose a supported type for each card and make its prompt self-contained.
   Follow that type's content contract. For equation cards, specify the symbol
   palette, structural operations, digits, answers, grading assumptions and explanation.
4. Return one JSON file. The author can choose it on the Import course page to run
   structural, mechanical, and rendering checks locally. Fix reported paths and repeat.
   Review the card preview and change summary, then choose Install local draft.
   Re-import the same course ID to review and replace a draft.
5. Review the mathematics and rendered equations separately. Mechanical success
   means the editor can construct and recognize the declared answers; it does not
   prove that a theorem, proof, or answer is mathematically correct.

For LLM authors, use the [authoring API workflow](api.md): public validation,
scoped-token proposal submission, and owner review. The [LLM manifest](llm.json)
and [OpenAPI contract](openapi.json) describe exact endpoints and limits.
Local installation still writes only to this browser; it never uploads or publishes.
Submitting a proposal also does not publish. Keep the JSON as a backup.

## Supported card types

`equation-editor-v1` supports equation and computation cards. `mixed-cards-v1`
also supports `verbatim`, `self-review`, `diagram-labeling`, and `cloze`.
See the [card type guide and examples](card-types.md) before choosing fields.
The equation fields below apply only to equation/computation cards.
Do not copy internal recall source files directly: use the public course envelope.

## Required top-level fields

- `schemaVersion`: 1.
- `id`: stable course identifier, matching `^[A-Za-z][A-Za-z0-9_-]*$`.
- `engine`: `equation-editor-v1` or `mixed-cards-v1`.
- `metadata`: `title`; optionally `lecturer`, `deckAuthor`, and
  `source: {label, url}`. Source URLs must use HTTP or HTTPS.
- `decks`: ordered deck definitions. Each requires `id`, `kind` (`lecture`,
  `computation`, `recall`, `activity`, or `supplementary`), `shortName`, `title`, `subtitle`, `description`, and ordered
  `cards` containing card IDs present in the course.
- `cards`: card definitions described below.

Unknown fields are rejected. Consult the schema for exact limits and enums.

## Optional progress categories

The optional top-level `progress` object customizes the labels and colors used
in progress bars, percentage readouts, preview tubes, and the granular-mode icon.
Omit it to keep the standard three colors. For example:

```json
"progress": {
  "categories": [
    {"id": "independent", "label": "Without help", "color": "#9753bb"},
    {"id": "helped", "label": "With help", "color": "#e78935"}
  ],
  "outcomeCategories": {
    "solved": "independent",
    "corrected": "helped",
    "assisted": "helped"
  }
}
```

Provide both fields. Declare 1–12 categories with unique stable IDs, nonempty
labels, and six-digit hex colors. Map every outcome of each selected card type.
For equation cards the three editor outcomes are:
`solved` means no deletions or answer reveal; `corrected` means corrections;
`assisted` means the answer was shown. Several outcomes may share one category.
The app appends grey `unused` (not practiced); do not declare it yourself.
Category order controls presentation. Existing attempts are interpreted through
this mapping, so changing it also changes how past progress is displayed.

The default `progress.policy` is `practice`. Each card type supplies its history
depth; all current types use 10. Omit `historyLength`: only legacy value 10 is accepted. Set `policy: "completion"` for activities completed once: each
eligible card contributes one slot after any recognized completion at its current
learning version, independent of weight. Repetition cannot increase its capacity.
The latest recognized completion supplies its color; this is participation, not
correctness. Unknown outcomes do not erase a known completion. Random drill
buttons are hidden in this policy. A Run's activity history still records all tries.

An ungraded type may declare one outcome such as `reflected`. Map it to a category
with an honest label, e.g. `Reflected`; no success flag or score is required.
Registered custom types are supported; executable code is registered at build
time, never inside imported course JSON.

## Card contract

Each card requires `id`, `title`, `prompt`, positive integer `learningVersion`,
`editor`, `answers`, `explanation`, and `grading`.

`editor` requires:
- `palette`: ordered `{tool, label, accessibleLabel?}` entries. A string tool inserts
  one atomic symbol; an array inserts several symbols. Prefer ordinary constituent
  symbols rather than one monolithic symbol containing a whole equation.
- `operations`: exact operations from the schema, such as `=`, `+`, `−`, `fraction`,
  `power`, `square`, `sqrt`, `(`, `)`, `⟨`, `⟩`, `||`, and supported matrix tools.
- `digits`: individual strings such as `"0"`, `"1"`, `"2"`.
- `initialAnswerVisible`: boolean; true requires a `sequence`.

`answers` contains accepted notation trees. An optional `sequence` contains ordered
step targets for a computation card. For an initial course, use exactly one
entry containing the complete equality chain, also included in `answers`, and
set `grading.equalityChain` to true. Every declared answer and sequence step must
be constructible using the provided tools. Do not rely on a symbol being supplied
implicitly because it occurs in an answer. A prime can be part of a palette token such as `x'`, or offered as a separate
`'` palette tool alongside its base symbol.

Notation trees:

```json
{"kind":"symbol","text":"x"}
{"kind":"row","children":[{"kind":"symbol","text":"x"}]}
{"kind":"fraction","top":{"kind":"row","children":[]},"bottom":{"kind":"row","children":[]}}
{"kind":"power","base":{"kind":"symbol","text":"x"},"exponent":{"kind":"symbol","text":"2"}}
{"kind":"radical","radicand":{"kind":"symbol","text":"x"}}
{"kind":"matrix","cols":2,"cells":[{"kind":"row","children":[]},{"kind":"row","children":[]}]}
```

Empty fields above illustrate structure, not complete answers. Matrices use row-major
cells, each a row node. Although the schema allows dimensions from 1 to 3,
one-row matrices become tuple notation in the editor, not row matrices for
multiplication. Use a transposed column vector for a row factor in a matrix
product. Use `column` for a 2×1 control, `matrix` for 2×2, and the matching
`matrix-3x1`, `matrix-2x3`, `matrix-3x2`, or `matrix-3x3` for other shapes.
See [supported notation](notation.md) for transpose notation.

`explanation` has `kind` (`proof` or `definition`), optional `definition` text, and
optional `proof: {intro, steps}`. Each proof step has `text` and/or an `equation` tree.
Prompt and explanation text support inline `$LaTeX$`; escape backslashes for JSON.

`grading` requires `symbolTypes`, `scalarProducts`, `implicitArguments`, `nonnegative`,
`positive`, `nonzero`, and `equalityChain`. Copy the example's structure but supply
only assumptions that actually hold. Scalar symbols need no declaration; declare
vectors and matrices explicitly using the schema's allowed types. Equality-chain
recognition does not provide arbitrary theorem proving or optional omitted steps.
Equation cards do not support custom functions, glyph definitions or keyboard aliases. Verbatim formula tokens support LaTeX and explicit keyboard aliases.

## Identity and revisions

`schemaVersion` describes the course file format and currently stays at `1`.
Each card's `learningVersion` determines whether its previous attempts still
apply to its current content. These are separate version numbers: revising a
card does not require increasing `schemaVersion`. Internal attempt-storage
changes also require no changes to existing course files.

Card/deck IDs are local to their course. IDs are not content hashes. Keep IDs and
`learningVersion` for cosmetic edits. Increase `learningVersion` when past attempts
no longer assess the same knowledge. Do not change an ID just to edit wording.
Replace placeholders with new card IDs when introducing unrelated real material.

### Sharing a card between decks

Define a card once in the course's `cards` array, then list its ID in each deck
that should contain it. Each deck's `cards` array determines its own order.
Editing that definition updates it everywhere; moving a reference does not
create a new card or reset its history.

History belongs to the course/card identity and learning version, not to a deck.
Under the same mechanic settings, practice of a shared card contributes to every
deck containing it. Each deck includes that card in its progress capacity, and
course totals sum the decks included in course progress: shared membership therefore contributes more than
once to both earned progress and capacity. This does not create duplicate Tries.
Use separate card IDs only for genuinely separate learning tasks.

## Checks for an AI agent with a repository checkout

```sh
node scripts/review-course.mjs --render path/to/course.json
```

The command writes a JSON report and exits nonzero on failure. Inspect `issues`,
including their exact `path` and `cardId`. The browser checker runs structural, editor, and rendering checks.
`--render` provides the equivalent rendering checks from the command line.
A successful report is a preflight result, not authorization to publish.

Limit the file to 10 MB. The engine also bounds notation depth, node counts, matrix
sizes, and saved-document complexity. Keep cards small enough to read and edit.

## Course language preferences

A course may declare optional `localization` metadata with `original` (a language
code), `available` (objects with `code` and the language's own `name`, optionally
`note`), `metadata` (course text by language), and `decks` (deck text by language
and deck ID). Deck translations may provide title, shortName, subtitle, and
description; IDs, membership, grading, and progress remain unchanged.

Equation cards may declare `translations` keyed by an advertised language code.
A translation may replace title, prompt, definition, or proof. It does not replace
answers or grading. The original fields supply the fallback. Keep every proof
complete in its translated language. Other card implementations own their own
translation payloads, including localized answers where appropriate.

The host remembers a course selection separately from its interface language.
The interface language supplies the initial preference only. The course runtime
receives that selection and invokes each card's `withLanguage({language,
originalLanguage})` capability if provided. Unsupported preferences may fall back
to the original. Attempt contexts also carry the selected `language`; cards must
not infer it from interface labels. Preview rendering uses the resolved card
implementation. Language changes do not create new card IDs or progress weights.

### Retiring a card

Set `retired: true` on a card to exclude it from practice, previews and active progress capacity. Keep its definition and deck references: the loader filters it out at runtime, and export preserves its position. Existing attempt history is retained. Remove the flag or set it to `false` to reactivate the card.

### Reading complete courses

The [combined Differential Geometry reading export](../courses/differential-geometry.complete.json) includes equation/computation source, both recall sources, translations and ordered decks. It is not import-compatible. For fetchers with response limits, use the [per-deck JSON index](../courses/differential-geometry.decks.json) or [HTML listing with file sizes](../courses/decks.html). These are generated from the source on every build.

### Recall vocabulary

For verbatim cards, word capsules are generated automatically from the official answer's prose: all words of at least 10 Unicode characters (counting hyphens), regardless of whether they are technical. They preserve answer capitalization and sort longest first, with alphabetical ties. Translated answers produce their own capsules. There are no helper-word or punctuation capsules. Legacy `vocabulary` and `vocabularyAlways` fields remain accepted for compatibility but do not control display; new cards need not supply them. Capsules are free typing aids; Show Answer retains its grading effect. There is no Peek button.

For verbatim cards, the default weight and `gradingScale` are derived from prose characters plus one per formula: 1 below 125, 2 at 125–174, 3 at 175–249, and 4 at 250 or more. They can be set independently: `weight` controls progress credit; `gradingScale` controls correction allowances. Each Show Answer reveal counts as two warnings. Pink allows as many warnings as `gradingScale`; orange allows one additional warning for scale 1, or two additional warnings for scales 2–4; further warnings give yellow. Historical attempts retain their original weights and grading policies.

Verbatim cards begin with a free official-answer preview, which hides when the learner starts typing. This initial preview does not count as a Show Answer reveal. Subsequent reveals count as two warnings under the grading rule above.
