AgentSkillsCN

sdlc:complete

完成当前工作,并重置本地环境,为下一阶段任务做好准备。

SKILL.md
--- frontmatter
name: sdlc:complete
description: Finish work and reset local environment for next task
allowed-tools:
  - Bash(git:*)
  - Bash(gh:*)
  - Bash(linearis:*)

Complete Work

Finish the current task and reset the local environment for the next piece of work.

Workflow

  1. Verify PR is merged - Confirm the work is complete
  2. Update Linear issue - Mark as Done (if applicable)
  3. Checkout main - Switch to main branch
  4. Pull latest - Get all merged changes
  5. Cleanup branches - Delete merged local branches
  6. Confirm reset - Show clean state

Step 1: Verify PR is Merged

Check if the current branch has a merged PR:

bash
BASE_BRANCH=$(../../scripts/get-base-branch.sh)
CURRENT_BRANCH=$(git branch --show-current)

# Skip if already on default branch
if [ "$CURRENT_BRANCH" = "$BASE_BRANCH" ]; then
  echo "Already on default branch ($BASE_BRANCH)"
else
  # Check PR status
  PR_STATE=$(gh pr view --json state --jq '.state' 2>/dev/null || echo "NONE")

  if [ "$PR_STATE" = "OPEN" ]; then
    echo "WARNING: PR for $CURRENT_BRANCH is still open"
    echo "Are you sure you want to abandon this work?"
    # Continue anyway - user may want to discard
  elif [ "$PR_STATE" = "MERGED" ]; then
    echo "PR merged successfully"
  elif [ "$PR_STATE" = "NONE" ]; then
    echo "No PR found for branch $CURRENT_BRANCH. Proceeding to clean up local branch."
  fi
fi

Step 2: Update Linear Issue (Optional)

If the branch name looks like a Linear issue ID (e.g., ATE-123), update its status:

bash
# Extract issue ID from branch name if it matches pattern
ISSUE_ID=$(echo "$CURRENT_BRANCH" | grep -oE '^[A-Z]+-[0-9]+')

if [ -n "$ISSUE_ID" ] && command -v linearis &> /dev/null; then
  echo "Marking $ISSUE_ID as Done..."
  linearis issues update "$ISSUE_ID" --state "Done" 2>/dev/null || true
fi

Step 3: Checkout Default Branch

bash
# BASE_BRANCH was determined in Step 1
git checkout "$BASE_BRANCH"

Step 4: Pull Latest

bash
git pull origin "$BASE_BRANCH"

Step 5: Cleanup Branches

Prune remote tracking branches:

bash
git fetch --prune

List branches and identify those that can be deleted:

bash
git branch -vv

For branches showing [gone] (remote was deleted after merge), delete them:

bash
# Delete branches where remote is gone (uses conditional formatting for efficiency)
git for-each-ref --format='%(if:equals=gone)%(upstream:track,nobracket)%(then)%(refname:short)%(end)' refs/heads | while read -r branch; do
  [ -z "$branch" ] && continue
  echo "Deleting merged branch: $branch"
  git branch -d "$branch"
done

Also delete the branch we were just on if it's different from the default branch:

bash
if [ "$CURRENT_BRANCH" != "$BASE_BRANCH" ]; then
  git branch -d "$CURRENT_BRANCH" 2>/dev/null || true
fi

Step 6: Confirm Reset

Show the clean state:

bash
echo ""
echo "Environment reset complete"
echo "Branch: $(git branch --show-current)"
echo "Status:"
git status --short

Output

code
Environment reset complete
Branch: main
Status: (clean)

Ready for next task. Use /sdlc:plan <issue-id> to start.