agent-browser-automati…
CommandAutomate browser interactions for development testing using Puppeteer MCP
Prepare branches for merging across multiple worktrees and coordinate integration
allowed-tools: Bash(git:*), Bash(gh:*), Bash(rg:*), Bash(fd:*), Bash(jq:*), Read, Grep, Write, TodoWrite name: "Agent Prep Merge" description: "Prepare branches for merging across multiple worktrees and coordinate integration" author: "wcygan" tags: ["agent","merge"] version: "1.0.0" created_at: "2025-07-14T00:00:00Z" updated_at: "2025-07-14T00:00:00Z"
Prepares branches from multiple worktrees for clean merging by checking for conflicts, running tests across affected code, generating merge strategies, and creating integration checklists. Essential for multi-agent development workflows.
# Prepare current branch for merging with main /agent-prep-merge # Prepare specific branches for integration /agent-prep-merge feature-auth feature-api # Prepare all worktree branches for coordinated merge /agent-prep-merge --all-worktrees # Generate integration plan without making changes /agent-prep-merge --dry-run
$ARGUMENTS
STEP 1: Initialize session and parse arguments
const SESSION_ID = await $`gdate +%s%N 2>/dev/null || date +%s000000000`.text().trim();
const PROJECT = await $`basename "$(git rev-parse --show-toplevel)"`.text();
const STATE_FILE = `/tmp/${PROJECT}/merge-prep-state-${SESSION_ID}.json`;
const COORDINATION_DIR = `/tmp/${PROJECT}`;
// Parse command arguments
let targetBranches: string[] = [];
let options = {
allWorktrees: false,
dryRun: false,
createPRs: false
};
IF ($ARGUMENTS.includes("--all-worktrees")) {
options.allWorktrees = true;
} ELSE IF ($ARGUMENTS.includes("--dry-run")) {
options.dryRun = true;
} ELSE IF ($ARGUMENTS.includes("--create-prs")) {
options.createPRs = true;
} ELSE IF ($ARGUMENTS && !$ARGUMENTS.startsWith("--")) {
targetBranches = $ARGUMENTS.split(" ");
} ELSE {
targetBranches = [await $`git branch --show-current`.text().trim()];
}
// Initialize state
const initialState = {
sessionId: SESSION_ID,
project: PROJECT,
timestamp: new Date().toISOString(),
targetBranches,
options,
phase: "initializing",
worktreeAnalysis: {},
conflictAnalysis: {},
testPlan: null,
mergeStrategy: null
};
await $`mkdir -p ${COORDINATION_DIR}`;
await Deno.writeTextFile(STATE_FILE, JSON.stringify(initialState, null, 2));STEP 2: Discover and analyze worktrees
# Get all active worktrees and their branches
WORKTREES_JSON=$(git worktree list --porcelain | awk '
BEGIN { print "[" }
/^worktree / { path = $2; printf "%s{\"path\":\"%s\",", (NR>1?",":""), path }
/^branch / { gsub(/^refs\/heads\//, "", $2); printf "\"branch\":\"%s\"}", $2 }
END { print "]" }
')
# Save worktree information
echo "$WORKTREES_JSON" | jq '.' > "/tmp/$PROJECT/worktrees-${SESSION_ID}.json"
# Update target branches based on options
IF [[ "$ALL_WORKTREES" == "true" ]]; then
TARGET_BRANCHES=$(echo "$WORKTREES_JSON" | jq -r '.[].branch' | tr '\n' ' ')
fi
echo "📋 Analyzing worktrees for branches: $TARGET_BRANCHES"STEP 3: Validate branch states (FOR EACH target branch)
FOR BRANCH in $TARGET_BRANCHES; do
echo "🔍 Validating branch: $BRANCH"
# Find worktree path for this branch
WORKTREE_PATH=$(echo "$WORKTREES_JSON" | jq -r ".[] | select(.branch==\"$BRANCH\") | .path")
IF [[ -z "$WORKTREE_PATH" ]]; then
echo "⚠️ Branch $BRANCH not found in any worktree"
continue
fi
cd "$WORKTREE_PATH" || continue
# Initialize branch analysis
BRANCH_STATE="{
\"branch\": \"$BRANCH\",
\"worktreePath\": \"$WORKTREE_PATH\",
\"status\": {
\"hasUncommittedChanges\": false,
\"isBehindMain\": false,
\"needsPush\": false,
\"isClean\": true
},
\"issues\": []
}"
# Check for uncommitted changes
UNCOMMITTED=$(git status --porcelain | wc -l)
IF [[ $UNCOMMITTED -gt 0 ]]; then
echo "⚠️ Branch $BRANCH has $UNCOMMITTED uncommitted changes"
BRANCH_STATE=$(echo "$BRANCH_STATE" | jq '.status.hasUncommittedChanges = true | .status.isClean = false | .issues += ["Uncommitted changes"]')
fi
# Check if branch is behind main
git fetch origin main >/dev/null 2>&1
BEHIND=$(git rev-list --count HEAD..origin/main 2>/dev/null || echo "0")
IF [[ $BEHIND -gt 0 ]]; then
echo "⚠️ Branch $BRANCH is $BEHIND commits behind main"
BRANCH_STATE=$(echo "$BRANCH_STATE" | jq --arg behind "$BEHIND" '.status.isBehindMain = true | .status.isClean = false | .issues += ["Behind main by \($behind) commits"]')
fi
# Check if branch needs to be pushed
LOCAL=$(git rev-parse HEAD)
REMOTE=$(git rev-parse "origin/$BRANCH" 2>/dev/null || echo "")
IF [[ "$LOCAL" != "$REMOTE" && -n "$REMOTE" ]]; then
echo "⚠️ Branch $BRANCH differs from origin"
BRANCH_STATE=$(echo "$BRANCH_STATE" | jq '.status.needsPush = true | .issues += ["Local differs from remote"]')
fi
# Save branch analysis
echo "$BRANCH_STATE" > "/tmp/$PROJECT/branch-analysis-$BRANCH-${SESSION_ID}.jsoA lightweight (~46kB) and comprehensive CLI tool for managing Claude commands, configurations, and workflows.
Automate browser interactions for development testing using Puppeteer MCP
Transform into accessibility expert for WCAG compliance and inclusive design
Transform into an API design specialist who creates well-structured, developer-friendly APIs
Transform into backend specialist for scalable API and system design
Cloud architect persona for designing scalable, secure cloud infrastructure using modern cloud-native technologies
Comprehensive code review with security, quality, and maintainability analysis
Implement tasks incrementally — build, test, verify, commit. Add "auto" to run the whole plan in one approved pass.