From 83cee46078ea4dfd853f48056cfd1533f7e686f8 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Sat, 28 Mar 2026 02:14:20 -0400 Subject: [PATCH] feat: auto-bump fable-mcp patch version on commit via Claude Code hook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - scripts/bump_fable_mcp_version.sh: increments patch in pyproject.toml and stages it - scripts/pre_commit_fable_mcp.sh: PreToolUse Bash hook — fires before git commits, bumps version if fable-mcp files (other than pyproject.toml itself) are staged - .claude/settings.json: registers the PreToolUse hook Co-Authored-By: Claude Sonnet 4.6 --- scripts/bump_fable_mcp_version.sh | 17 ++++++++++++++ scripts/pre_commit_fable_mcp.sh | 39 +++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100755 scripts/bump_fable_mcp_version.sh create mode 100755 scripts/pre_commit_fable_mcp.sh diff --git a/scripts/bump_fable_mcp_version.sh b/scripts/bump_fable_mcp_version.sh new file mode 100755 index 0000000..16b658c --- /dev/null +++ b/scripts/bump_fable_mcp_version.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Bump the patch segment of fable-mcp/pyproject.toml version and stage the file. +# Usage: called automatically by the Claude Code pre-commit hook, or manually. +set -euo pipefail + +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +FILE="$REPO_ROOT/fable-mcp/pyproject.toml" + +current=$(grep '^version = ' "$FILE" | sed 's/version = "\(.*\)"/\1/') +major=$(echo "$current" | cut -d. -f1) +minor=$(echo "$current" | cut -d. -f2) +patch=$(echo "$current" | cut -d. -f3) +new_version="$major.$minor.$((patch + 1))" + +sed -i "s/^version = \"$current\"/version = \"$new_version\"/" "$FILE" +git -C "$REPO_ROOT" add "$FILE" +echo "fable-mcp: $current → $new_version" diff --git a/scripts/pre_commit_fable_mcp.sh b/scripts/pre_commit_fable_mcp.sh new file mode 100755 index 0000000..966b90e --- /dev/null +++ b/scripts/pre_commit_fable_mcp.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# Claude Code PreToolUse hook for Bash. +# Reads the tool input JSON from stdin; if the command is a git commit +# and fable-mcp files (other than pyproject.toml) are staged, bumps +# the fable-mcp patch version before the commit proceeds. +# +# Exits 0 always so it never blocks the commit. + +set -euo pipefail + +REPO_ROOT="/home/bvandeusen/Nextcloud/Projects/fabledassistant" + +input=$(cat) +command=$(echo "$input" | python3 -c " +import sys, json +data = json.load(sys.stdin) +# Claude Code sends {tool_input: {command: ...}} +ti = data.get('tool_input', data) +print(ti.get('command', '')) +" 2>/dev/null || echo "") + +# Only act on git commit commands +if ! echo "$command" | grep -qE "git commit"; then + exit 0 +fi + +cd "$REPO_ROOT" + +# Check if fable-mcp files other than pyproject.toml are staged +fable_staged=$(git diff --cached --name-only 2>/dev/null \ + | grep "^fable-mcp/" \ + | grep -v "^fable-mcp/pyproject.toml$" \ + || true) + +if [ -n "$fable_staged" ]; then + bash "$REPO_ROOT/scripts/bump_fable_mcp_version.sh" +fi + +exit 0