Files
ai-proj-helper/skills/skill-manager-plugin/validate.sh
John Qiu 99881e268a refactor: 合并 claude-marketplace,重构目录结构为单一仓库
- 重命名 plugins/ → skills/,个人插件迁移到 skills-personal/(gitignore)
- 更新 generate-marketplace.py 支持 config 读取和 skills-personal 扫描
- 新增 claude-config.yaml(技能启用/禁用 + MCP 配置)
- 新增 init.sh(交互式 MCP 初始化,支持 stdio/SSE 模式)
- 新增 CLAUDE.md 项目说明
- 重写 README.md 反映新结构
- 删除过时脚本:PUSH.sh、generate-marketplace.sh、convert-skills.sh

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-14 11:11:59 +10:30

89 lines
2.6 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# validate.sh - 验证 skill.yaml 格式
# 用法: ./validate.sh <skill-directory>
set -e
SKILL_DIR="${1:-.}"
SKILL_YAML="$SKILL_DIR/skill.yaml"
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo "验证技能目录: $SKILL_DIR"
echo "----------------------------------------"
# 检查 skill.yaml 是否存在
if [ ! -f "$SKILL_YAML" ]; then
echo -e "${RED}✗ skill.yaml 不存在${NC}"
exit 1
fi
echo -e "${GREEN}✓ skill.yaml 存在${NC}"
# 检查 YAML 格式(需要 yq 或 python
if command -v yq &> /dev/null; then
if ! yq e '.' "$SKILL_YAML" > /dev/null 2>&1; then
echo -e "${RED}✗ YAML 格式错误${NC}"
exit 1
fi
echo -e "${GREEN}✓ YAML 格式正确${NC}"
# 检查必填字段
NAME=$(yq e '.name' "$SKILL_YAML")
VERSION=$(yq e '.version' "$SKILL_YAML")
DESCRIPTION=$(yq e '.description' "$SKILL_YAML")
if [ "$NAME" == "null" ] || [ -z "$NAME" ]; then
echo -e "${RED}✗ 缺少必填字段: name${NC}"
exit 1
fi
echo -e "${GREEN}✓ name: $NAME${NC}"
if [ "$VERSION" == "null" ] || [ -z "$VERSION" ]; then
echo -e "${RED}✗ 缺少必填字段: version${NC}"
exit 1
fi
echo -e "${GREEN}✓ version: $VERSION${NC}"
if [ "$DESCRIPTION" == "null" ] || [ -z "$DESCRIPTION" ]; then
echo -e "${RED}✗ 缺少必填字段: description${NC}"
exit 1
fi
echo -e "${GREEN}✓ description: 已设置${NC}"
# 验证 name 格式
if ! echo "$NAME" | grep -qE '^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$'; then
echo -e "${RED}✗ name 格式错误: 只能包含小写字母、数字、连字符${NC}"
exit 1
fi
if [ ${#NAME} -gt 64 ]; then
echo -e "${RED}✗ name 超过 64 字符${NC}"
exit 1
fi
echo -e "${GREEN}✓ name 格式正确${NC}"
# 检查 prompt_file
PROMPT_FILE=$(yq e '.prompt_file // "SKILL.md"' "$SKILL_YAML")
if [ ! -f "$SKILL_DIR/$PROMPT_FILE" ]; then
echo -e "${YELLOW}⚠ prompt_file 不存在: $PROMPT_FILE${NC}"
else
echo -e "${GREEN}✓ prompt_file: $PROMPT_FILE${NC}"
fi
elif command -v python3 &> /dev/null; then
python3 -c "import yaml; yaml.safe_load(open('$SKILL_YAML'))" 2>/dev/null
if [ $? -ne 0 ]; then
echo -e "${RED}✗ YAML 格式错误${NC}"
exit 1
fi
echo -e "${GREEN}✓ YAML 格式正确 (使用 Python 验证)${NC}"
else
echo -e "${YELLOW}⚠ 无法验证 YAML 格式 (需要 yq 或 python3)${NC}"
fi
echo "----------------------------------------"
echo -e "${GREEN}✓ 验证通过${NC}"