A YAML-to-DAG workflow compiler that uses Kahn's topological sort to determine execution order, detect cycles, and identify steps that can run in parallel.
Implements the core algorithm described in the "Workflow DAG Compiler" patent (March 2026) by 577 Industries.
┌──────────┐
YAML Definition → │ Parser │
└────┬─────┘
│
┌────▼─────┐
│ Compiler │ ← Kahn's Algorithm
└────┬─────┘
│
┌──────────┼──────────┐
│ │ │
┌────▼───┐ ┌───▼────┐ ┌──▼───────┐
│ Order │ │ Groups │ │ Mermaid │
└────────┘ └────────┘ └──────────┘
npm install @577-industries/workflow-dagimport { parseYaml, compileWorkflow, toMermaid } from "@577-industries/workflow-dag";
const yaml = `
name: deploy-pipeline
steps:
- id: build
task: compile_code
- id: test_unit
task: run_unit_tests
depends_on: [build]
- id: test_e2e
task: run_e2e_tests
depends_on: [build]
- id: deploy
task: deploy_to_prod
depends_on: [test_unit, test_e2e]
`;
const definition = parseYaml(yaml);
const dag = compileWorkflow(definition);
console.log(dag.executionOrder);
// → ["build", "test_unit", "test_e2e", "deploy"]
console.log(dag.parallelGroups);
// → [["build"], ["test_unit", "test_e2e"], ["deploy"]]
console.log(toMermaid(dag));
// → graph TD
// build["compile_code"]
// test_unit["run_unit_tests"]
// ...Parses a YAML string into a validated workflow definition.
Compiles a workflow definition into a DAG with execution order and parallel groups. Throws CycleDetectedError if a cycle exists, or InvalidDependencyError if a step references a nonexistent dependency.
Generates a Mermaid graph diagram from a compiled DAG.
Dry-runs the DAG, estimating total execution time based on step timeouts and parallelism.
| Type | Description |
|---|---|
WorkflowDefinition |
Input workflow with name, steps, and metadata |
WorkflowStep |
A single step: id, task, depends_on, condition, timeout |
DagNode |
Compiled node with resolved dependencies |
CompiledDag |
Full compilation result: nodes, order, parallel groups |
SimulationResult |
Dry-run result with group timing estimates |
| Error | When |
|---|---|
CycleDetectedError |
Workflow contains circular dependencies |
InvalidDependencyError |
Step references a nonexistent dependency |
This library implements Kahn's algorithm for topological sorting:
- Parse — YAML → validated WorkflowDefinition
- Build adjacency — compute in-degree for each node
- Process zero-degree nodes — in batches (each batch = parallel group)
- Detect cycles — if unprocessed nodes remain after sort, a cycle exists
Based on the "Workflow DAG Compiler" patent by 577 Industries.
Extracted from FORGE OS by 577 Industries.