Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Enable an AI agent to iteratively improve its own skills and instructions based on task feedback.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/extract-skill.sh
1#!/bin/bash2# Skill Extraction Helper3# Creates a new skill from a learning entry4# Usage: ./extract-skill.sh <skill-name> [--dry-run]56set -e78# Configuration9SKILLS_DIR="./skills"1011# Colors for output12RED='\033[0;31m'13GREEN='\033[0;32m'14YELLOW='\033[1;33m'15NC='\033[0m' # No Color1617usage() {18cat << EOF19Usage: $(basename "$0") <skill-name> [options]2021Create a new skill from a learning entry.2223Arguments:24skill-name Name of the skill (lowercase, hyphens for spaces)2526Options:27--dry-run Show what would be created without creating files28--output-dir Relative output directory under current path (default: ./skills)29-h, --help Show this help message3031Examples:32$(basename "$0") docker-m1-fixes33$(basename "$0") api-timeout-patterns --dry-run34$(basename "$0") pnpm-setup --output-dir ./skills/custom3536The skill will be created in: \$SKILLS_DIR/<skill-name>/37EOF38}3940log_info() {41echo -e "${GREEN}[INFO]${NC} $1"42}4344log_warn() {45echo -e "${YELLOW}[WARN]${NC} $1"46}4748log_error() {49echo -e "${RED}[ERROR]${NC} $1" >&250}5152# Parse arguments53SKILL_NAME=""54DRY_RUN=false5556while [[ $# -gt 0 ]]; do57case $1 in58--dry-run)59DRY_RUN=true60shift61;;62--output-dir)63if [ -z "${2:-}" ] || [[ "${2:-}" == -* ]]; then64log_error "--output-dir requires a relative path argument"65usage66exit 167fi68SKILLS_DIR="$2"69shift 270;;71-h|--help)72usage73exit 074;;75-*)76log_error "Unknown option: $1"77usage78exit 179;;80*)81if [ -z "$SKILL_NAME" ]; then82SKILL_NAME="$1"83else84log_error "Unexpected argument: $1"85usage86exit 187fi88shift89;;90esac91done9293# Validate skill name94if [ -z "$SKILL_NAME" ]; then95log_error "Skill name is required"96usage97exit 198fi99100# Validate skill name format (lowercase, hyphens, no spaces)101if ! [[ "$SKILL_NAME" =~ ^[a-z0-9]+(-[a-z0-9]+)*$ ]]; then102log_error "Invalid skill name format. Use lowercase letters, numbers, and hyphens only."103log_error "Examples: 'docker-fixes', 'api-patterns', 'pnpm-setup'"104exit 1105fi106107# Validate output path to avoid writes outside current workspace.108if [[ "$SKILLS_DIR" = /* ]]; then109log_error "Output directory must be a relative path under the current directory."110exit 1111fi112113if [[ "$SKILLS_DIR" =~ (^|/)\.\.(/|$) ]]; then114log_error "Output directory cannot include '..' path segments."115exit 1116fi117118SKILLS_DIR="${SKILLS_DIR#./}"119SKILLS_DIR="./$SKILLS_DIR"120121SKILL_PATH="$SKILLS_DIR/$SKILL_NAME"122123# Check if skill already exists124if [ -d "$SKILL_PATH" ] && [ "$DRY_RUN" = false ]; then125log_error "Skill already exists: $SKILL_PATH"126log_error "Use a different name or remove the existing skill first."127exit 1128fi129130# Dry run output131if [ "$DRY_RUN" = true ]; then132log_info "Dry run - would create:"133echo " $SKILL_PATH/"134echo " $SKILL_PATH/SKILL.md"135echo ""136echo "Template content would be:"137echo "---"138cat << TEMPLATE139name: $SKILL_NAME140description: "[TODO: Add a concise description of what this skill does and when to use it]"141---142143# $(echo "$SKILL_NAME" | sed 's/-/ /g' | awk '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2))}1')144145[TODO: Brief introduction explaining the skill's purpose]146147## Quick Reference148149| Situation | Action |150|-----------|--------|151| [Trigger condition] | [What to do] |152153## Usage154155[TODO: Detailed usage instructions]156157## Examples158159[TODO: Add concrete examples]160161## Source Learning162163This skill was extracted from a learning entry.164- Learning ID: [TODO: Add original learning ID]165- Original File: .learnings/LEARNINGS.md166TEMPLATE167echo "---"168exit 0169fi170171# Create skill directory structure172log_info "Creating skill: $SKILL_NAME"173174mkdir -p "$SKILL_PATH"175176# Create SKILL.md from template177cat > "$SKILL_PATH/SKILL.md" << TEMPLATE178---179name: $SKILL_NAME180description: "[TODO: Add a concise description of what this skill does and when to use it]"181---182183# $(echo "$SKILL_NAME" | sed 's/-/ /g' | awk '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2))}1')184185[TODO: Brief introduction explaining the skill's purpose]186187## Quick Reference188189| Situation | Action |190|-----------|--------|191| [Trigger condition] | [What to do] |192193## Usage194195[TODO: Detailed usage instructions]196197## Examples198199[TODO: Add concrete examples]200201## Source Learning202203This skill was extracted from a learning entry.204- Learning ID: [TODO: Add original learning ID]205- Original File: .learnings/LEARNINGS.md206TEMPLATE207208log_info "Created: $SKILL_PATH/SKILL.md"209210# Suggest next steps211echo ""212log_info "Skill scaffold created successfully!"213echo ""214echo "Next steps:"215echo " 1. Edit $SKILL_PATH/SKILL.md"216echo " 2. Fill in the TODO sections with content from your learning"217echo " 3. Add references/ folder if you have detailed documentation"218echo " 4. Add scripts/ folder if you have executable code"219echo " 5. Update the original learning entry with:"220echo " **Status**: promoted_to_skill"221echo " **Skill-Path**: skills/$SKILL_NAME"222