diff --git a/.claude/skills/setup-agent-team/discovery.sh b/.claude/skills/setup-agent-team/discovery.sh index adede4f6..7384705d 100755 --- a/.claude/skills/setup-agent-team/discovery.sh +++ b/.claude/skills/setup-agent-team/discovery.sh @@ -517,15 +517,32 @@ run_team_cycle() { git fetch --prune origin 2>/dev/null || true git pull --rebase origin main 2>/dev/null || true - # --- Pre-cycle cleanup: stale worktrees --- - log_info "Pre-cycle cleanup: stale worktrees..." + # --- Pre-cycle cleanup: stale worktrees and branches --- + log_info "Pre-cycle cleanup..." git worktree prune 2>/dev/null || true if [[ -d "${WORKTREE_BASE}" ]]; then rm -rf "${WORKTREE_BASE}" 2>/dev/null || true log_info "Removed stale ${WORKTREE_BASE} directory" fi - # Note: branch pruning and PR management is handled by the security team + # Delete merged discovery-related remote branches + # Discovery agents create branches like: add-*, impl-*, gap-filler-*, {cloud}-{agent} + MERGED_BRANCHES=$(git branch -r --merged origin/main | grep -v 'origin/main\|origin/HEAD' | grep -E 'origin/(add-|impl-|gap-filler-)' | sed 's|origin/||' | tr -d ' ') || true + for branch in $MERGED_BRANCHES; do + if [[ -n "$branch" ]]; then + git push origin --delete "$branch" 2>&1 && log_info "Deleted merged branch: $branch" || true + fi + done + + # Delete stale local discovery-related branches + LOCAL_BRANCHES=$(git branch --list 'add-*' --list 'impl-*' --list 'gap-filler-*' | tr -d ' *') || true + for branch in $LOCAL_BRANCHES; do + if [[ -n "$branch" ]]; then + git branch -D "$branch" 2>/dev/null || true + fi + done + + log_info "Pre-cycle cleanup done." # Set up worktree directory for parallel agent work mkdir -p "${WORKTREE_BASE}" diff --git a/.claude/skills/setup-agent-team/refactor.sh b/.claude/skills/setup-agent-team/refactor.sh index 75d7324a..758d42df 100755 --- a/.claude/skills/setup-agent-team/refactor.sh +++ b/.claude/skills/setup-agent-team/refactor.sh @@ -86,14 +86,30 @@ if [[ "${RUN_MODE}" == "refactor" ]]; then # Reset main checkout to origin/main git reset --hard origin/main 2>&1 | tee -a "${LOG_FILE}" || true - log "Pre-cycle cleanup: stale worktrees..." + log "Pre-cycle cleanup: stale worktrees and branches..." git worktree prune 2>&1 | tee -a "${LOG_FILE}" || true if [[ -d "${WORKTREE_BASE}" ]]; then rm -rf "${WORKTREE_BASE}" 2>&1 | tee -a "${LOG_FILE}" || true log "Removed stale ${WORKTREE_BASE} directory" fi - # Note: branch pruning and PR management is handled by the security team + # Delete merged refactor-related remote branches (fix/*, refactor/*, test/*, ux/*) + MERGED_BRANCHES=$(git branch -r --merged origin/main | grep -v 'origin/main\|origin/HEAD' | grep -E 'origin/(fix/|refactor/|test/|ux/)' | sed 's|origin/||' | tr -d ' ') || true + for branch in $MERGED_BRANCHES; do + if [[ -n "$branch" ]]; then + git push origin --delete "$branch" 2>&1 | tee -a "${LOG_FILE}" && log "Deleted merged branch: $branch" || true + fi + done + + # Delete stale local refactor-related branches + LOCAL_BRANCHES=$(git branch --list 'fix/*' --list 'refactor/*' --list 'test/*' --list 'ux/*' | tr -d ' *') || true + for branch in $LOCAL_BRANCHES; do + if [[ -n "$branch" ]]; then + git branch -D "$branch" 2>&1 | tee -a "${LOG_FILE}" || true + fi + done + + log "Pre-cycle cleanup done." fi # Launch Claude Code with mode-specific prompt diff --git a/.claude/skills/setup-agent-team/security.sh b/.claude/skills/setup-agent-team/security.sh index 7655b5dc..4675d53f 100644 --- a/.claude/skills/setup-agent-team/security.sh +++ b/.claude/skills/setup-agent-team/security.sh @@ -115,10 +115,35 @@ if [[ "${RUN_MODE}" == "team_building" ]] || [[ "${RUN_MODE}" == "triage" ]]; th log "Issue: #${ISSUE_NUM}" fi -# Fetch latest refs (read-only, safe for concurrent runs) -log "Fetching latest refs..." +# Pre-cycle cleanup (stale branches, worktrees from prior runs) +log "Pre-cycle cleanup..." git fetch --prune origin 2>&1 | tee -a "${LOG_FILE}" || true +# Clean stale worktrees +git worktree prune 2>&1 | tee -a "${LOG_FILE}" || true +if [[ -d "${WORKTREE_BASE}" ]]; then + rm -rf "${WORKTREE_BASE}" 2>&1 | tee -a "${LOG_FILE}" || true + log "Removed stale ${WORKTREE_BASE} directory" +fi + +# Delete merged security-related remote branches (team-building/*, review-pr-*) +MERGED_BRANCHES=$(git branch -r --merged origin/main | grep -E 'origin/(team-building/|review-pr-)' | sed 's|origin/||' | tr -d ' ') || true +for branch in $MERGED_BRANCHES; do + if [[ -n "$branch" ]]; then + git push origin --delete "$branch" 2>&1 | tee -a "${LOG_FILE}" && log "Deleted merged branch: $branch" || true + fi +done + +# Delete stale local security-related branches +LOCAL_BRANCHES=$(git branch --list 'team-building/*' --list 'review-pr-*' | tr -d ' *') || true +for branch in $LOCAL_BRANCHES; do + if [[ -n "$branch" ]]; then + git branch -D "$branch" 2>&1 | tee -a "${LOG_FILE}" || true + fi +done + +log "Pre-cycle cleanup done." + # Launch Claude Code with mode-specific prompt log "Launching ${RUN_MODE} cycle..."