Menstrual-cycle and health tracking (readable built-in keywords, uniform { date, ... }[] arrays, FHIR R4 CodeableConcept escapes, and FHIR dateTime, spanning up to 10,000 days, bounded naturally by QR capacity) in one dense QR code.
- The model, its FHIR mapping, the samples and the entropy targets are described in
MODEL.md,MAPPING.mdandEXPRESSIVENESS.md. - The codec is a Rust crate compiled to WebAssembly. Its wire format is in
FORMAT.md; the measurements are below.
Codec files
| file | what |
|---|---|
cycle-log.wasm | the codec, registry id 1. Exports memory, shc_alloc, shc_decode (card → canonical Bundle JSON) and shc_encode (model JSON → card), per CODEC-ABI.md v0.1. |
cycle-log-tools.wasm | the same codec plus cy_trace (where the bits go), cy_sizes (modelled and plain sizes), cy_encode_mode (a forced, possibly non-canonical mode), cy_encode_p / cy_decode_p (alternative model constants) and cy_cost (decoding cost of a card or model, for warnings; FORMAT.md 5.4). Not a registry module. |
rust/ | the crate. core/ holds everything, under #![no_std] and #![forbid(unsafe_code)]. shim.rs is the only unsafe code: the allocator and the ABI entry points. codec/ and tools/ are the two cdylibs. |
FORMAT.md | the wire format, precise enough for an independent implementation |
codec.test.ts | the codec tests (about 13 minutes) |
codec-host.ts, codec-fixtures.ts | the ABI host used by the tests, and the test inputs (with verbatim copies of the generator in cycle-log.test.ts, checked against it) |
sizes.ts | the measurement tables |
wasm-count.ts | counts executed WebAssembly instructions (used for the worst-case figures in FORMAT.md 5.3) |
node-decode.mjs | decodes with Node, for the second-engine check |
What the encoder accepts
shc_encode takes the model as JSON text and refuses exactly what validateJson in model.ts rejects, with a message that starts with one of the field paths it reports (@<position> for a number spelling).
- Any model
validateaccepts is encoded, normalized or not. The encoder appliesnormalizeitself: for example, aCodeableConceptmatching a built-in keyword (SymptomKind,MedicationKind,ConditionKind, etc.) is normalized to the keyword (stripping anydisplay), non-built-in escape concepts preserve theirdisplayandtext, text-only{ text }concepts stay text-only, andZ/:00timestamps are normalized to canonical+00:00/ minute precision. - The only other refusal is LIMIT, for a card that would exceed 4,096 bytes. A large Bundle or a slow decode is never refused;
cy_costreports them so tools can warn (FORMAT.md 5.3 and 5.4).
Build
rust/build.sh
- The build needs the rustup
stabletoolchain with thewasm32-unknown-unknownstandard library. A distribution's ownrustcmay lack it (for example, Arch's 1.100 has no wasm32 std). - It has no dependencies and needs no network.
- Build output goes to
$CARGO_TARGET_DIR, by defaultrust/target, which is git-ignored. The script copies both modules here and prints their SHA-256. - The crate is built at
opt-level = 3, the decoder that executes the fewest instructions and stays panic-free. The codec is about 370 KiB (zero imports, zero floats, link-time zero-panic). - Target features are pinned in
rust/.cargo/config.toml:target-cpu=mvpplus mutable-globals, sign-ext, bulk-memory and multivalue.
The panic handler refers to an undefined symbol. If any panic path survives optimisation, linking fails, so a module that builds has no reachable panic.
Test and regenerate
bun test codec.test.ts # the codec
bun test # also the model tests
bun sizes.ts # measurements (markdown)
The tests decode each sample and check it against golden.json. After the model or the samples change, regenerate that file with bun golden.ts --write, then rebuild and rerun the tests. Once cards have been shared, a change to the wire format needs a new codec id.
For quicker development:
CY_FIX=<dir of model/bundle json> cargo test --release -p cycle_log_core --test native
Measurements
From bun sizes.ts.
QR versions are for the codec input plus 3 bytes: the codec reference and the card's 2-byte check. The working lines for a phone screen are Version 25-L (1,250 bytes) and Version 30-L (1,703 bytes).
| sample | set | codec B | card B | QR L / M | line |
|---|---|---|---|---|---|
| power-tracker | tuning | 1,239 | 1,242 | Version 25-L / Version 30-M | ≤ Version 25-L |
| copper-iud (named) | tuning | 317 | 320 | Version 12-L / Version 14-M | ≤ Version 25-L |
| combined-pill | tuning | 244 | 247 | Version 10-L / Version 12-M | ≤ Version 25-L |
| pcos | held out | 281 | 284 | Version 11-L / Version 13-M | ≤ Version 25-L |
| minimal | held out | 31 | 34 | Version 3-L / Version 3-M | ≤ Version 25-L |
| perimenopause | held out | 694 | 697 | Version 18-L / Version 22-M | ≤ Version 25-L |
| near-empty | held out | 15 | 18 | Version 2-L / Version 2-M | ≤ Version 25-L |
| own-vocabulary (named) | held out | 1,616 | 1,619 | Version 30-L / Version 34-M | ≤ Version 30-L |
| wellness-diary | held out | 1,856 | 1,859 | Version 32-L / Version 36-M | over Version 30-L |
| calendar-only | held out | 53 | 56 | Version 4-L / Version 5-M | ≤ Version 25-L |
| smart-cup-hmb | held out | 329 | 332 | Version 12-L / Version 14-M | ≤ Version 25-L |
| wearable | held out | 686 | 689 | Version 18-L / Version 21-M | ≤ Version 25-L |
| post-ablation | held out | 460 | 463 | Version 15-L / Version 17-M | ≤ Version 25-L |
| vitals-follow-up | held out | 710 | 713 | Version 19-L / Version 22-M | ≤ Version 25-L |
| timestamped | held out | 1,957 | 1,960 | Version 33-L / Version 38-M | over Version 30-L |
| bp-twice-daily | held out | 1,812 | 1,815 | Version 32-L / Version 36-M | over Version 30-L |
| med-doses | held out | 1,243 | 1,246 | Version 25-L / Version 30-M | ≤ Version 25-L |
| bbt-exclusions-and-fever | held out | 597 | 600 | Version 17-L / Version 19-M | ≤ Version 25-L |
The tuning samples were looked at while designing the model; the others are held out (there are now 20 sample records in total, including text-tags for text-only CodeableConcept tags without synthetic app URIs and offline-displays for offline display and text on standard SNOMED CT / RxNorm escape codes; run bun sizes.ts for current live measurements across all 20). calendar-only, smart-cup-hmb, wearable and post-ablation, the sample records that exercise the source app, conditions, answers, measured volume and wearable temperature, were not looked at while modelling those fields. vitals-follow-up (heart rate, weight and blood pressure readings with components) was not looked at while modelling components: they were designed on synthetic readings added to the tuning sample power-tracker. timestamped (a time of day on every entry) was not looked at while modelling times of day, which were designed on synthetic times added to power-tracker (FORMAT.md 4.11); its card is 699 B with only each day's first entry and no times. bp-twice-daily (blood pressure morning and evening) was not looked at while modelling several entries a day, which were designed on synthetic readings added to power-tracker; with only the first reading of each day and no times its card is 706 B.
The full tables, with the per-category breakdown, random and adversarial models, and the sensitivity of every model constant, are printed by bun sizes.ts.