create-skill.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. TRANSLATED CONTENT:
  2. #!/usr/bin/env bash
  3. set -euo pipefail
  4. # ==================== Help ====================
  5. usage() {
  6. cat <<'EOF'
  7. Usage:
  8. create-skill.sh <skill-name> [--minimal|--full] [--output <dir>] [--force]
  9. Notes:
  10. - <skill-name> MUST be lowercase, start with a letter, and only contain letters, digits, and hyphens
  11. - Default mode: --full
  12. - Default output: current directory (creates ./<skill-name>/)
  13. Examples:
  14. ./skills/claude-skills/scripts/create-skill.sh postgresql --full --output skills
  15. ./skills/claude-skills/scripts/create-skill.sh my-api --minimal
  16. EOF
  17. }
  18. die() {
  19. echo "Error: $*" >&2
  20. exit 1
  21. }
  22. # ==================== Arg Parsing ====================
  23. skill_name=""
  24. mode="full"
  25. output_dir="."
  26. force=0
  27. while [[ $# -gt 0 ]]; do
  28. case "$1" in
  29. -h|--help)
  30. usage
  31. exit 0
  32. ;;
  33. --minimal)
  34. mode="minimal"
  35. shift
  36. ;;
  37. --full)
  38. mode="full"
  39. shift
  40. ;;
  41. -o|--output)
  42. [[ $# -ge 2 ]] || die "--output requires a directory argument"
  43. output_dir="$2"
  44. shift 2
  45. ;;
  46. -f|--force)
  47. force=1
  48. shift
  49. ;;
  50. --)
  51. shift
  52. break
  53. ;;
  54. -*)
  55. die "Unknown argument: $1 (use --help)"
  56. ;;
  57. *)
  58. if [[ -z "$skill_name" ]]; then
  59. skill_name="$1"
  60. shift
  61. else
  62. die "Extra argument: $1 (only one <skill-name> is allowed)"
  63. fi
  64. ;;
  65. esac
  66. done
  67. [[ -n "$skill_name" ]] || { usage; exit 1; }
  68. if [[ ! "$skill_name" =~ ^[a-z][a-z0-9-]*$ ]]; then
  69. die "skill-name must be lowercase, start with a letter, and only contain letters/digits/hyphens (e.g. my-skill-name)"
  70. fi
  71. script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
  72. assets_dir="${script_dir}/../assets"
  73. template_path=""
  74. case "$mode" in
  75. minimal) template_path="${assets_dir}/template-minimal.md" ;;
  76. full) template_path="${assets_dir}/template-complete.md" ;;
  77. *) die "Internal error: unknown mode=$mode" ;;
  78. esac
  79. [[ -f "$template_path" ]] || die "Template not found: $template_path"
  80. mkdir -p "$output_dir"
  81. target_dir="${output_dir%/}/${skill_name}"
  82. if [[ -e "$target_dir" && "$force" -ne 1 ]]; then
  83. die "Target already exists: $target_dir (use --force to overwrite)"
  84. fi
  85. mkdir -p "$target_dir"/{assets,scripts,references}
  86. # ==================== Write Files ====================
  87. render_template() {
  88. local src="$1"
  89. local dest="$2"
  90. sed "s/{{skill_name}}/${skill_name}/g" "$src" > "$dest"
  91. }
  92. render_template "$template_path" "$target_dir/SKILL.md"
  93. cat > "$target_dir/references/index.md" <<EOF
  94. # ${skill_name} Reference Index
  95. ## Quick Links
  96. - Getting started: \`getting_started.md\`
  97. - API/CLI/config: \`api.md\` (if applicable)
  98. - Examples: \`examples.md\`
  99. - Troubleshooting: \`troubleshooting.md\`
  100. ## Notes
  101. - Put long-form content here: excerpts, evidence links, edge cases, FAQ
  102. - Keep \`SKILL.md\` Quick Reference short and directly usable
  103. EOF
  104. if [[ "$mode" == "full" ]]; then
  105. cat > "$target_dir/references/getting_started.md" <<'EOF'
  106. # Getting Started & Vocabulary
  107. ## Goals
  108. - Define the 10 most important terms in this domain
  109. - Provide the shortest path from zero to working
  110. EOF
  111. cat > "$target_dir/references/api.md" <<'EOF'
  112. # API / CLI / Config Reference (If Applicable)
  113. ## Suggested Structure
  114. - Organize by use case, not alphabetically
  115. - Key parameters: defaults, boundaries, common misuse
  116. - Common errors: message -> cause -> fix steps
  117. EOF
  118. cat > "$target_dir/references/examples.md" <<'EOF'
  119. # Long Examples
  120. Put examples longer than ~20 lines here, split by use case:
  121. - Use case 1: ...
  122. - Use case 2: ...
  123. EOF
  124. cat > "$target_dir/references/troubleshooting.md" <<'EOF'
  125. # Troubleshooting & Edge Cases
  126. Write as: symptom -> likely causes -> diagnosis -> fix.
  127. EOF
  128. fi
  129. # ==================== Summary ====================
  130. echo ""
  131. echo "OK: Skill generated: $target_dir/"
  132. echo ""
  133. echo "Layout:"
  134. echo " $target_dir/"
  135. echo " |-- SKILL.md"
  136. echo " |-- assets/"
  137. echo " |-- scripts/"
  138. echo " \\-- references/"
  139. echo " \\-- index.md"
  140. echo ""
  141. echo "Next steps:"
  142. echo " 1) Edit $target_dir/SKILL.md (triggers/boundaries/quick reference/examples)"
  143. echo " 2) Put long-form docs into $target_dir/references/ and update index.md"