AgentSkillsCN

@ruvector/rudag

采用 Rust/WASM 的快速 DAG 库,支持拓扑排序、关键路径分析、任务调度以及依赖关系解析。适用于用户需要进行有向无环图运算、拓扑排序、关键路径分析、依赖关系解析、任务调度,或管理工作流 DAG。

SKILL.md
--- frontmatter
name: "@ruvector/rudag"
description: "Fast DAG library with Rust/WASM for topological sort, critical path, task scheduling, and dependency resolution. Use when the user needs directed acyclic graph operations, topological sorting, critical path analysis, dependency resolution, task scheduling, or workflow DAG management."

@ruvector/rudag

Fast directed acyclic graph (DAG) library built with Rust/WASM providing topological sort, critical path analysis, task scheduling, dependency resolution, and cycle detection with near-native performance.

Quick Command Reference

TaskCode
Create DAGconst dag = new DAG()
Add nodedag.addNode('a', { weight: 1 })
Add edgedag.addEdge('a', 'b')
Topological sortdag.topologicalSort()
Critical pathdag.criticalPath()
Detect cyclesdag.hasCycle()
Get dependenciesdag.dependencies('b')
Get dependentsdag.dependents('a')

Installation

Hub install (recommended): npx ruvector@latest includes this package. Standalone: npx @ruvector/rudag@latest See Installation Guide for the full ecosystem.

Core API

DAG Constructor

typescript
import { DAG } from '@ruvector/rudag';

const dag = new DAG();

Node and Edge Operations

typescript
// Add nodes
dag.addNode('compile', { weight: 10, label: 'Compile source' });
dag.addNode('test', { weight: 5, label: 'Run tests' });
dag.addNode('deploy', { weight: 3, label: 'Deploy' });

// Add edges (dependencies)
dag.addEdge('compile', 'test');   // test depends on compile
dag.addEdge('test', 'deploy');    // deploy depends on test

// Remove
dag.removeNode('deploy');
dag.removeEdge('compile', 'test');

// Query
const hasNode = dag.hasNode('compile');   // true
const hasEdge = dag.hasEdge('compile', 'test'); // true

Graph Algorithms

typescript
// Topological sort
const order = dag.topologicalSort();   // ['compile', 'test', 'deploy']

// Critical path (longest path through weighted DAG)
const path = dag.criticalPath();
// { path: ['compile', 'test', 'deploy'], totalWeight: 18 }

// Cycle detection
const hasCycle = dag.hasCycle();        // false

// Dependencies (ancestors)
const deps = dag.dependencies('deploy'); // ['compile', 'test']

// Dependents (descendants)
const dependents = dag.dependents('compile'); // ['test', 'deploy']

// All paths between nodes
const paths = dag.allPaths('compile', 'deploy');

// Parallel execution levels
const levels = dag.parallelLevels();
// [['compile'], ['test'], ['deploy']]

Task Scheduling

typescript
// Get execution order respecting dependencies
const schedule = dag.schedule({ maxParallel: 4 });
// [['compile'], ['test', 'lint'], ['deploy']]

// Execute with async runner
await dag.execute(async (nodeId, data) => {
  console.log(`Running ${nodeId}`);
  return await runTask(nodeId);
}, { maxParallel: 4 });

Common Patterns

Build System Dependencies

typescript
const dag = new DAG();
dag.addNode('src', { weight: 2 });
dag.addNode('types', { weight: 1 });
dag.addNode('bundle', { weight: 5 });
dag.addNode('test', { weight: 3 });
dag.addEdge('src', 'bundle');
dag.addEdge('types', 'bundle');
dag.addEdge('bundle', 'test');
const order = dag.topologicalSort(); // ['src', 'types', 'bundle', 'test']

CI/CD Pipeline

typescript
const pipeline = new DAG();
pipeline.addNode('lint'); pipeline.addNode('test'); pipeline.addNode('build');
pipeline.addNode('deploy-staging'); pipeline.addNode('deploy-prod');
pipeline.addEdge('lint', 'build');
pipeline.addEdge('test', 'build');
pipeline.addEdge('build', 'deploy-staging');
pipeline.addEdge('deploy-staging', 'deploy-prod');
const levels = pipeline.parallelLevels();
// [['lint', 'test'], ['build'], ['deploy-staging'], ['deploy-prod']]

Package Dependency Resolution

typescript
const deps = new DAG();
deps.addNode('express'); deps.addNode('body-parser'); deps.addNode('qs');
deps.addEdge('body-parser', 'express');
deps.addEdge('qs', 'body-parser');
const installOrder = deps.topologicalSort(); // ['qs', 'body-parser', 'express']

Key Options

FeatureValue
BackendRust/WASM
AlgorithmsTopo sort, critical path, cycle detection
Parallel schedulingAutomatic level grouping
SerializationJSON, DOT (Graphviz)
Max nodes (tested)100k+

RAN DDD Context

Bounded Context: Data Infrastructure

References