# Card developer quickstart (SDK v1)

This path is for implementing a new interaction or grader through reviewed code
integration. To create a course using existing cards, start with the
[course-author workflow](api.md). Course proposal tokens do not authorize code installation.

Developing an interaction is separate from assembling courses and decks. Course
JSON selects a **registered type** and supplies content; it never contains executable
code. Registration is at build time and requires a reviewed deployment. Runtime
plugin installation is out of scope.

## Run a minimal card

From an app checkout with Node 22+, Gleam 1.18.1+ and `npm ci` completed:

```sh
npm run providers:prepare
npm run providers:init -- /absolute/path/my-card
cd /absolute/path/my-card
npm run build
```

Then from the app checkout:

```sh
npm run providers:check -- --config /absolute/path/my-card/playground.json
npm run dev:providers -- --config /absolute/path/my-card/playground.json
```

The starter is an exact-text echo card. Edit its manifest, Gleam content/result
contracts, `provider.js` and `view.js`; `playground.json` supplies test examples.
Generated facades hide compiler paths. Import `defineCardType` from
`@flashcards/provider-sdk/v1` (resolved by this kit, not a published npm package).
The manifest owns the type ID, schema name and view entry. Pass its ID into Gleam
contract factories; use `card.type` in submitted results. Do not repeat the ID.

The minimal declaration has `contracts`, `outcomes`, `interpret`, and optionally
`resultFor(card, typeId)` for current-content checks. The contract facade exports
`content_boundary(typeId)`, `encode_content_text(value)`, `content_schema(typeId)`
and `result_contract(typeId)`. The result interpreter receives historical evidence,
not today's answer. Common content fields compose `card_header.start` in Gleam.

A view exports `cardView.mount({root, card, state, context})`, renders only in its
owned empty root, and returns `{dispose()}`. Submit evidence with synchronous
`context.complete(result)`. A receipt means accepted, not durably saved. On refusal,
keep the view usable. After acceptance, show a button owned by the view that calls `context.advance()`.
Use the optional `app-next-button` CSS class for standard themed styling.
Dispose listeners and resources. Hosts start Redo with `freshState`; the adapter
remounts unless the instance supplies `restart`. `context.redoOfAttemptId` identifies Redo.
Use `standardCardView({mount})` from `@flashcards/provider-sdk/v1/view` for prompt, appearance and Back/Next/Redo controls
and default previews. Its inner root is empty; the host renders the page title.
The shell is optional; a bare view must render its own controls using `actions`
and `context`. Optional shell history is `{history:{interpret, style}}`.

## Add only capabilities you use

| Declaration | When omitted |
| --- | --- |
| `work: {mode: "run", json, workVersion}`, optionally `freshState(card, {mode})` and `restore(input)` | No saved payload; transient state is discarded |
| `history: {consumer, input}` | No history subscription |
| `localize`, `workLanguage` | Content unchanged; no language compatibility restriction |
| View `createPreview` | Plain title/prompt preview |
| `content.snapshot` | Frozen SDK-v1 canonical snapshot |
| `mathResources`, `authoringReview`, `offlinePreview` | No such checks/resources; offline preview explicitly unavailable |

For saved work, register an output boundary using SDK `jsonOutputBoundary`.
Default restore validates its version and codec, otherwise calls `freshState`.
The factory may randomize new work (including Redo and restore fallbacks); valid saved work preserves its saved choices. Do not regenerate state during render.
The same factory creates mount state and every fresh fallback. Custom restore gets
`{saved, current, card}` including both Run/Occurrence identities and may choose
its own within-Run compatibility policy. See [saved-work and presentation guide](provider-work-and-presentation.md) for declaration placement, validation, Run-only retention, CSS and evidence privacy.

SDK-v1 snapshots contain format/version, card identity/type, learning version,
resolved weight and canonical exported content. Their encoding is frozen once used;
changing it requires a new format or an explicit migration. Existing built-ins
retain their historical snapshot functions. Weight affects revision identity but
never rewrites earned tries. Math is not part of the core card contract.

For repository registration, add the manifest to `providers/catalog.js`, naming
`directory`, `gleamModule`, `contractsEntry` and `viewEntry`. The starter already
declares all except its repository-relative `directory`; keep its source layout. Runtime entry/export default to
`provider.js` / `cardType`. The build follows module imports; no second file list
is needed. Consumers receive only the normalized result of `defineCardType`.

Use the [kit reference](provider-playground.html) for tooling and the repository's
`providers/README.md` for detailed ownership/lifecycle rules. Automated browser
work belongs on a separate `--test-state` origin, never learner storage. The kit
runs trusted code; it is not a security sandbox.
