Runic.Workflow.Serializer behaviour (Runic v0.1.0-alpha.7)

Copy Markdown View Source

Behaviour for workflow serialization to various graph formats.

Implements serializers for:

  • Mermaid (flowcharts and sequence diagrams)
  • DOT (Graphviz)
  • Cytoscape.js (JSON elements)
  • Edgelist (simple edge pairs)

Usage

# Serialize workflow structure (excludes memory/runtime state)
Runic.Workflow.Serializer.Mermaid.serialize(workflow)

# Serialize causal reactions (for sequence diagrams)
Runic.Workflow.Serializer.Mermaid.serialize_causal(workflow)

Edge Labels

The workflow graph uses a multigraph with labeled edges:

  • :flow - Static dataflow connections between steps
  • :component_of - Component hierarchy (with :kind in properties)
  • :produced / :state_produced / :reduced - Causal memory edges
  • :matchable / :runnable / :ran / :satisfied - Runtime state edges

Summary

Functions

Returns causal memory edges for sequence diagram generation.

Escapes special characters for Mermaid labels.

Returns flow edges only (static dataflow, no memory).

Groups vertices by their parent component using :component_of edges. Returns a map of %{component => [child_vertices]}.

Returns all vertices that are invokable nodes (not facts or memory).

Returns Mermaid CSS class based on node type.

Returns a unique, Mermaid-safe node ID for a vertex.

Returns a display label for a vertex node.

Returns the node shape for Mermaid based on node type.

Types

serialization_opts()

@type serialization_opts() :: [
  include_memory: boolean(),
  include_facts: boolean(),
  direction: :TB | :LR | :BT | :RL,
  title: String.t() | nil
]

Callbacks

serialize(t, serialization_opts)

@callback serialize(Runic.Workflow.t(), serialization_opts()) ::
  String.t() | map() | list()

Functions

causal_edges(workflow)

Returns causal memory edges for sequence diagram generation.

escape_label(label)

Escapes special characters for Mermaid labels.

flow_edges(workflow)

Returns flow edges only (static dataflow, no memory).

group_by_component(workflow)

Groups vertices by their parent component using :component_of edges. Returns a map of %{component => [child_vertices]}.

invokable_vertices(workflow)

Returns all vertices that are invokable nodes (not facts or memory).

node_class(arg1)

Returns Mermaid CSS class based on node type.

node_id(hash)

Returns a unique, Mermaid-safe node ID for a vertex.

node_label(other)

Returns a display label for a vertex node.

node_shape(arg1)

Returns the node shape for Mermaid based on node type.