Expand description
The alignment engine — the moat crate.
Takes two amberfork_model::Runs and produces the move-typed alignment, the fork, and
ultimately the amberfork_model::DiffResult the CLI and UI render. Three parts, each an
empirically locked decision (see docs/design/design-run-diff-debugger.md, Amendment
2026-07-08, and docs/notebook.md 001–003):
- [
cost]: the step-vs-step cost model. v1 default is lexical (LexicalCost) — deterministic and dependency-free. Embeddings live behind the sameCostModeltrait and must beat lexical on dev fixtures to earn default status (Amendment B). - affine-gap Needleman–Wunsch over those costs, emitting
amberfork_model::Moves. - the resync-k fork rule: fork = first non-sync block the alignment does not recover from within k synchronous moves (Amendment A).
Sync + pure by design: no I/O, no async, no globals. Loading runs is amberfork-ingest’s
job; this crate is a function from two runs to a diff.
Structs§
- Align
Params - Affine-gap penalties, on the same scale as
CostModelcosts ([0, 1]per step). Defaults are the spike-validated values (notebook 001–003). - Consensus
- What N references agree on about one suspect run.
- Diff
Params - Everything tunable about a diff, one level up: the aligner’s gap penalties and the fork
rule’s threshold/recovery window.
Defaultis the dev-calibrated configuration. - Fork
Params - Parameters of the fork rule. Defaults are dev-calibrated (notebook 001–003):
resync_k = 2per Amendment A;tau = 0.3, the middle of the plateau (0.2–0.4 scored identically for the token-level lexical cost model on the dev pairs). - Lexical
Cost - The v1 default cost model:
1 - gestalt_ratioover the steps’ token sequences.
Enums§
- Param
Error - Why a parameter set was rejected. One variant per violated invariant, carrying the value so the message can be honest about what was seen.
Traits§
- Cost
Model - A step-vs-step alignment cost in
[0, 1]:0.0= identical content,1.0= nothing in common. Implementations must be deterministic and symmetric — the aligner’s output is part of the reproducibility promise, and the fork rule’stauthresholds compare against these values directly.
Functions§
- align
- Globally align reference
aagainst observedb, minimizing total cost. - consensus
- Diff
suspectagainst every run inreferencesand tally where they say it forked. - diff
- Diff
observedagainstreference: align, locate the fork, assemble the result. - find_
fork - Locate the fork in an alignment, or
Noneif the runs converged (all blocks benign).