feat: add PostToolUse hook to auto-validate marketplace.json on edit
When marketplace-dev is installed, any Write/Edit to a marketplace.json automatically runs `claude plugin validate` and reports pass/fail. Users get instant feedback without remembering to validate manually. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -960,7 +960,20 @@
|
|||||||
],
|
],
|
||||||
"skills": [
|
"skills": [
|
||||||
"./marketplace-dev"
|
"./marketplace-dev"
|
||||||
]
|
],
|
||||||
|
"hooks": {
|
||||||
|
"PostToolUse": [
|
||||||
|
{
|
||||||
|
"matcher": "Write|Edit",
|
||||||
|
"hooks": [
|
||||||
|
{
|
||||||
|
"type": "command",
|
||||||
|
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/post_edit_validate.sh"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
32
marketplace-dev/scripts/post_edit_validate.sh
Executable file
32
marketplace-dev/scripts/post_edit_validate.sh
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# PostToolUse hook: auto-validate marketplace.json after Write/Edit
|
||||||
|
# Checks if the edited file is marketplace.json, runs validation if so.
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Read tool use details from stdin
|
||||||
|
INPUT=$(cat)
|
||||||
|
|
||||||
|
# Check if the edited file is marketplace.json
|
||||||
|
FILE_PATH=$(echo "$INPUT" | python3 -c "
|
||||||
|
import json, sys
|
||||||
|
try:
|
||||||
|
data = json.load(sys.stdin)
|
||||||
|
path = data.get('tool_input', {}).get('file_path', '')
|
||||||
|
print(path)
|
||||||
|
except:
|
||||||
|
print('')
|
||||||
|
" 2>/dev/null)
|
||||||
|
|
||||||
|
if [[ "$FILE_PATH" == *"marketplace.json"* ]]; then
|
||||||
|
MARKETPLACE_DIR=$(dirname "$(dirname "$FILE_PATH")")
|
||||||
|
if [[ -f "$FILE_PATH" ]]; then
|
||||||
|
RESULT=$(cd "$MARKETPLACE_DIR" && claude plugin validate . 2>&1) || true
|
||||||
|
if echo "$RESULT" | grep -q "Validation passed"; then
|
||||||
|
echo '{"result": "marketplace.json validated ✔"}'
|
||||||
|
else
|
||||||
|
ERRORS=$(echo "$RESULT" | grep -v "^$" | head -5)
|
||||||
|
echo "{\"result\": \"marketplace.json validation FAILED:\\n$ERRORS\"}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user