- Upgraded @bytelyst/auth middleware to throw ServiceError types (UnauthorizedError, ForbiddenError) - Added @bytelyst/errors as dependency to auth package - 11 new middleware tests (extractAuth + requireRole) - 4 new E2E tests (full login → JWT → auth → role check flow) - Refactored tracker-service lib/auth.ts from 48-line local impl to 1-line re-export - Added @bytelyst/auth as tracker-service dependency - All 277 tests pass, 0 regressions
14 KiB
14 KiB
| description | date |
|---|---|
| Intelligent workspace sync - check, review, and commit changes across all repos | 2025-02-12 |
Workspace Sync Workflow
Intelligently manages uncommitted changes across all 3 workspace repos with interactive approval. Preserves developer knowledge and prevents data loss through careful review and conflict resolution.
Overview
This workflow helps maintain a clean workspace by:
- Scanning all repos for uncommitted changes
- Displaying changes in an organized, reviewable format
- Suggesting logical commit groups based on change types
- Interactive approval before each commit
- Safe conflict resolution with rebase
- Pushing in dependency order (common_plat → voice_agent → mindlyst)
Prerequisites
- Git CLI installed
- All repos cloned and accessible
- Proper Git credentials configured
Workflow Steps
Step 1: Scan Workspace for Changes
# Create workspace sync script
cat > ~/workspace-sync.sh << 'EOF'
#!/bin/bash
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Workspace paths
WORKSPACE="$HOME/code/mygh"
REPOS=(
"learning_ai_common_plat:Common Platform:First"
"learning_voice_ai_agent:LysnrAI:Second"
"learning_multimodal_memory_agents:MindLyst:Third"
)
echo -e "${BLUE}🔍 Scanning workspace for uncommitted changes...${NC}"
echo
# Track repos with changes
REPOS_WITH_CHANGES=()
for repo_info in "${REPOS[@]}"; do
IFS=':' read -r repo_name display_name order <<< "$repo_info"
repo_path="$WORKSPACE/$repo_name"
if [ -d "$repo_path" ]; then
cd "$repo_path"
# Check for uncommitted changes
if ! git diff --quiet || ! git diff --cached --quiet || [ -n "$(git ls-files --others --exclude-standard)" ]; then
REPOS_WITH_CHANGES+=("$repo_name:$display_name:$order")
echo -e "${CYAN}📁 $display_name${NC} (${YELLOW}$repo_name${NC})"
# Staged changes
if [ -n "$(git diff --cached --name-only)" ]; then
echo -e " ${GREEN}Staged changes:${NC}"
git diff --cached --stat
fi
# Unstaged changes
if [ -n "$(git diff --name-only)" ]; then
echo -e " ${YELLOW}Unstaged changes:${NC}"
git diff --stat
fi
# Untracked files
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
echo -e " ${RED}Untracked files:${NC}"
git ls-files --others --exclude-standard | head -10
count=$(git ls-files --others --exclude-standard | wc -l)
[ $count -gt 10 ] && echo " ... and $((count - 10)) more"
fi
# Branch status
branch_status=$(git status --porcelain -b | head -1)
if [[ $branch_status == *"ahead"* ]]; then
echo -e " ${YELLOW}⚠️ Branch is ahead of origin${NC}"
fi
if [[ $branch_status == *"behind"* ]]; then
echo -e " ${YELLOW}⚠️ Branch is behind origin${NC}"
fi
echo
fi
fi
done
if [ ${#REPOS_WITH_CHANGES[@]} -eq 0 ]; then
echo -e "${GREEN}✅ All repos are clean!${NC}"
exit 0
fi
echo -e "${BLUE}📊 Summary: Found changes in ${#REPOS_WITH_CHANGES[@]} repo(s)${NC}"
echo
EOF
chmod +x ~/workspace-sync.sh
Step 2: Interactive Review and Commit
# Add interactive commit functionality
cat >> ~/workspace-sync.sh << 'EOF'
# Function to suggest commit message based on changes
suggest_commit_message() {
local repo_path="$1"
cd "$repo_path"
# Analyze changes
has_ci_changes=$(git diff --cached --name-only | grep -E "\.github|ci|workflow" || echo "")
has_docs_changes=$(git diff --cached --name-only | grep -E "README|\.md$" || echo "")
has_code_changes=$(git diff --cached --name-only | grep -E "\.(ts|js|py|kt|swift)$" || echo "")
has_test_changes=$(git diff --cached --name-only | grep -E "test|spec" || echo "")
has_config_changes=$(git diff --cached --name-only | grep -E "package\.json|requirements|gradle|\.env" || echo "")
# Suggest message
if [ -n "$has_ci_changes" ]; then
echo "ci: update CI/CD configuration"
elif [ -n "$has_docs_changes" ] && [ -z "$has_code_changes" ]; then
echo "docs: update documentation"
elif [ -n "$has_test_changes" ] && [ -z "$has_code_changes" ]; then
echo "test: update test suite"
elif [ -n "$has_config_changes" ]; then
echo "chore: update dependencies and configuration"
else
echo "feat: implement new features and improvements"
fi
}
# Function to safely commit with review
safe_commit() {
local repo_name="$1"
local display_name="$2"
local repo_path="$WORKSPACE/$repo_name"
cd "$repo_path"
echo -e "${BLUE}📋 Reviewing changes for $display_name${NC}"
echo
# Show detailed diff
echo -e "${CYAN}Press Enter to see diff summary, 's' to skip, 'q' to quit${NC}"
read -r response
if [[ "$response" == "q" ]]; then
echo -e "${RED}Quitting workflow${NC}"
exit 0
elif [[ "$response" != "s" ]]; then
git diff --cached --stat 2>/dev/null || true
git diff --stat 2>/dev/null || true
echo
fi
# Ask what to do with changes
echo -e "${YELLOW}Choose action:${NC}"
echo " 1) Stage all changes and commit"
echo " 2) Review and stage specific files"
echo " 3) Skip this repo"
echo " q) Quit workflow"
read -r action
case $action in
1)
# Stage all changes
git add -A
;;
2)
# Interactive staging
echo -e "${CYAN}Files to stage:${NC}"
git status --porcelain
echo -e "${YELLOW}Enter files to stage (space-separated, or 'all'):${NC}"
read -r files_to_stage
if [[ "$files_to_stage" == "all" ]]; then
git add -A
else
git add $files_to_stage
fi
;;
3)
echo -e "${YELLOW}Skipping $display_name${NC}"
return
;;
q)
echo -e "${RED}Quitting workflow${NC}"
exit 0
;;
esac
# Check if there's anything to commit
if git diff --cached --quiet; then
echo -e "${YELLOW}No changes staged, skipping${NC}"
return
fi
# Suggest commit message
suggested_msg=$(suggest_commit_message "$repo_path")
echo -e "${CYAN}Suggested commit message: $suggested_msg${NC}"
echo -e "${YELLOW}Enter commit message (or press Enter to accept suggestion):${NC}"
read -r commit_msg
if [[ -z "$commit_msg" ]]; then
commit_msg="$suggested_msg"
fi
# Confirm commit
echo -e "${YELLOW}Commit with message: '$commit_msg'? (y/N)${NC}"
read -r confirm
if [[ "$confirm" == "y" || "$confirm" == "Y" ]]; then
git commit -m "$commit_msg"
echo -e "${GREEN}✅ Committed changes in $display_name${NC}"
else
echo -e "${YELLOW}Commit cancelled${NC}"
fi
}
EOF
Step 3: Safe Push with Conflict Resolution
# Add push and conflict resolution
cat >> ~/workspace-sync.sh << 'EOF'
# Function to safely push with conflict resolution
safe_push() {
local repo_name="$1"
local display_name="$2"
local repo_path="$WORKSPACE/$repo_name"
cd "$repo_path"
# Check if we're ahead of origin
if git log --oneline origin/main..main 2>/dev/null | grep -q .; then
echo -e "${BLUE}📤 Pushing $display_name...${NC}"
# Try to push
if git push 2>/dev/null; then
echo -e "${GREEN}✅ Pushed $display_name successfully${NC}"
else
echo -e "${YELLOW}⚠️ Push failed, attempting to pull and rebase...${NC}"
# Fetch latest changes
git fetch
# Check if we have diverged
if git log --oneline main..origin/main | grep -q .; then
echo -e "${YELLOW}Local and remote have diverged. Options:${NC}"
echo " 1) Pull --rebase (rebase your changes on top of remote)"
echo " 2) Pull --no-rebase (merge remote changes)"
echo " 3) Skip pushing and handle manually"
read -r choice
case $choice in
1)
git pull --rebase
if git push; then
echo -e "${GREEN}✅ Pushed after rebase${NC}"
else
echo -e "${RED}❌ Still failed to push after rebase${NC}"
echo -e "${CYAN}Please resolve conflicts manually in $repo_path${NC}"
fi
;;
2)
git pull --no-rebase
if git push; then
echo -e "${GREEN}✅ Pushed after merge${NC}"
else
echo -e "${RED}❌ Still failed to push after merge${NC}"
fi
;;
3)
echo -e "${YELLOW}Skipping push. Please handle manually.${NC}"
;;
esac
else
# Just need to push
git push
echo -e "${GREEN}✅ Pushed $display_name${NC}"
fi
fi
fi
}
# Main execution
main() {
# Sort repos by dependency order
sorted_repos=($(printf '%s\n' "${REPOS_WITH_CHANGES[@]}" | sort -k3 -t':'))
echo -e "${BLUE}🚀 Starting interactive sync process...${NC}"
echo
for repo_info in "${sorted_repos[@]}"; do
IFS=':' read -r repo_name display_name order <<< "$repo_info"
safe_commit "$repo_name" "$display_name"
echo
done
# Ask about pushing
echo -e "${YELLOW}Push all committed changes to origin? (y/N)${NC}"
read -r push_confirm
if [[ "$push_confirm" == "y" || "$push_confirm" == "Y" ]]; then
echo -e "${BLUE}📤 Pushing in dependency order...${NC}"
echo
for repo_info in "${sorted_repos[@]}"; do
IFS=':' read -r repo_name display_name order <<< "$repo_info"
safe_push "$repo_name" "$display_name"
echo
done
else
echo -e "${YELLOW}Skipping push. Changes are committed locally.${NC}"
fi
echo -e "${GREEN}✨ Workspace sync complete!${NC}"
}
# Run main function
main
EOF
echo "Created workspace-sync.sh at ~/workspace-sync.sh"
Step 4: Create VS Code Task for Easy Access
# Create .vscode/tasks.json in each repo
cat > /Users/sd9235/code/mygh/learning_ai_common_plat/.vscode/tasks.json << 'EOF'
{
"version": "2.0.0",
"tasks": [
{
"label": "Workspace Sync",
"type": "shell",
"command": "~/workspace-sync.sh",
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "new"
},
"problemMatcher": []
}
]
}
EOF
# Copy to other repos
cp /Users/sd9235/code/mygh/learning_ai_common_plat/.vscode/tasks.json \
/Users/sd9235/code/mygh/learning_voice_ai_agent/.vscode/tasks.json
cp /Users/sd9235/code/mygh/learning_ai_common_plat/.vscode/tasks.json \
/Users/sd9235/code/mygh/learning_multimodal_memory_agents/.vscode/tasks.json
Usage
Option 1: Run from Terminal
~/workspace-sync.sh
Option 2: Run from VS Code
- Open any workspace repo
- Press
Cmd+Shift+P(macOS) orCtrl+Shift+P(Windows/Linux) - Type "Tasks: Run Task"
- Select "Workspace Sync"
Option 3: Create Git Alias
git config --global alias.ws '!~/workspace-sync.sh'
# Then run: git ws
Features
🔍 Smart Detection
- Identifies staged, unstaged, and untracked files
- Detects branch divergence (ahead/behind)
- Shows change statistics
📝 Intelligent Suggestions
- Suggests commit messages based on changed file types
- Follows conventional commit format
- Recognizes CI, docs, test, and feature changes
🛡️ Safety First
- Interactive review before each commit
- Confirmation before destructive operations
- Preserves developer knowledge and consent
🔄 Conflict Resolution
- Automatic fetch before push
- Interactive choice between rebase/merge
- Clear guidance for manual resolution
📊 Dependency Ordering
- Automatically pushes in correct order
- Common Platform → LysnrAI → MindLyst
- Prevents dependency issues
Example Session
🔍 Scanning workspace for uncommitted changes...
📁 Common Platform (learning_ai_common_plat)
Staged changes:
src/index.ts | 2 +-
README.md | 5 +++++
Untracked files:
new-feature.ts
📁 LysnrAI (learning_voice_ai_agent)
Unstaged changes:
src/app.py | 10 ++++++++++
requirements.txt | 2 +-
📊 Summary: Found changes in 2 repo(s)
🚀 Starting interactive sync process...
📋 Reviewing changes for Common Platform
Press Enter to see diff summary, 's' to skip, 'q' to quit
Choose action:
1) Stage all changes and commit
2) Review and stage specific files
3) Skip this repo
q) Quit workflow
1
Suggested commit message: feat: implement new features and improvements
Enter commit message (or press Enter to accept suggestion): feat: add new feature and update docs
Commit with message: 'feat: add new feature and update docs'? (y/N) y
✅ Committed changes in Common Platform
...
Best Practices
- Run before switching contexts: Always run workspace sync before moving to another task
- Review carefully: The interactive review prevents accidental commits
- Handle conflicts manually: If rebase/merge fails, resolve conflicts to understand what changed
- Commit frequently: Small, focused commits are easier to review and sync
- Use descriptive messages: Good commit messages help track changes across repos
Troubleshooting
Permission Issues
chmod +x ~/workspace-sync.sh
Git Credentials
git config --global credential.helper store
SSH Key Issues
ssh-add ~/.ssh/id_rsa
Customization
You can customize the script by:
- Adding more repos to the
REPOSarray - Modifying commit message suggestions
- Adding custom conflict resolution strategies
- Integrating with your team's workflow
Remember: This workflow preserves your knowledge and control over what gets committed. Never skip the review steps!