From c120cd415e6b28f6182c8f027f3cba175c2b6ae7 Mon Sep 17 00:00:00 2001 From: daymade Date: Mon, 6 Apr 2026 08:59:45 +0800 Subject: [PATCH] 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) --- .claude-plugin/marketplace.json | 15 ++++++++- marketplace-dev/scripts/post_edit_validate.sh | 32 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100755 marketplace-dev/scripts/post_edit_validate.sh diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index c9e360d..bb7b461 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -960,7 +960,20 @@ ], "skills": [ "./marketplace-dev" - ] + ], + "hooks": { + "PostToolUse": [ + { + "matcher": "Write|Edit", + "hooks": [ + { + "type": "command", + "command": "${CLAUDE_PLUGIN_ROOT}/scripts/post_edit_validate.sh" + } + ] + } + ] + } } ] } \ No newline at end of file diff --git a/marketplace-dev/scripts/post_edit_validate.sh b/marketplace-dev/scripts/post_edit_validate.sh new file mode 100755 index 0000000..ae8118a --- /dev/null +++ b/marketplace-dev/scripts/post_edit_validate.sh @@ -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