A MoonBit algorithm trace protocol and offline HTML/SVG visualization kit.
当前正式版本是 v0.7.0,发布于 GitHub 与 Mooncakes;GitHub Pages 提供同版本的离线 AI Trace Clinic。Gitlink 镜像单独维护,不由此状态推断。
# 1. 对冻结的正确/错误轨迹执行契约、首次分歧与反例切片
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. 生成完全离线、单文件的 AI Trace Clinic
moon run cmd/main -- playground --output _build/playground.html
# 3. 独立消费者只从 Mooncakes v0.6.0 解析依赖并复现实例
cd consumer/frontierlab_consumer_demo && moon test --target all --deny-warnflowchart LR
A["导入错误轨迹"] --> B["Schema / 契约检查"]
B --> C["首次分歧 step 10"]
C --> D["实际变化 vs 参考差异"]
D --> E["聚焦反例切片 JSON"]
E --> F["可复制修复提示"]
Set-Location D:\Code\Moonbit\frontierlab
Start-Process .\docs\playground.htmlpython scripts\build_cli.py
.\_dist\frontierlab.exe --versionmoon 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
python scripts/validate_cli.py
moon package --list
moon packagepub struct AlgorithmTrace {
schema_version : String
title : String
algorithm : String
description : String
initial_scene : Scene
steps : Array[AlgorithmTraceStep]
summary : Array[TraceAttribute]
} derive(Eq, ToJson, Debug)fn AlgorithmTrace::breakpoint_hits(self : AlgorithmTrace, breakpoint : TraceBreakpoint) -> Array[TraceBreakpointHit]fn AlgorithmTrace::decode_json(input : StringView, options? : TraceOptions) -> AlgorithmTrace raise TraceErrorfn AlgorithmTrace::diff(self : AlgorithmTrace, from_step~ : Int, to_step~ : Int) -> TraceFrameDiff raise TraceErrorfn AlgorithmTrace::slice(self : AlgorithmTrace, center~ : Int, before? : Int, after? : Int) -> TraceCounterexample raise TraceErrorfn AlgorithmTrace::validate(self : AlgorithmTrace, options? : TraceOptions) -> Unit raise TraceErrorpub struct AlgorithmTraceStep {
index : Int
event : TraceEvent
scene : Scene
annotation : Annotation?
} derive(Eq, ToJson, Debug)pub struct ContractReport {
report_version : String
contract_name : String
passed : Bool
violations : Array[TraceViolation]
first_failure : TraceViolation?
counterexample : TraceCounterexample?
} derive(Eq, ToJson, Debug)fn GraphState::new(id~ : String, label~ : String, nodes~ : Array[GraphNode], edges~ : Array[GraphEdge]) -> GraphState raise TraceErrorfn GridCellState::new(id~ : String, x~ : Int, y~ : Int, label? : String, blocked? : Bool) -> GridCellStatepub struct GridState {
id : String
label : String
width : Int
height : Int
cells : Array[GridCellState]
} derive(Eq, ToJson, Debug)fn GridState::new(id~ : String, label~ : String, width~ : Int, height~ : Int, cells~ : Array[GridCellState]) -> GridState raise TraceErrorfn ObjectUsage::new(object_id~ : String, object_kind~ : String, appearances? : Int, max_entities? : Int, first_step? : Int, last_step? : Int) -> ObjectUsagefn Scene::new(objects~ : Array[SceneObject], highlights? : Array[Highlight]) -> Scene raise TraceErrorpub(all) enum SceneObject {
Sequence(SequenceState)
Sets(SetState)
Graph(GraphState)
Grid(GridState)
} derive(Eq, ToJson, Debug)pub struct SequenceState {
id : String
label : String
items : Array[SequenceItem]
} derive(Eq, ToJson, Debug)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]) -> TargetUsagefn TraceBreakpoint::new(event_kind? : String, target? : TargetRef, role? : String, changed_only? : Bool) -> TraceBreakpointpub struct TraceBuilder {
title : String
algorithm : String
description : String
initial_scene : Scene
steps : Array[AlgorithmTraceStep]
options : TraceOptions
completed : Bool
} derive(Debug)fn TraceBuilder::finish(self : TraceBuilder, summary? : Array[TraceAttribute]) -> AlgorithmTrace raise TraceErrorfn TraceBuilder::new(title~ : String, algorithm~ : String, description? : String, initial_scene~ : Scene, options? : TraceOptions) -> TraceBuilder raise TraceErrorfn TraceBuilder::record(self : TraceBuilder, event~ : TraceEvent, scene~ : Scene, annotation? : Annotation) -> Unit raise TraceErrorpub struct TraceChange {
kind : TraceChangeKind
target : TargetRef
before_value : String
after_value : String
before_index : Int
after_index : Int
} derive(Eq, ToJson, Debug)fn TraceChange::new(kind~ : TraceChangeKind, target~ : TargetRef, before_value? : String, after_value? : String, before_index? : Int, after_index? : Int) -> TraceChangepub struct TraceContract {
name : String
description : String
checker : (AlgorithmTrace) -> Array[TraceViolation]
}fn TraceContract::new(name~ : String, description~ : String, checker~ : (AlgorithmTrace) -> Array[TraceViolation]) -> TraceContractpub struct TraceCounterexample {
original_title : String
original_start : Int
original_focus : Int
original_end : Int
focus_step : Int
trace : AlgorithmTrace
} derive(Eq, ToJson, Debug)pub struct TraceDiagnosis {
contract_report : ContractReport
divergence : TraceDivergence?
focus_step : Int
transition_diff : TraceFrameDiff?
reference_diff : TraceFrameDiff?
focused_slice : TraceCounterexample?
} derive(Eq, ToJson, Debug)pub struct TraceDivergence {
step : Int
kind : TraceDivergenceKind
message : String
expected_event : String
actual_event : String
scene_diff : TraceFrameDiff?
} derive(Eq, ToJson, Debug)pub struct TraceFrameDiff {
from_step : Int
to_step : Int
changes : Array[TraceChange]
} derive(Eq, ToJson, Debug)pub struct TraceLintIssue {
severity : TraceLintSeverity
code : String
message : String
step : Int
} derive(Eq, ToJson, Debug)fn TraceLintIssue::new(severity~ : TraceLintSeverity, code~ : String, message~ : String, step? : Int) -> TraceLintIssuefn TraceOptions::new(max_steps? : Int, max_entities_per_scene? : Int) -> TraceOptions raise TraceErrorpub 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)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) -> TraceTimelineEntrypub struct TraceViolation {
contract : String
code : String
severity : TraceViolationSeverity
step : Int
targets : Array[TargetRef]
message : String
evidence : Array[TraceAttribute]
} derive(Eq, ToJson, Debug)fn TraceViolation::new(contract~ : String, code~ : String, severity? : TraceViolationSeverity, step? : Int, targets? : Array[TargetRef], message~ : String, evidence? : Array[TraceAttribute]) -> TraceViolationfn bfs_trace(grid : GridMap, start~ : Position, goal~ : Position, rule? : MoveRule) -> SearchTrace raiselet debug_report_version : Stringfn diagnose_trace(actual : AlgorithmTrace, contract~ : TraceContract, expected? : AlgorithmTrace) -> TraceDiagnosisfn dijkstra(grid : GridMap, start~ : Position, goal~ : Position, rule? : MoveRule) -> PathResult raisefn dijkstra_trace(grid : GridMap, start~ : Position, goal~ : Position, rule? : MoveRule) -> SearchTrace raisefn export_ascii(grid : GridMap, start~ : Position, goal~ : Position, trace? : SearchTrace) -> Stringfn export_svg(grid : GridMap, start~ : Position, goal~ : Position, trace? : SearchTrace, cell_size? : Int) -> Stringfn insertion_sort_items_trace(items : Array[SortTraceItem], title? : String, object_id? : String, label? : String) -> AlgorithmTrace raise TraceErrorfn insertion_sort_trace(values : Array[Int], title? : String, object_id? : String, label? : String) -> AlgorithmTrace raise TraceErrorfn search_trace_to_algorithm_trace(grid : GridMap, start~ : Position, goal~ : Position, algorithm~ : String, trace~ : SearchTrace) -> AlgorithmTrace raisefn union_find_trace(size : Int, operations : Array[UnionOperation], title? : String, object_id? : String, label? : String, compress_paths? : Bool) -> AlgorithmTrace raise TraceErrorInstall
Download zipA MoonBit algorithm trace protocol and offline HTML/SVG visualization kit.