Conversation
Delivers mora-core's full surface: FormId newtypes, Patch enum + PatchFile postcard format, Distributor trait with placeholder EspWorld (Plan 5 replaces), PatchSink dedup/sort/finalize, DeterministicChance with inlined FNV-1a-32 + Szudzik + SplitMix64 + Xoshiro256** + MSVC uniform_real_distribution<float> port. Pure Rust, no unsafe, no platform-specific code. Bit-identity vs. real KID verified in M4's golden-harness plan. 14 tasks across 7 phases. No new workspace deps.
Source of truth for FormId, PatchFile postcard format, Patch enum serialization stability, Distributor trait, PatchSink semantics, and the KID-bit-compatible deterministic chance algorithm (Szudzik pairing + FNV-1a + SplitMix64 + Xoshiro256** + MSVC float draw). Cited by subsequent tasks when defining types.
mora-core/src: lib.rs declares form_id/patch/distributor/patch_sink/ chance modules, each populated in its own task. All stubs are minimally typed so cargo check stays green through Plan 4.
FormId wraps u32 with local_id / mod_index / from_parts helpers and hex Display. FullFormId holds (plugin, local_id) for load-order- independent references; resolved to FormId by mora-esp in Plan 5. 5 unit tests cover parts decomposition, construction, and display.
Patch has one variant (AddKeyword) at this plan; future variants must be appended (postcard serializes by declaration order). PatchFile wraps magic + version + load_order_hash + Vec<Patch> with to_bytes / from_bytes that validate magic and version on parse. Opcode_tag + target accessors for PatchSink sorting.
Four tests: empty file, one AddKeyword, bad magic rejected, future version rejected. Exercises the postcard pipeline end-to-end.
Trait: name + lower(world, chance, sink) -> Result<Stats, Error>. Stats: rules/candidates/patches/rejected counts + AddAssign for summing across frontends. EspWorld is a placeholder marker; Plan 5 replaces with mora_esp::EspWorld.
HashSet-backed dedup rejects identical patches; finalize sorts by (opcode_tag, target) and wraps in a PatchFile with magic/version/ load_order_hash. 5 unit tests.
Ports clib_util::hash::szudzik_pair. Wrapping arithmetic matches C++ uint64 overflow semantics. 6 unit tests: identity, greater-branch, less-branch, equal-case, asymmetry, overflow determinism.
Seeds 4-word Xoshiro state from a single u64 via 4 SplitMix64 steps. Matches the canonical algorithm at prng.di.unimi.it/splitmix64.c. 3 tests: first-4-outputs for seed=0 (golden values), determinism, distinct seeds produce distinct states.
Matches https://prng.di.unimi.it/xoshiro256starstar.c. Plan 4 only needs a single next_u64 per chance roll (no stream state). 3 tests: first-output-from-seed-0 (golden), determinism, state divergence. Golden value corrected to 0x99EC5F36CB75F2B4 — verified against reference C implementation; spec contained an incorrect value.
Four-step port matching MSVC STL on x64: 1. raw_u64 as f64 / 2^64 2. narrow to f32 (IEEE 754 round-to-nearest) 3. >=1.0 -> 0.0 snap (MSVC generate_canonical guard) 4. multiply by 100.0 in f32 Four tests: raw=0 -> 0.0, raw=u64::MAX snapped -> 0.0, raw=2^63 -> 50.0 (exact), range invariant for several raws.
Matches KID's clib_util::hash::fnv1a_32. Standard algorithm: offset basis 0x811c9dc5, prime 0x01000193, byte-by-byte, u32 wrapping arithmetic. 5 tests: empty input -> offset basis, 'a' golden value, 'foobar' golden value, determinism, distinct outputs.
passes(keyword, form_id, chance) -> bool: full KID pipeline (FNV-1a-32 + Szudzik + SplitMix + Xoshiro + MSVC draw + threshold compare). Chance=0 always fails, chance>=100 always passes (trivial paths). 6 tests: trivial paths, determinism, keyword variation, range invariant over 1000 form_ids, distribution sanity at chance=50 (47-53% pass rate over 10k rolls). M4's golden harness validates bit-identity against a real KID run once the self-hosted runner image is refreshed.
Whitespace normalization across mora-core. No functional changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fleshes out
mora-coreperdocs/superpowers/plans/2026-04-21-rust-kid-pivot-plan-4-mora-core.md:MORA, version 1,load_order_hash, Vec).
Patch::AddKeywordis the sole variantat this plan; enum is append-only for serialization stability.
EspWorldmarker that Plan 5 replaces with the real mora-esp view.szudzik.rs— Szudzik pairingsplitmix.rs— SplitMix64 state init (golden-verified vs. reference C)xoshiro.rs— Xoshiro256** one-shot (golden-verified vs. reference C;my plan had the wrong golden value, subagent corrected via ref C impl)
msvc_uniform.rs— MSVCuniform_real_distribution<float>portfnv.rs— FNV-1a-32 inlined (standard vectors for "a", "foobar")mod.rs— high-levelpasses(kw, form_id, chance)+ distributionsanity (10k samples at chance=50 → 47-53% pass rate)
docs/src/mora-core-reference.md— source-of-truth for all the above.No ESP parsing, no SKSE interaction, no
unsafe, no new workspace deps.Test plan
cargo test --workspace— 72 tests pass (27 from M1 + 45 new).cargo clippy --all-targets -- -D warningsclean.cargo fmt --checkclean.cargo xwin check --target x86_64-pc-windows-msvc --workspaceclean.skyrim-integrationwill fail until the Unraid runner image is refreshed (Plan 3 merge noted this).Notable implementation details
SplitMix64(0)-seeded state is
0x99EC5F36CB75F2B4(subagent verified byrunning the reference C implementation from prng.di.unimi.it). Test
uses the correct value.
fnvcrate dep.EspWorldis a placeholder struct inmora-core::distributor—empty unit struct that Plan 5 will replace.
Next up
Plan 5:
mora-esp— mmap ESP/ESL/ESM reader, TES4 header parsing,plugins.txt loader, load-order resolution, record iterators.