plugin-dependency-resolver
Scannednpx machina-cli add skill a5c-ai/babysitter/plugin-dependency-resolver --openclawFiles (1)
SKILL.md
1.3 KB
Plugin Dependency Resolver
Generate plugin dependency resolution logic.
Generated Patterns
interface PluginNode {
name: string;
dependencies: string[];
}
export function resolveDependencies(plugins: PluginNode[]): string[] {
const graph = new Map<string, string[]>();
const inDegree = new Map<string, number>();
for (const plugin of plugins) {
graph.set(plugin.name, plugin.dependencies);
inDegree.set(plugin.name, 0);
}
for (const [, deps] of graph) {
for (const dep of deps) {
inDegree.set(dep, (inDegree.get(dep) || 0) + 1);
}
}
const queue = [...inDegree.entries()].filter(([, d]) => d === 0).map(([n]) => n);
const result: string[] = [];
while (queue.length > 0) {
const node = queue.shift()!;
result.push(node);
for (const dep of graph.get(node) || []) {
inDegree.set(dep, inDegree.get(dep)! - 1);
if (inDegree.get(dep) === 0) queue.push(dep);
}
}
if (result.length !== plugins.length) {
throw new Error('Circular dependency detected');
}
return result.reverse();
}
Target Processes
- plugin-architecture-implementation
Source
git clone https://github.com/a5c-ai/babysitter/blob/main/plugins/babysitter/skills/babysit/process/specializations/cli-mcp-development/skills/plugin-dependency-resolver/SKILL.mdView on GitHub Overview
Generates a dependency resolver for plugins using topological sorting. It builds a graph of plugins and their dependencies, computes in-degrees, and outputs a linearized load order. It detects circular dependencies and throws an error.
How This Skill Works
Takes PluginNode[] with name and dependencies. Constructs a graph and inDegree maps, then runs a topological sort (Kahn's algorithm) by repeatedly removing nodes with zero in-degree. If a cycle is detected, it throws an error; otherwise it returns the resolved order.
When to Use It
- You have a plugin system where each plugin declares dependencies on other plugins.
- Load order matters: dependencies must initialize before dependents.
- You add or modify plugins and need an automatic, deterministic load sequence.
- You want to detect circular dependencies early to avoid runtime failures.
- Integrating with a build or deployment pipeline to ensure correct plugin resolution.
Quick Start
- Step 1: Define PluginNode[] with { name: string; dependencies: string[] } for all plugins.
- Step 2: Call resolveDependencies(plugins) to obtain a load sequence.
- Step 3: Initialize plugins in the returned order to ensure dependencies are ready.
Best Practices
- Declare explicit, up-to-date dependencies for every plugin (names must match the PluginNode).
- Validate that all dependencies appear in the plugin set to avoid unresolved references.
- Treat the resolver as a pure function: input plugins -> deterministic order without side effects.
- Catch and report circular dependencies clearly, including the involved plugin names.
- Return a stable, deterministic order (the implementation returns a reverse topological order for load sequencing).
Example Use Cases
- In a plugin-architecture-implementation workflow, resolve plugin load order so dependencies initialize first.
- Game engine mods that require base mods; the resolver ensures core mods load before dependent mods.
- IDE extensions where certain features rely on foundational plugins being active first.
- Automation platform with plugin tasks that must run in a specific dependency-respecting sequence.
- Web application with backend plugins that depend on shared utility plugins.
Frequently Asked Questions
Add this skill to your agents