frontierlab

    A MoonBit algorithm trace protocol and polished offline HTML visualization kit.

    algorithm
    trace
    visualization
    education
    html
    debugger
    Download zip
    Author
    Version
    0.10.0
    License
    MIT
    Last updated
    3 days ago
    Downloads
    97

    #FrontierLab

    FrontierLab 是一个 MoonBit 算法轨迹库。它把算法执行过程记录为带稳定实体 ID 的语义事件和场景快照,并提供检查、对比、调试、JSON 编解码和精修后的离线 HTML 可视化能力。

    CI Mooncakes

    #安装

    在 MoonBit 项目中添加依赖:

    moon add shop1111/frontierlab

    然后在需要使用 FrontierLab 的包中导入 shop1111/frontierlab。

    FrontierLab 需要 MoonBit moonc 0.10.16 或更新版本,CI 固定在 0.10.18+6c83a7f62 上验证,详见工具链策略。

    #最小示例

    下面的例子生成一条插入排序轨迹,再检查最终序列是否有序:

    let trace = @frontierlab.insertion_sort_trace([3, 1, 2])
    let result = @frontierlab.diagnose_trace(
    trace,
    contract=@frontierlab.sorted_int_sequence_contract(object_id="values"),
    expected=trace,
    )
    assert_true(result.passed())

    这里的“轨迹规则”(代码类型为 TraceContract)是一个检查器:它检查轨迹中的 步骤或最终结果是否违反预先定义的要求,并返回具体的失败步骤和原因。 sorted_int_sequence_contract 检查最终整数序列是否有序; sequence_transition_contract 检查事件描述的变化是否与场景快照一致。

    自定义算法通常按以下顺序接入:

    1. 用稳定 ID 表示元素、节点或网格单元;元素移动后 ID 不变。
    2. 用 TraceBuilder 记录 Compare、Swap、Visit、Union、Relax 等有意义的事件和对应场景。
    3. 调用 finish 得到 AlgorithmTrace。
    4. 将轨迹交给规则检查、差异分析、JSON 编解码或渲染 API。

    可直接运行的完整代码见 API 示例 和集成说明。

    #自动适配:不写埋点代码

    对于数组类算法,不必手动调用 TraceBuilder。有两种自动方式:

    追踪容器 TracedArray:把参数类型从 Array 换成 TracedArray,算法 正文照常写。a.less(i, j)、a.compare(i, j) 记录比较,a.swap(i, j) 记录 交换,a[i] = v 记录更新,读取 a[i] 只计数不生成步骤。直接写 a[i] < a[j] 不会被记录为比较,需要比较时请用 less 或 compare。

    fn bubble_sort(a : @frontierlab.TracedArray[Int]) -> Unit {
    for end = a.length() - 1; end > 0; end = end - 1 {
    for i in 0..<end {
    if a.less(i + 1, i) {
    a.swap(i, i + 1)
    }
    }
    }
    }

    let a = @frontierlab.TracedArray::new([5, 2, 4, 1, 3], title="Bubble sort")
    bubble_sort(a)
    let html = @frontierlab.render_trace_html(a.finish())

    快照推断 SequenceProbe:算法继续使用普通 Array,每次变化后调用一次 probe.observe(values)。FrontierLab 比较前后快照,自动推断交换、更新、移动、 插入和删除事件,并保持元素 ID 稳定;比较不会改变数据,需要时用 probe.compare(i, j) 补充。

    两者都接受 level 参数:Full 记录完整轨迹,Count 只统计比较、交换、读、 写次数(counts()),Off 什么都不做,用作测量追踪开销的基准。记录过程中 的错误(例如超过步数上限)会保留到 finish() 时再抛出,因此被追踪的算法 不需要声明 raise。完整示例见 examples/traced_sort。

    #内置算法 Adapter

    Adapter 把算法输入和执行步骤转换成统一的 AlgorithmTrace,因此这些轨迹可以 直接交给 JSON、HTML、分析、断点、diff 和诊断 API:

    类别Adapter场景主要语义事件
    排序insertion_sort_trace、insertion_sort_items_traceSequenceCompare、Swap
    集合union_find_traceSetsCompare、Union、Update
    一维 DPfibonacci_dp_trace、coin_change_dp_traceSequenceUpdate、依赖高亮
    二维 DPzero_one_knapsack_dp_trace、lcs_dp_traceGridUpdate、Visit
    平衡树red_black_tree_traceGraph插入、重着色、旋转、查找
    路径搜索桥接search_trace_to_algorithm_traceGridVisit、Relax

    Fibonacci 和零钱兑换保留各自简单的算法级入口,但内部共享一维 DP 场景表达。 红黑树支持 Insert 和 Find 操作;节点标签中的 [R]、[B] 在不修改 Trace Schema v1 的前提下持久表示颜色。

    let lcs = @frontierlab.lcs_dp_trace("ABCBDAB", "BDCABA")
    let tree = @frontierlab.red_black_tree_trace([
    @frontierlab.Insert(30),
    @frontierlab.Insert(10),
    @frontierlab.Insert(20),
    @frontierlab.Find(20),
    ])

    #CLI

    从源码运行统一诊断命令:

    moon run cmd/main -- diagnose \ fixtures/agent-traces/selection-sort-expected.json \ fixtures/agent-traces/selection-sort-actual.json \ --contract sorted-int-sequence \ --object values \ --format text \ --counterexample _build/counterexample.json \ --report _build/diagnosis.html

    这组示例输入故意包含错误,所以命令返回退出码 2,并报告第一次差异在 step 10。CLI 的退出码含义为:

    • 0:输入有效,并且轨迹通过检查且与参考轨迹一致;
    • 2:输入有效,但轨迹违反规则或与参考轨迹不同;
    • 1:参数、文件、JSON 或 Schema 无效。

    GitHub Release 同时提供 Windows 可执行文件和 SHA256。也可以在本地构建:

    python scripts\build_cli.py .\_dist\frontierlab.exe --version

    #生成算法可视化

    最直接的用法是让 CLI 生成一个完全离线的 HTML 文件,然后双击打开。页面默认 使用中文,可切换 English,并会显示比较对象、交换方向、旧值到新值、DP 依赖、 网格坐标、图节点移动、Adapter 注释和伪代码行。

    New-Item -ItemType Directory -Force _build\visual | Out-Null moon run cmd/main -- demo insertion-sort --format html --output _build/visual/insertion-sort.html moon run cmd/main -- demo fibonacci --format html --output _build/visual/fibonacci.html moon run cmd/main -- demo coin-change --format html --output _build/visual/coin-change.html moon run cmd/main -- demo knapsack --format html --output _build/visual/knapsack.html moon run cmd/main -- demo lcs --format html --output _build/visual/lcs.html moon run cmd/main -- demo union-find --format html --output _build/visual/union-find.html moon run cmd/main -- demo pathfinding --format html --output _build/visual/pathfinding.html moon run cmd/main -- demo red-black-tree --format html --output _build/visual/red-black-tree.html

    如果已经有 Schema v1 JSON 轨迹,则使用:

    moon run cmd/main -- render trace.json --format html --output trace.html

    render_trace_svg 与 render_trace_svg_frames 在 v0.9 仅保留为旧代码兼容入口, 已经标记弃用,并计划在 v1.0 删除。新项目应选择交互 HTML;需要交换或长期存档 轨迹数据时选择 Schema v1 JSON。

    #离线浏览器工具

    AI Trace Clinic 是一个单文件离线页面,可导入、回放和比较轨迹,不依赖服务器、 CDN 或外部脚本:

    moon run cmd/main -- playground --output _build/playground.html

    生成后直接用浏览器打开 _build/playground.html。页面自带一个错误示例,用于 展示规则失败、第一次差异、状态变化和聚焦切片。

    #核心 API

    用途主要 API说明
    记录轨迹TraceBuilder::new、record、finish把算法执行过程记录为语义事件和完整场景快照
    统一诊断diagnose_trace、TraceDiagnosis::passed同时执行规则检查、参考轨迹比较和聚焦切片
    调试与比较diff、breakpoint_hits、slice、first_divergence查看步骤变化、命中语义断点并定位第一次差异
    JSON 协议encode_json、AlgorithmTrace::decode_json、validate读写并校验稳定的 Trace Schema v1
    输出render_trace_html、render_trace_playground生成交互式离线 HTML 或诊断页面;SVG API 仅作弃用兼容

    完整公开接口由 moon info 生成在 pkg.generated.mbti 中。

    #独立 consumer 示例

    consumer/frontierlab_consumer_demo 是一个单独的 MoonBit 项目。它通过 Mooncakes 安装 shop1111/frontierlab,不引用当前仓库中的源码,因此可以模拟 一个真正的外部使用者。

    这个项目有两个作用:验证发布包确实能被其他项目安装和调用,以及提供一个完整 的集成示例。普通用户不需要运行它;安装依赖并调用上面的公开 API 即可。

    发布后可用以下命令核验:

    cd consumer/frontierlab_consumer_demo moon tree moon check --target all --deny-warn moon test --target all --deny-warn

    consumer 不会被打入 FrontierLab 的 Mooncakes 源码包,它运行时生成的 evidence/ 目录也不会提交到 Git。

    #开发与验证

    moon check --target all --deny-warn moon build --target all --deny-warn moon fmt --check moon info moon test --target all --deny-warn python scripts/check_coverage.py node scripts/check_playground.mjs node scripts/check_renderer.mjs _build/renderer/insertion-sort.html python scripts/validate_cli.py moon package --list moon package

    更多资料:

    #License

    MIT

    TraceError

    pub(all) suberror TraceError {
    JsonSyntax(String)
    UnsupportedSchema(String)
    DuplicateId(String)
    DanglingReference(TargetRef)
    InvalidGraph(String)
    InvalidGrid(String)
    InvalidStep(String)
    DuplicateSummaryKey(String)
    AlreadyCompleted
    LimitExceeded(String)
    } derive(Eq,
    Debug
    )

    impl Show for TraceError

    TraceError::equal

    fn TraceError::equal(TraceError, TraceError) -> Bool

    TraceError::message

    fn TraceError::message(self : TraceError) -> String

    TraceError::not_equal

    fn TraceError::not_equal(x : TraceError, y : TraceError) -> Bool

    TraceError::output

    fn TraceError::output(self : TraceError, logger : &Logger) -> Unit

    TraceError::to_string

    fn TraceError::to_string(self : TraceError) -> String

    AlgorithmReport

    pub struct AlgorithmReport {
    algorithm : String
    reachable : Bool
    visited_count : Int
    path_length : Int
    total_cost : Int
    } derive(Eq, ToJson,
    Debug
    )

    AlgorithmReport::equal

    AlgorithmReport::from_result

    fn AlgorithmReport::from_result(algorithm : String, result : PathResult) -> AlgorithmReport

    AlgorithmReport::not_equal

    fn AlgorithmReport::not_equal(x : AlgorithmReport, y : AlgorithmReport) -> Bool

    AlgorithmReport::to_json

    AlgorithmTrace

    pub struct AlgorithmTrace {
    schema_version : String
    title : String
    algorithm : String
    description : String
    initial_scene : Scene
    steps : Array[AlgorithmTraceStep]
    summary : Array[TraceAttribute]
    } derive(Eq, ToJson,
    Debug
    )

    AlgorithmTrace::analysis_markdown

    fn AlgorithmTrace::analysis_markdown(self : AlgorithmTrace, target_limit? : Int) -> String

    AlgorithmTrace::analyze

    AlgorithmTrace::breakpoint_hits

    fn AlgorithmTrace::breakpoint_hits(self : AlgorithmTrace, breakpoint : TraceBreakpoint) -> Array[TraceBreakpointHit]

    AlgorithmTrace::decode_json

    fn AlgorithmTrace::decode_json(input : StringView, options? : TraceOptions) -> AlgorithmTrace raise TraceError

    Decode and validate the stable FrontierLab schema-v1 wire format.

    AlgorithmTrace::diff

    fn AlgorithmTrace::diff(self : AlgorithmTrace, from_step~ : Int, to_step~ : Int) -> TraceFrameDiff raise TraceError

    AlgorithmTrace::encode_json

    fn AlgorithmTrace::encode_json(self : AlgorithmTrace) -> String

    Encode the stable FrontierLab schema-v1 wire format.

    AlgorithmTrace::equal

    AlgorithmTrace::event_counts

    fn AlgorithmTrace::event_counts(self : AlgorithmTrace) -> Array[EventCount]

    AlgorithmTrace::has_lint_errors

    fn AlgorithmTrace::has_lint_errors(self : AlgorithmTrace) -> Bool

    AlgorithmTrace::has_lint_warnings

    fn AlgorithmTrace::has_lint_warnings(self : AlgorithmTrace) -> Bool

    AlgorithmTrace::lint

    Run non-throwing quality checks that complement AlgorithmTrace::validate.

    AlgorithmTrace::lint_count

    fn AlgorithmTrace::lint_count(self : AlgorithmTrace, severity : TraceLintSeverity) -> Int

    AlgorithmTrace::lint_markdown

    fn AlgorithmTrace::lint_markdown(self : AlgorithmTrace) -> String

    AlgorithmTrace::lint_report

    fn AlgorithmTrace::lint_report(self : AlgorithmTrace) -> String

    AlgorithmTrace::not_equal

    fn AlgorithmTrace::not_equal(x : AlgorithmTrace, y : AlgorithmTrace) -> Bool

    AlgorithmTrace::object_usage

    fn AlgorithmTrace::object_usage(self : AlgorithmTrace) -> Array[ObjectUsage]

    AlgorithmTrace::slice

    fn AlgorithmTrace::slice(self : AlgorithmTrace, center~ : Int, before? : Int, after? : Int) -> TraceCounterexample raise TraceError

    AlgorithmTrace::summary_report

    fn AlgorithmTrace::summary_report(self : AlgorithmTrace) -> String

    AlgorithmTrace::target_usage

    fn AlgorithmTrace::target_usage(self : AlgorithmTrace) -> Array[TargetUsage]

    AlgorithmTrace::timeline

    AlgorithmTrace::timeline_report

    fn AlgorithmTrace::timeline_report(self : AlgorithmTrace) -> String

    AlgorithmTrace::timeline_table

    fn AlgorithmTrace::timeline_table(self : AlgorithmTrace) -> String

    AlgorithmTrace::to_json

    AlgorithmTrace::to_json_string

    fn AlgorithmTrace::to_json_string(self : AlgorithmTrace) -> String

    AlgorithmTrace::validate

    fn AlgorithmTrace::validate(self : AlgorithmTrace, options? : TraceOptions) -> Unit raise TraceError

    AlgorithmTraceStep

    pub struct AlgorithmTraceStep {
    index : Int
    event : TraceEvent
    scene : Scene
    annotation : Annotation?
    } derive(Eq, ToJson,
    Debug
    )

    AlgorithmTraceStep::equal

    AlgorithmTraceStep::not_equal

    AlgorithmTraceStep::to_json

    Annotation

    pub struct Annotation {
    title : String
    body : String
    pseudocode_line : Int?
    } derive(Eq, ToJson,
    Debug
    )

    Annotation::equal

    fn Annotation::equal(Annotation, Annotation) -> Bool

    Annotation::new

    fn Annotation::new(title~ : String, body~ : String, pseudocode_line? : Int) -> Annotation

    Annotation::not_equal

    fn Annotation::not_equal(x : Annotation, y : Annotation) -> Bool

    Annotation::to_json

    fn Annotation::to_json(Annotation) -> Json

    CompareReport

    pub struct CompareReport {
    entries : Array[AlgorithmReport]
    } derive(Eq, ToJson,
    Debug
    )

    CompareReport::equal

    CompareReport::not_equal

    fn CompareReport::not_equal(x : CompareReport, y : CompareReport) -> Bool

    CompareReport::to_json

    ContractReport

    pub struct ContractReport {
    report_version : String
    contract_name : String
    passed : Bool
    violations : Array[TraceViolation]
    first_failure : TraceViolation?
    counterexample : TraceCounterexample?
    } derive(Eq, ToJson,
    Debug
    )

    ContractReport::equal

    ContractReport::not_equal

    fn ContractReport::not_equal(x : ContractReport, y : ContractReport) -> Bool

    ContractReport::report

    fn ContractReport::report(self : ContractReport) -> String

    ContractReport::to_json

    ContractReport::to_json_string

    fn ContractReport::to_json_string(self : ContractReport) -> String

    ContractReport::to_markdown

    fn ContractReport::to_markdown(self : ContractReport) -> String

    CostEntry

    pub struct CostEntry {
    position : Position
    cost : Int
    } derive(Eq, ToJson,
    Debug
    )

    CostEntry::equal

    fn CostEntry::equal(CostEntry, CostEntry) -> Bool

    CostEntry::new

    fn CostEntry::new(position~ : Position, cost~ : Int) -> CostEntry

    CostEntry::not_equal

    fn CostEntry::not_equal(x : CostEntry, y : CostEntry) -> Bool

    CostEntry::to_json

    fn CostEntry::to_json(CostEntry) -> Json

    DebugEntity

    type DebugEntity derive(Eq,
    Debug
    )

    DebugEntity::equal

    fn DebugEntity::equal(DebugEntity, DebugEntity) -> Bool

    DebugEntity::not_equal

    fn DebugEntity::not_equal(x : DebugEntity, y : DebugEntity) -> Bool

    EventCount

    pub struct EventCount {
    name : String
    count : Int
    first_step : Int
    last_step : Int
    } derive(Eq, ToJson,
    Debug
    )

    A counted event kind in an AlgorithmTrace.

    EventCount::equal

    fn EventCount::equal(EventCount, EventCount) -> Bool

    EventCount::new

    fn EventCount::new(name~ : String, count? : Int, first_step? : Int, last_step? : Int) -> EventCount

    EventCount::not_equal

    fn EventCount::not_equal(x : EventCount, y : EventCount) -> Bool

    EventCount::to_json

    fn EventCount::to_json(EventCount) -> Json

    GraphEdge

    pub struct GraphEdge {
    id : String
    from : String
    to : String
    label : String
    directed : Bool
    } derive(Eq, ToJson,
    Debug
    )

    GraphEdge::equal

    fn GraphEdge::equal(GraphEdge, GraphEdge) -> Bool

    GraphEdge::new

    fn GraphEdge::new(id~ : String, from~ : String, to~ : String, label? : String, directed? : Bool) -> GraphEdge

    GraphEdge::not_equal

    fn GraphEdge::not_equal(x : GraphEdge, y : GraphEdge) -> Bool

    GraphEdge::to_json

    fn GraphEdge::to_json(GraphEdge) -> Json

    GraphNode

    pub struct GraphNode {
    id : String
    label : String
    } derive(Eq, ToJson,
    Debug
    )

    GraphNode::equal

    fn GraphNode::equal(GraphNode, GraphNode) -> Bool

    GraphNode::new

    fn GraphNode::new(id~ : String, label~ : String) -> GraphNode

    GraphNode::not_equal

    fn GraphNode::not_equal(x : GraphNode, y : GraphNode) -> Bool

    GraphNode::to_json

    fn GraphNode::to_json(GraphNode) -> Json

    GraphState

    pub struct GraphState {
    id : String
    label : String
    nodes : Array[GraphNode]
    edges : Array[GraphEdge]
    } derive(Eq, ToJson,
    Debug
    )

    GraphState::equal

    fn GraphState::equal(GraphState, GraphState) -> Bool

    GraphState::new

    fn GraphState::new(id~ : String, label~ : String, nodes~ : Array[GraphNode], edges~ : Array[GraphEdge]) -> GraphState raise TraceError

    GraphState::not_equal

    fn GraphState::not_equal(x : GraphState, y : GraphState) -> Bool

    GraphState::to_json

    fn GraphState::to_json(GraphState) -> Json

    GridCellState

    pub struct GridCellState {
    id : String
    x : Int
    y : Int
    label : String
    blocked : Bool
    } derive(Eq, ToJson,
    Debug
    )

    GridCellState::equal

    GridCellState::new

    fn GridCellState::new(id~ : String, x~ : Int, y~ : Int, label? : String, blocked? : Bool) -> GridCellState

    GridCellState::not_equal

    fn GridCellState::not_equal(x : GridCellState, y : GridCellState) -> Bool

    GridCellState::to_json

    GridMap

    pub struct GridMap {
    width : Int
    height : Int
    obstacles : Array[Position]
    weights : Array[WeightedCell]
    } derive(Eq, ToJson,
    Debug
    )

    GridMap::contains

    fn GridMap::contains(self : GridMap, position : Position) -> Bool

    GridMap::equal

    fn GridMap::equal(GridMap, GridMap) -> Bool

    GridMap::is_obstacle

    fn GridMap::is_obstacle(self : GridMap, position : Position) -> Bool

    GridMap::is_walkable

    fn GridMap::is_walkable(self : GridMap, position : Position) -> Bool

    GridMap::neighbors

    fn GridMap::neighbors(self : GridMap, position : Position, rule : MoveRule) -> Array[Position]

    GridMap::new

    fn GridMap::new(width~ : Int, height~ : Int) -> GridMap raise

    GridMap::not_equal

    fn GridMap::not_equal(x : GridMap, y : GridMap) -> Bool

    GridMap::to_json

    fn GridMap::to_json(GridMap) -> Json

    GridMap::to_repr

    GridMap::weight_at

    fn GridMap::weight_at(self : GridMap, position : Position) -> Int

    GridMap::with_obstacle

    fn GridMap::with_obstacle(self : GridMap, position : Position) -> GridMap raise

    GridMap::with_weight

    fn GridMap::with_weight(self : GridMap, position : Position, weight : Int) -> GridMap raise

    GridState

    pub struct GridState {
    id : String
    label : String
    width : Int
    height : Int
    cells : Array[GridCellState]
    } derive(Eq, ToJson,
    Debug
    )

    GridState::equal

    fn GridState::equal(GridState, GridState) -> Bool

    GridState::new

    fn GridState::new(id~ : String, label~ : String, width~ : Int, height~ : Int, cells~ : Array[GridCellState]) -> GridState raise TraceError

    GridState::not_equal

    fn GridState::not_equal(x : GridState, y : GridState) -> Bool

    GridState::to_json

    fn GridState::to_json(GridState) -> Json

    Heuristic

    pub(all) enum Heuristic {
    Manhattan
    Chebyshev
    Zero
    } derive(Eq, ToJson,
    Debug
    )

    Heuristic::equal

    fn Heuristic::equal(Heuristic, Heuristic) -> Bool

    Heuristic::not_equal

    fn Heuristic::not_equal(x : Heuristic, y : Heuristic) -> Bool

    Heuristic::to_json

    fn Heuristic::to_json(Heuristic) -> Json

    Highlight

    pub struct Highlight {
    target : TargetRef
    role : HighlightRole
    } derive(Eq, ToJson,
    Debug
    )

    Highlight::equal

    fn Highlight::equal(Highlight, Highlight) -> Bool

    Highlight::new

    fn Highlight::new(target~ : TargetRef, role~ : HighlightRole) -> Highlight

    Highlight::not_equal

    fn Highlight::not_equal(x : Highlight, y : Highlight) -> Bool

    Highlight::to_json

    fn Highlight::to_json(Highlight) -> Json

    HighlightRole

    pub(all) enum HighlightRole {
    Current
    Candidate
    Compared
    Changed
    Visited
    Frontier
    Result
    Error
    } derive(Eq, ToJson,
    Debug
    )

    HighlightRole::equal

    HighlightRole::not_equal

    fn HighlightRole::not_equal(x : HighlightRole, y : HighlightRole) -> Bool

    HighlightRole::to_json

    MoveRule

    pub(all) enum MoveRule {
    FourDirections
    EightDirections
    } derive(Eq, ToJson,
    Debug
    )

    MoveRule::equal

    fn MoveRule::equal(MoveRule, MoveRule) -> Bool

    MoveRule::not_equal

    fn MoveRule::not_equal(x : MoveRule, y : MoveRule) -> Bool

    MoveRule::to_json

    fn MoveRule::to_json(MoveRule) -> Json

    MoveRule::to_repr

    ObjectUsage

    pub struct ObjectUsage {
    object_id : String
    object_kind : String
    appearances : Int
    max_entities : Int
    first_step : Int
    last_step : Int
    } derive(Eq, ToJson,
    Debug
    )

    Object-level usage collected across the initial scene and every step scene.

    ObjectUsage::equal

    fn ObjectUsage::equal(ObjectUsage, ObjectUsage) -> Bool

    ObjectUsage::new

    fn ObjectUsage::new(object_id~ : String, object_kind~ : String, appearances? : Int, max_entities? : Int, first_step? : Int, last_step? : Int) -> ObjectUsage

    ObjectUsage::not_equal

    fn ObjectUsage::not_equal(x : ObjectUsage, y : ObjectUsage) -> Bool

    ObjectUsage::to_json

    fn ObjectUsage::to_json(ObjectUsage) -> Json

    OperationCounts

    pub struct OperationCounts {
    compares : Int
    swaps : Int
    reads : Int
    writes : Int
    snapshots : Int
    } derive(Eq, ToJson,
    Debug
    )

    Operation counters collected by TracedArray and SequenceProbe.

    TracedArray counts the operations the algorithm performs. SequenceProbe infers them from snapshots, so a shift of k elements counts as k writes.

    OperationCounts::equal

    OperationCounts::not_equal

    fn OperationCounts::not_equal(x : OperationCounts, y : OperationCounts) -> Bool

    OperationCounts::to_json

    pub struct ParentLink {
    child : Position
    parent : Position
    } derive(Eq, ToJson,
    Debug
    )

    ParentLink::equal

    fn ParentLink::equal(ParentLink, ParentLink) -> Bool

    ParentLink::new

    fn ParentLink::new(child~ : Position, parent~ : Position) -> ParentLink

    ParentLink::not_equal

    fn ParentLink::not_equal(x : ParentLink, y : ParentLink) -> Bool

    ParentLink::to_json

    fn ParentLink::to_json(ParentLink) -> Json

    PathResult

    pub struct PathResult {
    reachable : Bool
    path : Array[Position]
    cost : Int
    visited_count : Int
    } derive(Eq, ToJson,
    Debug
    )

    PathResult::equal

    fn PathResult::equal(PathResult, PathResult) -> Bool

    PathResult::found

    fn PathResult::found(path~ : Array[Position], cost~ : Int, visited_count~ : Int) -> PathResult

    PathResult::not_equal

    fn PathResult::not_equal(x : PathResult, y : PathResult) -> Bool

    PathResult::not_found

    fn PathResult::not_found(visited_count~ : Int) -> PathResult

    PathResult::to_json

    fn PathResult::to_json(PathResult) -> Json

    Position

    pub struct Position {
    x : Int
    y : Int
    } derive(Eq, ToJson,
    Debug
    )

    Position::equal

    fn Position::equal(Position, Position) -> Bool

    Position::new

    fn Position::new(x~ : Int, y~ : Int) -> Position

    Position::not_equal

    fn Position::not_equal(x : Position, y : Position) -> Bool

    Position::to_json

    fn Position::to_json(Position) -> Json

    Position::to_repr

    RedBlackTreeOperation

    pub(all) enum RedBlackTreeOperation {
    Insert(Int)
    Find(Int)
    } derive(Eq, ToJson,
    Debug
    )

    One operation accepted by the red-black-tree trace adapter.

    RedBlackTreeOperation::equal

    RedBlackTreeOperation::not_equal

    RedBlackTreeOperation::to_json

    Scene

    pub struct Scene {
    objects : Array[SceneObject]
    highlights : Array[Highlight]
    } derive(Eq, ToJson,
    Debug
    )

    Scene::equal

    fn Scene::equal(Scene, Scene) -> Bool

    Scene::new

    fn Scene::new(objects~ : Array[SceneObject], highlights? : Array[Highlight]) -> Scene raise TraceError

    Scene::not_equal

    fn Scene::not_equal(x : Scene, y : Scene) -> Bool

    Scene::to_json

    fn Scene::to_json(Scene) -> Json

    Scene::to_repr

    SceneObject

    pub(all) enum SceneObject {
    Sequence(SequenceState)
    Sets(SetState)
    Graph(GraphState)
    Grid(GridState)
    } derive(Eq, ToJson,
    Debug
    )

    SceneObject::equal

    fn SceneObject::equal(SceneObject, SceneObject) -> Bool

    SceneObject::not_equal

    fn SceneObject::not_equal(x : SceneObject, y : SceneObject) -> Bool

    SceneObject::to_json

    fn SceneObject::to_json(SceneObject) -> Json

    SearchTrace

    pub struct SearchTrace {
    result : PathResult
    steps : Array[TraceStep]
    } derive(Eq, ToJson,
    Debug
    )

    SearchTrace::equal

    fn SearchTrace::equal(SearchTrace, SearchTrace) -> Bool

    SearchTrace::new

    fn SearchTrace::new(result~ : PathResult, steps~ : Array[TraceStep]) -> SearchTrace

    SearchTrace::not_equal

    fn SearchTrace::not_equal(x : SearchTrace, y : SearchTrace) -> Bool

    SearchTrace::to_json

    fn SearchTrace::to_json(SearchTrace) -> Json

    SequenceItem

    pub struct SequenceItem {
    id : String
    value : String
    } derive(Eq, ToJson,
    Debug
    )

    SequenceItem::equal

    SequenceItem::new

    fn SequenceItem::new(id~ : String, value~ : String) -> SequenceItem

    SequenceItem::not_equal

    fn SequenceItem::not_equal(x : SequenceItem, y : SequenceItem) -> Bool

    SequenceItem::to_json

    SequenceProbe

    pub struct SequenceProbe[T] {
    // private fields
    }

    Records a sequence algorithm from snapshots without hand-written events.

    Call observe with the current values after each change. FrontierLab keeps element ids stable across moves and infers the semantic event: Swap, Update, or a Custom move, insert, remove, or edit. Comparisons leave no trace in the values, so report them with compare if wanted.

    SequenceProbe::compare

    fn[T] SequenceProbe::compare(self : SequenceProbe[T], i : Int, j : Int, note? : String) -> Unit

    Records a comparison between two current positions.

    SequenceProbe::counts

    fn[T] SequenceProbe::counts(self : SequenceProbe[T]) -> OperationCounts

    SequenceProbe::finish

    fn[T] SequenceProbe::finish(self : SequenceProbe[T]) -> AlgorithmTrace raise TraceError

    Completes the trace. Raises the first recording error, or InvalidStep when the probe was not created at TraceLevel::Full.

    SequenceProbe::new

    fn[T : Show] SequenceProbe::new(values : Array[T], title? : String, algorithm? : String, object_id? : String, label? : String, level? : TraceLevel, options? : TraceOptions) -> SequenceProbe[T]

    SequenceProbe::observe

    fn[T : Eq + Show] SequenceProbe::observe(self : SequenceProbe[T], values : Array[T], note? : String) -> Unit

    Reports the values after a change; unchanged snapshots record nothing.

    SequenceState

    pub struct SequenceState {
    id : String
    label : String
    items : Array[SequenceItem]
    } derive(Eq, ToJson,
    Debug
    )

    SequenceState::equal

    SequenceState::new

    fn SequenceState::new(id~ : String, label~ : String, items~ : Array[SequenceItem]) -> SequenceState

    SequenceState::not_equal

    fn SequenceState::not_equal(x : SequenceState, y : SequenceState) -> Bool

    SequenceState::to_json

    SetGroup

    pub struct SetGroup {
    id : String
    label : String
    members : Array[String]
    } derive(Eq, ToJson,
    Debug
    )

    SetGroup::equal

    fn SetGroup::equal(SetGroup, SetGroup) -> Bool

    SetGroup::new

    fn SetGroup::new(id~ : String, label~ : String, members~ : Array[String]) -> SetGroup

    SetGroup::not_equal

    fn SetGroup::not_equal(x : SetGroup, y : SetGroup) -> Bool

    SetGroup::to_json

    fn SetGroup::to_json(SetGroup) -> Json

    SetGroup::to_repr

    SetState

    pub struct SetState {
    id : String
    label : String
    groups : Array[SetGroup]
    } derive(Eq, ToJson,
    Debug
    )

    SetState::equal

    fn SetState::equal(SetState, SetState) -> Bool

    SetState::new

    fn SetState::new(id~ : String, label~ : String, groups~ : Array[SetGroup]) -> SetState

    SetState::not_equal

    fn SetState::not_equal(x : SetState, y : SetState) -> Bool

    SetState::to_json

    fn SetState::to_json(SetState) -> Json

    SetState::to_repr

    SortTraceItem

    pub struct SortTraceItem {
    id : String
    value : Int
    label : String
    } derive(Eq, ToJson,
    Debug
    )

    One stable value in a sortable sequence trace.

    SortTraceItem::equal

    SortTraceItem::new

    fn SortTraceItem::new(id~ : String, value~ : Int, label? : String) -> SortTraceItem

    SortTraceItem::not_equal

    fn SortTraceItem::not_equal(x : SortTraceItem, y : SortTraceItem) -> Bool

    SortTraceItem::to_json

    TargetRef

    pub struct TargetRef {
    object_id : String
    entity_id : String?
    } derive(Eq, ToJson,
    Debug
    ,
    FromJson
    )

    A scoped reference to either a scene object or one entity inside it.

    TargetRef::entity

    fn TargetRef::entity(object_id : String, entity_id : String) -> TargetRef

    TargetRef::equal

    fn TargetRef::equal(TargetRef, TargetRef) -> Bool

    TargetRef::not_equal

    fn TargetRef::not_equal(x : TargetRef, y : TargetRef) -> Bool

    TargetRef::object

    fn TargetRef::object(object_id : String) -> TargetRef

    TargetRef::to_json

    fn TargetRef::to_json(TargetRef) -> Json

    TargetUsage

    pub struct TargetUsage {
    object_id : String
    entity_id : String?
    references : Int
    event_references : Int
    highlight_references : Int
    first_step : Int
    last_step : Int
    event_names : Array[String]
    highlight_roles : Array[String]
    } derive(Eq, ToJson,
    Debug
    )

    Target-level references observed in semantic events and visual highlights.

    TargetUsage::equal

    fn TargetUsage::equal(TargetUsage, TargetUsage) -> Bool

    TargetUsage::new

    fn TargetUsage::new(object_id~ : String, entity_id? : String, references? : Int, event_references? : Int, highlight_references? : Int, first_step? : Int, last_step? : Int, event_names? : Array[String], highlight_roles? : Array[String]) -> TargetUsage

    TargetUsage::not_equal

    fn TargetUsage::not_equal(x : TargetUsage, y : TargetUsage) -> Bool

    TargetUsage::to_json

    fn TargetUsage::to_json(TargetUsage) -> Json

    TraceAttribute

    pub struct TraceAttribute {
    key : String
    value : String
    } derive(Eq, ToJson,
    Debug
    )

    A stable key/value attribute used by custom events and summaries.

    TraceAttribute::equal

    TraceAttribute::new

    fn TraceAttribute::new(key~ : String, value~ : String) -> TraceAttribute

    TraceAttribute::not_equal

    fn TraceAttribute::not_equal(x : TraceAttribute, y : TraceAttribute) -> Bool

    TraceAttribute::to_json

    TraceBreakpoint

    pub struct TraceBreakpoint {
    event_kind : String
    target : TargetRef?
    role : String
    changed_only : Bool
    } derive(Eq, ToJson,
    Debug
    )

    TraceBreakpoint::equal

    TraceBreakpoint::new

    fn TraceBreakpoint::new(event_kind? : String, target? : TargetRef, role? : String, changed_only? : Bool) -> TraceBreakpoint

    TraceBreakpoint::not_equal

    fn TraceBreakpoint::not_equal(x : TraceBreakpoint, y : TraceBreakpoint) -> Bool

    TraceBreakpoint::to_json

    TraceBreakpointHit

    pub struct TraceBreakpointHit {
    step : Int
    event_kind : String
    targets : Array[TargetRef]
    changes : Array[TraceChange]
    reason : String
    } derive(Eq, ToJson,
    Debug
    )

    TraceBreakpointHit::equal

    TraceBreakpointHit::not_equal

    TraceBreakpointHit::to_json

    TraceBuilder

    pub struct TraceBuilder {
    title : String
    algorithm : String
    description : String
    initial_scene : Scene
    steps : Array[AlgorithmTraceStep]
    options : TraceOptions
    completed : Bool
    } derive(
    Debug
    )

    Mutable recorder that stores immutable scene snapshots.

    TraceBuilder::finish

    fn TraceBuilder::finish(self : TraceBuilder, summary? : Array[TraceAttribute]) -> AlgorithmTrace raise TraceError

    TraceBuilder::new

    fn TraceBuilder::new(title~ : String, algorithm~ : String, description? : String, initial_scene~ : Scene, options? : TraceOptions) -> TraceBuilder raise TraceError

    TraceBuilder::record

    fn TraceBuilder::record(self : TraceBuilder, event~ : TraceEvent, scene~ : Scene, annotation? : Annotation) -> Unit raise TraceError

    TraceChange

    pub struct TraceChange {
    kind : TraceChangeKind
    target : TargetRef
    before_value : String
    after_value : String
    before_index : Int
    after_index : Int
    } derive(Eq, ToJson,
    Debug
    )

    TraceChange::equal

    fn TraceChange::equal(TraceChange, TraceChange) -> Bool

    TraceChange::new

    fn TraceChange::new(kind~ : TraceChangeKind, target~ : TargetRef, before_value? : String, after_value? : String, before_index? : Int, after_index? : Int) -> TraceChange

    TraceChange::not_equal

    fn TraceChange::not_equal(x : TraceChange, y : TraceChange) -> Bool

    TraceChange::to_json

    fn TraceChange::to_json(TraceChange) -> Json

    TraceChangeKind

    pub(all) enum TraceChangeKind {
    Added
    Removed
    Updated
    Moved
    HighlightAdded
    HighlightRemoved
    } derive(Eq, ToJson,
    Debug
    )

    TraceChangeKind::equal

    TraceChangeKind::not_equal

    fn TraceChangeKind::not_equal(x : TraceChangeKind, y : TraceChangeKind) -> Bool

    TraceChangeKind::to_json

    TraceContract

    pub struct TraceContract {
    name : String
    description : String
    checker : (AlgorithmTrace) -> Array[TraceViolation]
    }

    An extensible semantic contract backed by a pure MoonBit checker callback.

    TraceContract::check

    TraceContract::new

    fn TraceContract::new(name~ : String, description~ : String, checker~ : (AlgorithmTrace) -> Array[TraceViolation]) -> TraceContract

    TraceCounterexample

    pub struct TraceCounterexample {
    original_title : String
    original_start : Int
    original_focus : Int
    original_end : Int
    focus_step : Int
    trace : AlgorithmTrace
    } derive(Eq, ToJson,
    Debug
    )

    TraceCounterexample::equal

    TraceCounterexample::not_equal

    TraceCounterexample::to_json

    TraceCounterexample::to_json_string

    fn TraceCounterexample::to_json_string(self : TraceCounterexample) -> String

    TraceDiagnosis

    pub struct TraceDiagnosis {
    contract_report : ContractReport
    divergence : TraceDivergence?
    focus_step : Int
    transition_diff : TraceFrameDiff?
    reference_diff : TraceFrameDiff?
    focused_slice : TraceCounterexample?
    } derive(Eq, ToJson,
    Debug
    )

    The authoritative result of combining a semantic contract with an optional reference trace.

    TraceDiagnosis::equal

    TraceDiagnosis::not_equal

    fn TraceDiagnosis::not_equal(x : TraceDiagnosis, y : TraceDiagnosis) -> Bool

    TraceDiagnosis::passed

    fn TraceDiagnosis::passed(self : TraceDiagnosis) -> Bool

    Return whether both the semantic contract and optional reference agree.

    TraceDiagnosis::to_json

    TraceDivergence

    pub struct TraceDivergence {
    step : Int
    kind : TraceDivergenceKind
    message : String
    expected_event : String
    actual_event : String
    scene_diff : TraceFrameDiff?
    } derive(Eq, ToJson,
    Debug
    )

    TraceDivergence::equal

    TraceDivergence::not_equal

    fn TraceDivergence::not_equal(x : TraceDivergence, y : TraceDivergence) -> Bool

    TraceDivergence::to_json

    TraceDivergence::to_json_string

    fn TraceDivergence::to_json_string(self : TraceDivergence) -> String

    TraceDivergenceKind

    pub(all) enum TraceDivergenceKind {
    EventMismatch
    SceneMismatch
    ExpectedEnded
    ActualEnded
    } derive(Eq, ToJson,
    Debug
    )

    TraceDivergenceKind::equal

    TraceDivergenceKind::not_equal

    TraceDivergenceKind::to_json

    TraceEvent

    pub(all) enum TraceEvent {
    Initialize
    Compare(Array[TargetRef])
    Swap(TargetRef, TargetRef)
    Visit(TargetRef)
    Update(TargetRef, String)
    Union(TargetRef, TargetRef)
    Relax(TargetRef, TargetRef, String)
    Complete
    Custom(String, Array[TraceAttribute])
    } derive(Eq, ToJson,
    Debug
    )

    The semantic reason why an algorithm produced a new scene.

    TraceEvent::equal

    fn TraceEvent::equal(TraceEvent, TraceEvent) -> Bool

    TraceEvent::not_equal

    fn TraceEvent::not_equal(x : TraceEvent, y : TraceEvent) -> Bool

    TraceEvent::to_json

    fn TraceEvent::to_json(TraceEvent) -> Json

    TraceFrameDiff

    pub struct TraceFrameDiff {
    from_step : Int
    to_step : Int
    changes : Array[TraceChange]
    } derive(Eq, ToJson,
    Debug
    )

    TraceFrameDiff::equal

    TraceFrameDiff::is_empty

    fn TraceFrameDiff::is_empty(self : TraceFrameDiff) -> Bool

    TraceFrameDiff::not_equal

    fn TraceFrameDiff::not_equal(x : TraceFrameDiff, y : TraceFrameDiff) -> Bool

    TraceFrameDiff::report

    fn TraceFrameDiff::report(self : TraceFrameDiff) -> String

    TraceFrameDiff::to_json

    TraceFrameDiff::to_json_string

    fn TraceFrameDiff::to_json_string(self : TraceFrameDiff) -> String

    TraceLevel

    pub(all) enum TraceLevel {
    Off
    Count
    Full
    } derive(Eq, ToJson,
    Debug
    )

    How much an automatic tracer records while the algorithm runs.

    TraceLevel::equal

    fn TraceLevel::equal(TraceLevel, TraceLevel) -> Bool

    TraceLevel::not_equal

    fn TraceLevel::not_equal(x : TraceLevel, y : TraceLevel) -> Bool

    TraceLevel::to_json

    fn TraceLevel::to_json(TraceLevel) -> Json

    TraceLintIssue

    pub struct TraceLintIssue {
    severity : TraceLintSeverity
    code : String
    message : String
    step : Int
    } derive(Eq, ToJson,
    Debug
    )

    A non-throwing quality observation for a trace document.

    TraceLintIssue::equal

    TraceLintIssue::is_error

    fn TraceLintIssue::is_error(self : TraceLintIssue) -> Bool

    TraceLintIssue::is_info

    fn TraceLintIssue::is_info(self : TraceLintIssue) -> Bool

    TraceLintIssue::is_warning

    fn TraceLintIssue::is_warning(self : TraceLintIssue) -> Bool

    TraceLintIssue::line

    fn TraceLintIssue::line(self : TraceLintIssue) -> String

    TraceLintIssue::markdown_row

    fn TraceLintIssue::markdown_row(self : TraceLintIssue) -> String

    TraceLintIssue::new

    fn TraceLintIssue::new(severity~ : TraceLintSeverity, code~ : String, message~ : String, step? : Int) -> TraceLintIssue

    TraceLintIssue::not_equal

    fn TraceLintIssue::not_equal(x : TraceLintIssue, y : TraceLintIssue) -> Bool

    TraceLintIssue::severity_name

    fn TraceLintIssue::severity_name(self : TraceLintIssue) -> String

    TraceLintIssue::to_json

    TraceLintSeverity

    pub(all) enum TraceLintSeverity {
    Info
    Warning
    Error
    } derive(Eq, ToJson,
    Debug
    )

    Severity for lightweight trace quality checks.

    TraceLintSeverity::equal

    TraceLintSeverity::not_equal

    fn TraceLintSeverity::not_equal(x : TraceLintSeverity, y : TraceLintSeverity) -> Bool

    TraceLintSeverity::to_json

    TraceOptions

    pub struct TraceOptions {
    max_steps : Int
    max_entities_per_scene : Int
    } derive(Eq, ToJson,
    Debug
    ,
    FromJson
    )

    TraceOptions::default

    fn TraceOptions::default() -> TraceOptions

    TraceOptions::equal

    TraceOptions::new

    fn TraceOptions::new(max_steps? : Int, max_entities_per_scene? : Int) -> TraceOptions raise TraceError

    TraceOptions::not_equal

    fn TraceOptions::not_equal(x : TraceOptions, y : TraceOptions) -> Bool

    TraceOptions::to_json

    TraceStats

    pub struct TraceStats {
    title : String
    algorithm : String
    step_count : Int
    completed : Bool
    event_counts : Array[EventCount]
    object_usage : Array[ObjectUsage]
    target_usage : Array[TargetUsage]
    initial_object_count : Int
    max_objects_per_scene : Int
    max_entities_per_scene : Int
    summary_count : Int
    annotation_count : Int
    custom_event_count : Int
    highlight_count : Int
    } derive(Eq, ToJson,
    Debug
    )

    Summary of a full trace document, suitable for docs, CLI output, or CI smoke checks before rendering.

    TraceStats::equal

    fn TraceStats::equal(TraceStats, TraceStats) -> Bool

    TraceStats::event_count

    fn TraceStats::event_count(self : TraceStats, name : String) -> Int

    TraceStats::event_table

    fn TraceStats::event_table(self : TraceStats) -> String

    Render the event section of TraceStats as a Markdown table.

    TraceStats::not_equal

    fn TraceStats::not_equal(x : TraceStats, y : TraceStats) -> Bool

    TraceStats::object_count

    fn TraceStats::object_count(self : TraceStats, object_id : String) -> Int

    TraceStats::object_table

    fn TraceStats::object_table(self : TraceStats) -> String

    Render the object section of TraceStats as a Markdown table.

    TraceStats::summary_report

    fn TraceStats::summary_report(self : TraceStats) -> String

    TraceStats::target_count

    fn TraceStats::target_count(self : TraceStats, object_id : String, entity_id? : String) -> Int

    TraceStats::target_table

    fn TraceStats::target_table(self : TraceStats, limit? : Int) -> String

    Render the most referenced targets as a Markdown table.

    TraceStats::to_json

    fn TraceStats::to_json(TraceStats) -> Json

    TraceStats::to_markdown

    fn TraceStats::to_markdown(self : TraceStats, target_limit? : Int) -> String

    Render the full analysis as Markdown for READMEs, reports, and CI artifacts.

    TraceStats::top_targets

    fn TraceStats::top_targets(self : TraceStats, limit? : Int) -> Array[TargetUsage]

    TraceStep

    pub struct TraceStep {
    current : Position?
    frontier : Array[Position]
    visited : Array[Position]
    cost : Array[CostEntry]
    parent : Array[ParentLink]
    } derive(Eq, ToJson,
    Debug
    )

    TraceStep::equal

    fn TraceStep::equal(TraceStep, TraceStep) -> Bool

    TraceStep::new

    fn TraceStep::new(current~ : Position?, frontier~ : Array[Position], visited~ : Array[Position], cost~ : Array[CostEntry], parent~ : Array[ParentLink]) -> TraceStep

    TraceStep::not_equal

    fn TraceStep::not_equal(x : TraceStep, y : TraceStep) -> Bool

    TraceStep::to_json

    fn TraceStep::to_json(TraceStep) -> Json

    TraceTimelineEntry

    pub struct TraceTimelineEntry {
    step : Int
    event_name : String
    target_count : Int
    object_count : Int
    entity_count : Int
    highlight_count : Int
    annotation_title : String
    completed : Bool
    } derive(Eq, ToJson,
    Debug
    )

    A compact row describing one renderable point in a trace timeline.

    TraceTimelineEntry::equal

    TraceTimelineEntry::label

    fn TraceTimelineEntry::label(self : TraceTimelineEntry) -> String

    TraceTimelineEntry::markdown_row

    fn TraceTimelineEntry::markdown_row(self : TraceTimelineEntry) -> String

    TraceTimelineEntry::new

    fn TraceTimelineEntry::new(step~ : Int, event_name~ : String, target_count~ : Int, object_count~ : Int, entity_count~ : Int, highlight_count~ : Int, annotation_title? : String, completed? : Bool) -> TraceTimelineEntry

    TraceTimelineEntry::not_equal

    TraceTimelineEntry::to_json

    TraceViolation

    pub struct TraceViolation {
    contract : String
    code : String
    severity : TraceViolationSeverity
    step : Int
    targets : Array[TargetRef]
    message : String
    evidence : Array[TraceAttribute]
    } derive(Eq, ToJson,
    Debug
    )

    TraceViolation::equal

    TraceViolation::new

    fn TraceViolation::new(contract~ : String, code~ : String, severity? : TraceViolationSeverity, step? : Int, targets? : Array[TargetRef], message~ : String, evidence? : Array[TraceAttribute]) -> TraceViolation

    TraceViolation::not_equal

    fn TraceViolation::not_equal(x : TraceViolation, y : TraceViolation) -> Bool

    TraceViolation::to_json

    TraceViolationSeverity

    pub(all) enum TraceViolationSeverity {
    Warning
    Error
    } derive(Eq, ToJson,
    Debug
    )

    TraceViolationSeverity::equal

    TraceViolationSeverity::not_equal

    TraceViolationSeverity::to_json

    TracedArray

    pub struct TracedArray[T] {
    // private fields
    }

    An array that records what an algorithm does to it.

    Write the algorithm against TracedArray instead of Array: indexing, swap, less, and compare record Compare, Swap, and Update events with stable element ids, so no TraceBuilder code is needed. Reads are counted but not recorded as steps. Use less or compare instead of a[i] < a[j], which reads the values without recording a comparison.

    TracedArray::compare

    fn[T : Compare + Eq] TracedArray::compare(self : TracedArray[T], i : Int, j : Int) -> Int

    Compares two positions like Compare::compare and records a Compare.

    TracedArray::counts

    fn[T] TracedArray::counts(self : TracedArray[T]) -> OperationCounts

    TracedArray::finish

    fn[T] TracedArray::finish(self : TracedArray[T]) -> AlgorithmTrace raise TraceError

    Completes the trace. Raises the first recording error, or InvalidStep when the array was not created at TraceLevel::Full.

    TracedArray::get

    #alias("_[_]")
    fn[T] TracedArray::get(self : TracedArray[T], index : Int) -> T

    TracedArray::length

    fn[T] TracedArray::length(self : TracedArray[T]) -> Int

    TracedArray::less

    fn[T : Compare + Eq] TracedArray::less(self : TracedArray[T], i : Int, j : Int) -> Bool

    Returns whether position i is less than position j, recording a Compare.

    TracedArray::new

    fn[T : Show] TracedArray::new(values : Array[T], title? : String, algorithm? : String, object_id? : String, label? : String, level? : TraceLevel, options? : TraceOptions) -> TracedArray[T]

    TracedArray::set

    #alias("_[_]=_")
    fn[T : Show] TracedArray::set(self : TracedArray[T], index : Int, value : T) -> Unit

    TracedArray::swap

    fn[T] TracedArray::swap(self : TracedArray[T], i : Int, j : Int) -> Unit

    Exchanges two positions and records a Swap.

    TracedArray::to_array

    fn[T] TracedArray::to_array(self : TracedArray[T]) -> Array[T]

    Returns a copy of the current values without counting reads.

    UnionOperation

    pub struct UnionOperation {
    left : Int
    right : Int
    label : String
    } derive(Eq, ToJson,
    Debug
    )

    One union operation for the Union-Find trace adapter.

    UnionOperation::equal

    UnionOperation::new

    fn UnionOperation::new(left~ : Int, right~ : Int, label? : String) -> UnionOperation

    UnionOperation::not_equal

    fn UnionOperation::not_equal(x : UnionOperation, y : UnionOperation) -> Bool

    UnionOperation::to_json

    WeightedCell

    type WeightedCell derive(Eq, ToJson,
    Debug
    )

    WeightedCell::equal

    WeightedCell::not_equal

    fn WeightedCell::not_equal(x : WeightedCell, y : WeightedCell) -> Bool

    WeightedCell::to_json

    astar

    fn astar(grid : GridMap, start~ : Position, goal~ : Position, rule? : MoveRule, heuristic? : Heuristic) -> PathResult raise

    astar_trace

    fn astar_trace(grid : GridMap, start~ : Position, goal~ : Position, rule? : MoveRule, heuristic? : Heuristic) -> SearchTrace raise

    bfs

    fn bfs(grid : GridMap, start~ : Position, goal~ : Position, rule? : MoveRule) -> PathResult raise

    bfs_trace

    fn bfs_trace(grid : GridMap, start~ : Position, goal~ : Position, rule? : MoveRule) -> SearchTrace raise

    coin_change_dp_trace

    fn coin_change_dp_trace(coins : Array[Int], amount : Int, title? : String, object_id? : String, label? : String, options? : TraceOptions) -> AlgorithmTrace raise TraceError

    Build a one-dimensional minimum-coin-change dynamic-programming trace.

    compare_algorithms

    fn compare_algorithms(grid : GridMap, start~ : Position, goal~ : Position, rule? : MoveRule, heuristic? : Heuristic) -> CompareReport raise

    debug_report_version

    let debug_report_version : String

    Stable version marker for machine-readable debugger reports.

    diagnose_trace

    fn diagnose_trace(actual : AlgorithmTrace, contract~ : TraceContract, expected? : AlgorithmTrace) -> TraceDiagnosis

    Diagnose an actual trace with a contract and an optional reference trace.

    The focus is the earliest non-negative contract failure or divergence. transition_diff describes the actual transition into that focus, while reference_diff compares expected and actual state at the focus.

    dijkstra

    fn dijkstra(grid : GridMap, start~ : Position, goal~ : Position, rule? : MoveRule) -> PathResult raise

    dijkstra_trace

    fn dijkstra_trace(grid : GridMap, start~ : Position, goal~ : Position, rule? : MoveRule) -> SearchTrace raise

    export_ascii

    fn export_ascii(grid : GridMap, start~ : Position, goal~ : Position, trace? : SearchTrace) -> String

    export_svg

    fn export_svg(grid : GridMap, start~ : Position, goal~ : Position, trace? : SearchTrace, cell_size? : Int) -> String

    faulty_insertion_sort_demo_trace

    fn faulty_insertion_sort_demo_trace() -> AlgorithmTrace raise

    Build an intentionally faulty trace for debugger and contract demos.

    fibonacci_dp_trace

    fn fibonacci_dp_trace(n : Int, title? : String, object_id? : String, label? : String, options? : TraceOptions) -> AlgorithmTrace raise TraceError

    Build a Fibonacci dynamic-programming trace for F(n).

    first_divergence

    fn first_divergence(expected : AlgorithmTrace, actual : AlgorithmTrace) -> TraceDivergence?

    grid_path_contract

    fn grid_path_contract(object_id~ : String) -> TraceContract

    heuristic_distance

    fn heuristic_distance(kind : Heuristic, from : Position, to : Position) -> Int

    insertion_sort_demo_trace

    fn insertion_sort_demo_trace(values : Array[Int]) -> AlgorithmTrace raise

    Build the insertion-sort trace used by the bundled demo and CLI.

    insertion_sort_int_contract

    fn insertion_sort_int_contract(object_id~ : String) -> TraceContract

    insertion_sort_items_trace

    fn insertion_sort_items_trace(items : Array[SortTraceItem], title? : String, object_id? : String, label? : String) -> AlgorithmTrace raise TraceError

    Build an insertion-sort trace while preserving caller-provided stable item ids. Stable ids make animated swaps and external annotations deterministic.

    insertion_sort_trace

    fn insertion_sort_trace(values : Array[Int], title? : String, object_id? : String, label? : String) -> AlgorithmTrace raise TraceError

    Build a reusable insertion-sort trace from plain integer values.

    lcs_dp_trace

    fn lcs_dp_trace(left : String, right : String, title? : String, object_id? : String, label? : String, options? : TraceOptions) -> AlgorithmTrace raise TraceError

    Build a two-dimensional longest-common-subsequence trace.

    pathfinding_demo_trace

    fn pathfinding_demo_trace() -> AlgorithmTrace raise

    Build the A* flagship trace used by the bundled demo and CLI.

    project_name

    let project_name : String

    Human-readable project name.

    red_black_tree_trace

    fn red_black_tree_trace(operations : Array[RedBlackTreeOperation], title? : String, object_id? : String, label? : String, options? : TraceOptions) -> AlgorithmTrace raise TraceError

    Build a red-black-tree trace with insertion balancing and lookup paths.

    render_trace_html

    fn render_trace_html(trace : AlgorithmTrace) -> String

    Render a trace as a self-contained offline HTML player.

    render_trace_playground

    fn render_trace_playground() -> String raise TraceError

    Render the self-contained AI Trace Clinic.

    The page intentionally has no framework, server, or external asset. Its default evidence mirrors fixtures/agent-traces: a selection-sort trace whose stale-index swap first diverges at step 10.

    render_trace_svg

    #deprecated("Legacy static renderer; use render_trace_html or Schema v1 JSON. This API will be removed in v1.0.")
    fn render_trace_svg(trace : AlgorithmTrace, step? : Int, width? : Int) -> String raise

    Render one trace frame as a deterministic, standalone SVG document.

    render_trace_svg_frames

    #deprecated("Legacy static renderer; use render_trace_html or Schema v1 JSON. This API will be removed in v1.0.")
    fn render_trace_svg_frames(trace : AlgorithmTrace, width? : Int) -> Array[String] raise

    Render every recorded step. An empty trace yields its initial scene.

    search_trace_to_algorithm_trace

    fn search_trace_to_algorithm_trace(grid : GridMap, start~ : Position, goal~ : Position, algorithm~ : String, trace~ : SearchTrace) -> AlgorithmTrace raise

    Convert a legacy path-search trace into the generic visualization protocol.

    sequence_transition_contract

    fn sequence_transition_contract(object_id~ : String) -> TraceContract

    sorted_int_sequence_contract

    fn sorted_int_sequence_contract(object_id~ : String) -> TraceContract

    Check stable sequence transitions and a nondecreasing integer result.

    Unlike insertion_sort_int_contract, this name is algorithm-neutral and is suitable for selection sort, merge sort, agent-generated traces, and other sorting implementations.

    union_find_demo_trace

    fn union_find_demo_trace() -> AlgorithmTrace raise

    Build the Union-Find trace used by the bundled demo and CLI.

    union_find_trace

    fn union_find_trace(size : Int, operations : Array[UnionOperation], title? : String, object_id? : String, label? : String, compress_paths? : Bool) -> AlgorithmTrace raise TraceError

    Build a reusable Union-Find trace from a size and an ordered operation list.

    zero_one_knapsack_dp_trace

    fn zero_one_knapsack_dp_trace(weights : Array[Int], values : Array[Int], capacity : Int, title? : String, object_id? : String, label? : String, options? : TraceOptions) -> AlgorithmTrace raise TraceError

    Build a two-dimensional 0/1-knapsack dynamic-programming trace.

    Powered by MoonBit

    Site sourceReport issueModulesSkillsBuild queueStatistics

    © 2026 mooncakes.io