Skip to main content

Crate amberfork_align

Crate amberfork_align 

Source
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 same CostModel trait 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§

AlignParams
Affine-gap penalties, on the same scale as CostModel costs ([0, 1] per step). Defaults are the spike-validated values (notebook 001–003).
Consensus
What N references agree on about one suspect run.
DiffParams
Everything tunable about a diff, one level up: the aligner’s gap penalties and the fork rule’s threshold/recovery window. Default is the dev-calibrated configuration.
ForkParams
Parameters of the fork rule. Defaults are dev-calibrated (notebook 001–003): resync_k = 2 per 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).
LexicalCost
The v1 default cost model: 1 - gestalt_ratio over the steps’ token sequences.

Enums§

ParamError
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§

CostModel
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’s tau thresholds compare against these values directly.

Functions§

align
Globally align reference a against observed b, minimizing total cost.
consensus
Diff suspect against every run in references and tally where they say it forked.
diff
Diff observed against reference: align, locate the fork, assemble the result.
find_fork
Locate the fork in an alignment, or None if the runs converged (all blocks benign).