Skip to content

marketingjuliancongdanh79-pixel/skill-generator

skill-creator-ultra

Verified

Tạo AI Skill mới từ ý tưởng hoặc quy trình công việc. Kết hợp phỏng vấn thông minh, pattern detection, và quantitative evaluation để tạo skill chất lượng production. Dùng khi user nói "tạo skill", "biến quy trình thành skill", "make a new skill", "tự động hóa công việc này", hoặc mô tả quy trình lặp lại mà họ muốn AI tự làm. Cũng dùng khi user muốn cải thiện, test, hoặc optimize skill hiện có.

scripts/skill_export.py

View on GitHub
#!/usr/bin/env python3
"""
skill_export.py — Chuyển đổi SKILL.md sang format các nền tảng khác

Sử dụng:
    python skill_export.py /path/to/SKILL.md --platform cursor
    python skill_export.py /path/to/skill-folder/ --platform claude
    python skill_export.py /path/to/skill-folder/ --platform all
    python skill_export.py /path/to/skill-folder/ --platform all --output ./exports/

Nền tảng hỗ trợ:
    cursor    → .cursor/rules/<name>.mdc
    claude    → CLAUDE.md (Custom Commands)
    windsurf  → .windsurf/rules/<name>.md
    cline     → .clinerules (Custom Instructions)
    copilot   → .github/copilot-instructions.md
    openclaw  → System Prompt (text file)
    all       → Export tất cả

Developed by Thân Công Hải — Skill Generator v3.2 Expert
"""

import sys
import os
import re
from pathlib import Path
from datetime import datetime


# ============================================================
# COLOR OUTPUT
# ============================================================

class Colors:
    PASS = '\033[92m'
    FAIL = '\033[91m'
    WARN = '\033[93m'
    INFO = '\033[96m'
    BOLD = '\033[1m'
    DIM = '\033[2m'
    RESET = '\033[0m'

    @staticmethod
    def enable_windows():
        if os.name == 'nt':
            try:
                import ctypes
                kernel32 = ctypes.windll.kernel32
                kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7)
            except Exception:
                pass


Colors.enable_windows()


# ============================================================
# PARSERS
# ============================================================

def parse_frontmatter(content):
    """Trích xuất YAML frontmatter."""
    match = re.match(r'^---\s*\n(.*?)\n---\s*\n', content, re.DOTALL)
    if not match:
        return {}, content

    fm_text = match.group(1)
    body = content[match.end():]
    frontmatter = {}
    current_key = None
    current_value = []

    for line in fm_text.split('\n'):
        key_match = re.match(r'^(\w+):\s*(.*)', line)
        if key_match:
            if current_key:
                frontmatter[current_key] = '\n'.join(current_value).strip()
            current_key = key_match.group(1)
            current_value = [key_match.group(2)] if key_match.group(2) and key_match.group(2) != '|' else []
        elif current_key and line.startswith('  '):
            current_value.append(line.strip())

    if current_key:
        frontmatter[current_key] = '\n'.join(current_value).strip()

    return frontmatter, body


def extract_trigger_phrases(description):
    """Trích xuất trigger phrases từ description."""
    triggers = re.findall(r'"([^"]+)"', description)
    return triggers


# ============================================================
# EXPORTERS
# ============================================================

def export_cursor(frontmatter, body, name):
    """Export sang Cursor .mdc rule format."""
    desc = frontmatter.get('description', '')
    triggers = extract_trigger_phrases(desc)
    trigger_str = ', '.join([f'"{t}"' for t in triggers]) if triggers else f'"{name}"'

    return f"""---
description: {desc.split(chr(10))[0] if desc else name}
globs:
alwaysApply: false
---

# {name}

> Trigger: {trigger_str}
> Converted from SKILL.md by Skill Generator v3.2

{body}

<!-- Generated by Skill Generator v3.2 — Export: Cursor -->
"""


def export_claude(frontmatter, body, name):
    """Export sang Claude Code CLAUDE.md format."""
    desc = frontmatter.get('description', '')

    return f"""# {name}

> {desc}
> Converted from SKILL.md by Skill Generator v3.2

{body}

<!-- Generated by Skill Generator v3.2 — Export: Claude Code -->
"""


def export_windsurf(frontmatter, body, name):
    """Export sang Windsurf Cascade Rule format."""
    desc = frontmatter.get('description', '')

    return f"""---
trigger: manual
description: {desc.split(chr(10))[0] if desc else name}
---

# {name}

> {desc}
> Converted from SKILL.md by Skill Generator v3.2

{body}

<!-- Generated by Skill Generator v3.2 — Export: Windsurf -->
"""


def export_cline(frontmatter, body, name):
    """Export sang Cline Custom Instructions format."""
    desc = frontmatter.get('description', '')

    return f"""# Custom Instruction: {name}

## Mô tả
{desc}

## Hướng dẫn
Khi user yêu cầu liên quan đến skill này, hãy tuân theo quy trình dưới đây:

{body}

<!-- Generated by Skill Generator v3.2 — Export: Cline -->
"""


def export_copilot(frontmatter, body, name):
    """Export sang GitHub Copilot instructions format."""
    desc = frontmatter.get('description', '')

    return f"""## {name}

{desc}

### Quy trình thực hiện

{body}

<!-- Generated by Skill Generator v3.2 — Export: GitHub Copilot -->
"""


def export_openclaw(frontmatter, body, name):
    """Export sang OpenClaw System Prompt format."""
    desc = frontmatter.get('description', '')

    return f"""[SYSTEM PROMPT — {name}]

Mô tả: {desc}

---

{body}

---
[END SYSTEM PROMPT]
Generated by Skill Generator v3.2 — Export: OpenClaw
"""


EXPORTERS = {
    'cursor':   {'fn': export_cursor,   'ext': '.mdc',  'dir': '.cursor/rules',  'label': 'Cursor Rule'},
    'claude':   {'fn': export_claude,   'ext': '.md',   'dir': '.claude/commands', 'label': 'Claude Code Command'},
    'windsurf': {'fn': export_windsurf, 'ext': '.md',   'dir': '.windsurf/rules', 'label': 'Windsurf Rule'},
    'cline':    {'fn': export_cline,    'ext': '.md',   'dir': '.clinerules',     'label': 'Cline Instructions'},
    'copilot':  {'fn': export_copilot,  'ext': '.md',   'dir': '.github',         'label': 'Copilot Instructions'},
    'openclaw': {'fn': export_openclaw, 'ext': '.txt',  'dir': 'openclaw',        'label': 'OpenClaw System Prompt'},
}


# ============================================================
# MAIN
# ============================================================

def export_skill(target_path, platform, output_dir=None):
    """Chạy export cho skill."""

    # Tìm SKILL.md
    if os.path.isdir(target_path):
        skill_md = os.path.join(target_path, 'SKILL.md')
    else:
        skill_md = target_path

    if not os.path.exists(skill_md):
        print(f"{Colors.FAIL}❌ Không tìm thấy SKILL.md tại: {skill_md}{Colors.RESET}")
        return False

    with open(skill_md, 'r', encoding='utf-8') as f:
        content = f.read()

    frontmatter, body = parse_frontmatter(content)
    name = frontmatter.get('name', 'unnamed-skill')

    # Determine platforms
    platforms = list(EXPORTERS.keys()) if platform == 'all' else [platform]

    if output_dir is None:
        output_dir = os.path.join(os.path.dirname(skill_md), 'exports')

    os.makedirs(output_dir, exist_ok=True)

    print()
    print(f"{Colors.BOLD}{'=' * 55}{Colors.RESET}")
    print(f"{Colors.BOLD}  📦 SKILL EXPORT — Chuyển đổi đa nền tảng{Colors.RESET}")
    print(f"{Colors.BOLD}  Skill: {Colors.INFO}{name}{Colors.RESET}")
    print(f"{Colors.BOLD}{'=' * 55}{Colors.RESET}")
    print()

    exported = 0

    for p in platforms:
        if p not in EXPORTERS:
            print(f"  {Colors.FAIL}❌ Nền tảng '{p}' không hỗ trợ{Colors.RESET}")
            continue

        exporter = EXPORTERS[p]
        export_content = exporter['fn'](frontmatter, body, name)

        # Create platform subdirectory
        platform_dir = os.path.join(output_dir, p)
        os.makedirs(platform_dir, exist_ok=True)

        # Write file
        filename = f"{name}{exporter['ext']}"
        filepath = os.path.join(platform_dir, filename)

        with open(filepath, 'w', encoding='utf-8') as f:
            f.write(export_content)

        lines = len(export_content.split('\n'))
        print(f"  {Colors.PASS}✅ {exporter['label']}{Colors.RESET}")
        print(f"     📄 {filepath}")
        print(f"     📏 {lines} dòng")
        print()
        exported += 1

    # Summary
    print(f"{Colors.BOLD}{'=' * 55}{Colors.RESET}")
    print(f"  {Colors.PASS}📊 Đã export {exported}/{len(platforms)} nền tảng{Colors.RESET}")
    print(f"  {Colors.DIM}📁 Output: {output_dir}{Colors.RESET}")
    print(f"{Colors.BOLD}{'=' * 55}{Colors.RESET}")
    print()

    # Usage hint
    print(f"  {Colors.INFO}💡 Cách dùng file export:{Colors.RESET}")
    for p in platforms:
        if p in EXPORTERS:
            ex = EXPORTERS[p]
            print(f"     {p}: Copy {ex['dir']}/{name}{ex['ext']} vào dự án")
    print()

    return exported > 0


if __name__ == '__main__':
    if len(sys.argv) < 2:
        print("Sử dụng: python skill_export.py <path> --platform <platform>")
        print()
        print("Platforms: cursor, claude, windsurf, cline, copilot, openclaw, all")
        print()
        print("Options:")
        print("  --platform <name>   Nền tảng đích (bắt buộc)")
        print("  --output <dir>      Thư mục output (mặc định: ./exports/)")
        print()
        print("Ví dụ:")
        print("  python skill_export.py ./my-skill/ --platform cursor")
        print("  python skill_export.py ./my-skill/ --platform all")
        print("  python skill_export.py ./my-skill/ --platform all --output ./exports/")
        sys.exit(1)

    target = sys.argv[1]
    platform = 'all'
    output = None

    for i, arg in enumerate(sys.argv):
        if arg == '--platform' and i + 1 < len(sys.argv):
            platform = sys.argv[i + 1].lower()
        elif arg == '--output' and i + 1 < len(sys.argv):
            output = sys.argv[i + 1]

    if not os.path.exists(target):
        print(f"❌ Không tìm thấy: {target}")
        sys.exit(1)

    success = export_skill(target, platform, output)
    sys.exit(0 if success else 1)
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall