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 <noreply@anthropic.com>
This commit is contained in:
Snider 2026-02-02 07:31:51 +00:00 committed by GitHub
parent 737c471078
commit 89cc44eaf6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 79 additions and 0 deletions

View file

@ -0,0 +1,23 @@
---
name: sync
description: Sync changes across dependent modules
args: <module_name> [--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" "$@"
```

56
claude/code/scripts/sync.sh Executable file
View file

@ -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