feat: add model field validation to marketplace script

Add validation for:
- defaultModel field in plugin.json (must be opus|sonnet|haiku)
- model field in agent frontmatter (must be opus|sonnet|haiku)

The validation passes when fields are absent (optional) but errors
if present with invalid values.

Fixes #306

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-28 21:55:16 -05:00
parent 5b1b0f609c
commit 8a95e061ad

View File

@@ -143,6 +143,16 @@ for plugin_dir in "$PLUGINS_DIR"/*/; do
echo "WARNING: Missing 'keywords' array in $plugin_name/plugin.json"
fi
# v5.4.0: Validate defaultModel field if present
default_model=$(jq -r '.defaultModel // empty' "$plugin_json")
if [[ -n "$default_model" ]]; then
if [[ ! "$default_model" =~ ^(opus|sonnet|haiku)$ ]]; then
echo "ERROR: Invalid defaultModel '$default_model' in $plugin_name/plugin.json (must be opus|sonnet|haiku)"
exit 1
fi
echo " ✓ defaultModel: $default_model"
fi
# Check README exists
if [[ ! -f "$plugin_dir/README.md" ]]; then
echo "WARNING: Missing README.md in $plugin_name/"
@@ -151,6 +161,40 @@ for plugin_dir in "$PLUGINS_DIR"/*/; do
echo "$plugin_name valid"
done
# v5.4.0: Validate agent model fields
echo ""
echo "=== Validating Agent Model Fields (v5.4.0+) ==="
validate_agent_model() {
local file="$1"
local agent_name=$(basename "$file" .md)
# Extract model from frontmatter (between --- markers)
local model=$(sed -n '/^---$/,/^---$/p' "$file" | grep '^model:' | awk '{print $2}')
if [[ -n "$model" ]]; then
if [[ ! "$model" =~ ^(opus|sonnet|haiku)$ ]]; then
echo "ERROR: Invalid model '$model' in $file (must be opus|sonnet|haiku)"
exit 1
fi
echo "$agent_name: model=$model"
fi
}
for plugin_dir in "$PLUGINS_DIR"/*/; do
plugin_name=$(basename "$plugin_dir")
agents_dir="$plugin_dir/agents"
if [[ -d "$agents_dir" ]]; then
echo "--- Checking agents in $plugin_name ---"
for agent_file in "$agents_dir"/*.md; do
if [[ -f "$agent_file" ]]; then
validate_agent_model "$agent_file"
fi
done
fi
done
# v3.0.0: Validate MCP server symlinks
echo ""
echo "=== Validating MCP Server Symlinks (v3.0.0+) ==="