A MoonBit task graph and provenance trace library for reproducible research and agent workflows.
///|
test {
let graph = FlowGraph::new()
guard graph.add_task(TaskNode::new("collect_papers", "Collect papers"))
is Ok(_) else {
fail("expected first task")
}
guard graph.add_task(TaskNode::new("write_report", "Write report")) is Ok(_) else {
fail("expected second task")
}
guard graph.add_dependency(
TaskId::new("collect_papers"),
TaskId::new("write_report"),
)
is Ok(_) else {
fail("expected dependency")
}
guard graph.plan() is Ok(plan) else { fail("expected valid graph") }
debug_inspect(plan.order().length(), content="2")
debug_inspect(plan.batches().length(), content="2")
guard graph.roots() is Ok(roots) else { fail("expected roots") }
guard graph.leaves() is Ok(leaves) else { fail("expected leaves") }
debug_inspect(roots[0].value(), content="\"collect_papers\"")
debug_inspect(leaves[0].value(), content="\"write_report\"")
guard graph.to_mermaid() is Ok(mermaid) else { fail("expected Mermaid") }
debug_inspect(mermaid.contains("task_0 --> task_1"), content="true")
let trace = Trace::new()
guard graph.to_json_checked(plan, trace) is Ok(snapshot) else {
fail("expected checked JSON")
}
debug_inspect(snapshot.contains("\"schema_version\": 1"), content="true")
guard RunSnapshot::from_json(snapshot) is Ok(imported_snapshot) else {
fail("expected run snapshot import")
}
debug_inspect(imported_snapshot.audit() is Ok(_), content="true")
let workflow_json = graph.to_workflow_spec().to_json()
guard FlowGraph::from_workflow_json(workflow_json) is Ok(round_trip) else {
fail("expected workflow import")
}
debug_inspect(round_trip.task_count(), content="2")
}fn FlowGraph::add_dependency(self : FlowGraph, before : TaskId, after : TaskId) -> Result[Unit, GraphError]fn FlowGraph::to_json_checked(self : FlowGraph, plan : ExecutionPlan, trace : Trace) -> Result[String, SnapshotError]fn FlowGraph::to_markdown_checked(self : FlowGraph, plan : ExecutionPlan, trace : Trace) -> Result[String, SnapshotError]fn FlowGraph::transition_status(self : FlowGraph, id : TaskId, status : TaskStatus) -> Result[Unit, StatusTransitionError]fn FlowGraph::update_status(self : FlowGraph, id : TaskId, status : TaskStatus) -> Result[Unit, GraphError]fn FlowGraph::validate_snapshot(self : FlowGraph, plan : ExecutionPlan, trace : Trace) -> Result[Unit, SnapshotError]pub(all) enum GraphError {
DuplicateTask(TaskId)
DuplicateDependency(Dependency)
MissingTask(TaskId)
MissingDependencyEndpoint(Dependency)
CycleDetected(Array[TaskId])
} derive(Eq, Debug)pub(all) enum RunSnapshotError {
InvalidRunSnapshotJson(String)
UnsupportedRunSnapshotSchema(String)
MissingRunSnapshotField(String)
InvalidRunSnapshotField(String)
RunSnapshotGraphError(GraphError)
RunSnapshotPlanMismatch
RunSnapshotUnknownTraceTask(TaskId)
InvalidTraceLifecycle(TaskId, TraceEventType)
RunSnapshotStatusMismatch(TaskId, TaskStatus, String)
} derive(Eq, Debug)pub(all) enum SnapshotError {
SnapshotGraphError(GraphError)
StaleExecutionPlan
UnknownTraceTask(TaskId)
} derive(Eq, Debug)pub(all) enum StatusTransitionError {
TransitionMissingTask(TaskId)
InvalidStatusTransition(TaskId, TaskStatus, TaskStatus)
} derive(Eq, Debug)fn TraceEvent::new(task_id : TaskId, event_type : TraceEventType, message : String, timestamp : String) -> TraceEventfn WorkflowSpec::new(tasks : Array[WorkflowTaskSpec], dependencies : Array[Dependency]) -> WorkflowSpecpub(all) enum WorkflowSpecError {
InvalidWorkflowJson(String)
UnsupportedWorkflowSchema(String)
MissingWorkflowField(String)
InvalidWorkflowField(String)
WorkflowGraphError(GraphError)
} derive(Eq, Debug)fn WorkflowTaskSpec::with_description(self : WorkflowTaskSpec, description : String) -> WorkflowTaskSpecfn WorkflowTaskSpec::with_inputs(self : WorkflowTaskSpec, inputs : Array[String]) -> WorkflowTaskSpecfn WorkflowTaskSpec::with_outputs(self : WorkflowTaskSpec, outputs : Array[String]) -> WorkflowTaskSpecA MoonBit task graph and provenance trace library for reproducible research and agent workflows.