From 89cc44eaf6db1be8c1c9f22d2996c0db03893d48 Mon Sep 17 00:00:00 2001 From: Snider Date: Mon, 2 Feb 2026 07:31:51 +0000 Subject: [PATCH] feat(code): add /code:sync for dependent module sync (#119) Add sync command that: - Finds dependent modules from repos.yaml - Updates composer.json with new version - Supports --dry-run for preview - Auto-detects current module from directory Migrated from core-claude PR #63. Co-authored-by: Claude Opus 4.5 --- claude/code/commands/sync.md | 23 +++++++++++++++ claude/code/scripts/sync.sh | 56 ++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 claude/code/commands/sync.md create mode 100755 claude/code/scripts/sync.sh diff --git a/claude/code/commands/sync.md b/claude/code/commands/sync.md new file mode 100644 index 0000000..3764039 --- /dev/null +++ b/claude/code/commands/sync.md @@ -0,0 +1,23 @@ +--- +name: sync +description: Sync changes across dependent modules +args: [--dry-run] +--- + +# Sync Dependent Modules + +When changing a base module, this command syncs the dependent modules. + +## Usage + +``` +/code:sync # Sync all dependents of current module +/code:sync core-tenant # Sync specific module +/code:sync --dry-run # Show what would change +``` + +## Action + +```bash +"${CLAUDE_PLUGIN_ROOT}/scripts/sync.sh" "$@" +``` diff --git a/claude/code/scripts/sync.sh b/claude/code/scripts/sync.sh new file mode 100755 index 0000000..b7b9224 --- /dev/null +++ b/claude/code/scripts/sync.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +dry_run=false +target_module="" + +while [[ $# -gt 0 ]]; do + case "$1" in + --dry-run) + dry_run=true + shift + ;; + *) + target_module="$1" + shift + ;; + esac +done + +if [ ! -f "repos.yaml" ]; then + echo "Error: repos.yaml not found" + exit 1 +fi + +if [ -z "$target_module" ]; then + # Detect from current directory + target_module=$(basename "$(pwd)") +fi + +echo "Syncing dependents of $target_module..." + +# Get version from composer.json +version=$(jq -r '.version // "1.0.0"' "${target_module}/composer.json" 2>/dev/null || echo "1.0.0") + +# Find dependents from repos.yaml +dependents=$(yq -r ".repos | to_entries[] | select(.value.depends[]? == \"$target_module\") | .key" repos.yaml 2>/dev/null) + +if [ -z "$dependents" ]; then + echo "No dependents found for $target_module" + exit 0 +fi + +echo "Dependents:" +for dep in $dependents; do + echo "├── $dep" + if [ "$dry_run" = true ]; then + echo "│ └── [dry-run] Would update host-uk/$target_module to v$version" + else + composer_file="${dep}/composer.json" + if [ -f "$composer_file" ]; then + jq --arg pkg "host-uk/$target_module" --arg ver "$version" \ + '.require[$pkg] = $ver' "$composer_file" > "$composer_file.tmp" && \ + mv "$composer_file.tmp" "$composer_file" + echo "│ └── Updated composer.json" + fi + fi +done