dependency
dependency
¶
Dependency graph: cycle detection, topological sort, capability union.
Classes¶
DependencyCycleError
¶
Bases: Exception
Raised when a cycle is detected in the skill dependency graph.
DepthExceededError
¶
Bases: Exception
Raised when the dependency depth exceeds the configured maximum.
Functions¶
build_dependency_graph
¶
Build a directed graph of skill dependencies.
Each key maps to the set of skill names it directly depends on, drawn from
both the depends field and any skill_name references in steps.
Only edges pointing to skills that are present in the skills dict are
included (unknown refs are silently dropped so that the graph stays clean
for topological analysis).
Args: skills: Mapping of skill name → SkillManifest.
Returns: Dict mapping each skill name to the set of its direct dependencies.
Source code in src/openjarvis/skills/dependency.py
validate_dependencies
¶
Validate the skill dependency graph and return a topological ordering.
Uses Kahn's algorithm for topological sort and cycle detection. After a valid ordering is found, a DFS checks that no skill's transitive dependency chain exceeds max_depth. Dependencies that reference unknown skills are silently skipped.
Args: skills: Mapping of skill name → SkillManifest. max_depth: Maximum allowed dependency chain depth (default 5).
Returns: List of skill names in valid topological order (dependencies first).
Raises: DependencyCycleError: If the graph contains a cycle. DepthExceededError: If any skill's dependency chain depth exceeds max_depth.
Source code in src/openjarvis/skills/dependency.py
compute_capability_union
¶
Compute the union of all required_capabilities transitively needed by a skill.
Performs a DFS over the dependency graph, collecting required_capabilities
from the skill itself and all of its transitive dependencies. Duplicates are
removed while preserving a deterministic order (first-seen wins).
Args: skill_name: Name of the root skill to start from. skills: Mapping of skill name → SkillManifest.
Returns: Deduplicated list of capability strings. Returns an empty list if the skill is not found.