"""Stage 6: Skill Generator — Transform workflow into standardized Hermes Skill.""" import yaml import json def generate_skill(score_result, config): """ Generate a standardized Hermes Skill package from an approved workflow. """ if score_result.get("decision") != "PASS": return { "status": "BLOCKED", "reason": "Score check failed", } workflow = score_result.get("workflow", {}) skill_name = workflow.get("skill_name", "unknown").lower().replace(" ", "-").replace("_", "-") repo = score_result.get("repository", "") # Generate SKILL.md (frontmatter + markdown body) frontmatter = { "name": skill_name, "version": "1.0.0", "description": workflow.get("goal", ""), "inputs": workflow.get("inputs", []), "steps": workflow.get("steps", []), "outputs": workflow.get("outputs", []), "tags": [], "metadata": { "source_repo": repo, "extracted_at": "", "confidence": workflow.get("confidence", 0), }, } skill_md = "---\n" skill_md += yaml.dump(frontmatter, default_flow_style=False, sort_keys=False) skill_md += "---\n\n" skill_md += f"# {skill_name}\n\n" skill_md += f"{workflow.get('goal', '')}\n\n" skill_md += f"## Steps\n\n" for i, step in enumerate(workflow.get("steps", []), 1): skill_md += f"{i}. {step}\n" skill_md += f"\n## Inputs\n\n" for inp in workflow.get("inputs", []): skill_md += f"- {inp}\n" skill_md += f"\n## Outputs\n\n" for out in workflow.get("outputs", []): skill_md += f"- {out}\n" skill_md += f"\n## Failure Modes\n\n" for fm in workflow.get("failure_modes", []): skill_md += f"- {fm}\n" skill_md += f"\n## Source\n\n" skill_md += f"Extracted from: [{repo}]({repo})\n" skill_md += f"Confidence: {workflow.get('confidence', 0)}\n" # Generate examples.md examples_md = f"# Examples: {skill_name}\n\n" examples_md += f"## Usage Example\n\n" examples_md += f"```python\n# How to use this skill\n# Inputs: {', '.join(workflow.get('inputs', []))}\n# Process: {' → '.join(workflow.get('steps', [])[:3])}\n# Outputs: {', '.join(workflow.get('outputs', []))}\n```\n" # Generate commands.md commands_md = f"# Commands: {skill_name}\n\n" commands_md += f"## Available Commands\n\n" commands_md += f"- `/skill {skill_name}` — Load this skill\n" commands_md += f"- `/run {skill_name}` — Execute workflow\n" # Generate metadata.json metadata = { "name": skill_name, "version": "1.0.0", "goal": workflow.get("goal", ""), "inputs": workflow.get("inputs", []), "steps": workflow.get("steps", []), "outputs": workflow.get("outputs", []), "failure_modes": workflow.get("failure_modes", []), "confidence": workflow.get("confidence", 0), "explanation": workflow.get("explanation", ""), "source_repo": repo, "score": score_result.get("score", 0), } # Generate tests.md tests_md = f"# Tests: {skill_name}\n\n" tests_md += f"## Test Checklist\n\n" tests_md += f"- [ ] Workflow has at least 3 steps\n" tests_md += f"- [ ] All inputs are defined\n" tests_md += f"- [ ] All outputs are defined\n" tests_md += f"- [ ] Failure modes are documented\n" tests_md += f"- [ ] Skill can be loaded without errors\n" return { "status": "GENERATED", "skill_name": skill_name, "repository": repo, "files": { "SKILL.md": skill_md, "examples.md": examples_md, "commands.md": commands_md, "metadata.json": json.dumps(metadata, indent=2), "tests.md": tests_md, }, "metadata": metadata, }