--- name: executing-sequential-phase description: Use when orchestrating sequential phases in plan execution - executes tasks one-by-one in main worktree using git-spice natural stacking (NO manual upstack commands, NO worktree creation, tasks build on each other) --- # Executing Sequential Phase ## Overview **Sequential phases use natural git-spice stacking in the main worktree.** Each task creates a branch with `gs branch create`, which automatically stacks on the current HEAD. No manual stacking operations needed. **Critical distinction:** Sequential tasks BUILD ON each other. They need integration, not isolation. ## When to Use Use this skill when `execute` command encounters a phase marked "Sequential" in plan.md: - ✅ Tasks must run in order (dependencies) - ✅ Execute in existing `{runid}-main` worktree - ✅ Trust natural stacking (no manual `gs upstack onto`) - ✅ Stay on task branches (don't switch to base between tasks) **Sequential phases never use worktrees.** They share one workspace where tasks build cumulatively. ## Multi-Repo Support ### Receiving Multi-Repo Context The orchestrator passes: - `WORKSPACE_MODE`: "multi-repo" or "single-repo" - `WORKSPACE_ROOT`: Absolute path to workspace - Per-task `TASK_REPO` from plan ### Sequential Execution Across Repos In multi-repo mode, sequential tasks may span repos: ``` Phase 1 (sequential): - Task 1.1: repo=shared-lib # Shared types first - Task 1.2: repo=backend # Backend uses shared types - Task 1.3: repo=frontend # Frontend uses shared types ``` For each task, switch to that task's repo context. ### Per-Repo Worktrees In multi-repo sequential phases: - Each repo has its own main worktree: `{repo}/.worktrees/{runId}-main/` - Tasks execute in their repo's worktree - Switching tasks = switching repos (if different) ### Per-Repo Setup Commands Read setup commands from each task's repo: ```bash # Multi-repo: Read from task's repo CLAUDE.md INSTALL_CMD=$(grep -A1 "**install**:" ${TASK_REPO}/CLAUDE.md | tail -1) ``` ### Per-Repo Constitution Pass correct constitution to subagents: ```bash # Multi-repo CONSTITUTION="@${TASK_REPO}/docs/constitutions/current/" ``` ### Per-Repo Stacking Sequential tasks across repos create per-repo stacks: ``` Execution order: 1. Task 1.1 (shared-lib) → creates branch in shared-lib 2. Task 1.2 (backend) → creates branch in backend 3. Task 1.3 (backend) → stacks on 1.2 in backend 4. Task 1.4 (frontend) → creates branch in frontend Result: - shared-lib stack: task-1-1 - backend stack: task-1-2 → task-1-3 - frontend stack: task-1-4 ``` Each repo maintains its own linear stack. Cannot stack across repos. ### Single-Repo Mode (Unchanged) All existing behavior preserved: - Single main worktree at `.worktrees/{runId}-main/` - Single CLAUDE.md for setup commands - Single constitution at `@docs/constitutions/current/` - Single linear stack of branches ## The Natural Stacking Principle ``` SEQUENTIAL PHASE = MAIN WORKTREE + NATURAL STACKING ``` **What natural stacking means:** 1. Start on base branch (or previous task's branch) 2. Create new branch with `gs branch create` → automatically stacks on current 3. Stay on that branch when done 4. Next task creates from there → automatically stacks on previous **No manual commands needed.** The workflow IS the stacking. ## The Process **Announce:** "I'm using executing-sequential-phase to execute {N} tasks sequentially in Phase {phase-id}." ### Step 0: Verify Orchestrator Location **MANDATORY: Verify orchestrator is in correct location before any operations:** **Single-repo mode:** ```bash REPO_ROOT=$(git rev-parse --show-toplevel) CURRENT=$(pwd) if [ "$CURRENT" != "$REPO_ROOT" ]; then echo "❌ Error: Orchestrator must run from main repo root" echo "Current: $CURRENT" echo "Expected: $REPO_ROOT" echo "" echo "Return to main repo: cd $REPO_ROOT" exit 1 fi echo "✅ Orchestrator location verified: Main repo root" ``` **Multi-repo mode:** ```bash # Orchestrator runs from WORKSPACE_ROOT (parent of all repos) CURRENT=$(pwd) if [ "$CURRENT" != "$WORKSPACE_ROOT" ]; then echo "❌ Error: Orchestrator must run from workspace root" echo "Current: $CURRENT" echo "Expected: $WORKSPACE_ROOT" echo "" echo "Return to workspace: cd $WORKSPACE_ROOT" exit 1 fi echo "✅ Orchestrator location verified: Workspace root ($WORKSPACE_MODE mode)" ``` **Why critical:** - Orchestrator delegates work but never changes directory - Single-repo: All operations use `git -C .worktrees/path` or `bash -c "cd path && cmd"` - Multi-repo: All operations use `git -C {repo}/.worktrees/path` or `bash -c "cd {repo}/path && cmd"` - This assertion catches upstream drift immediately ### Step 1: Verify Setup and Base Branch **First, verify we're on the correct base branch for this phase:** **Single-repo mode:** ```bash # Get current branch in main worktree CURRENT_BRANCH=$(git -C .worktrees/{runid}-main branch --show-current) EXPECTED_BASE="{expected-base-branch}" # From plan: previous phase's last task, or {runid}-main for Phase 1 if [ "$CURRENT_BRANCH" != "$EXPECTED_BASE" ]; then echo "⚠️ WARNING: Phase {phase-id} starting from unexpected branch" echo " Current: $CURRENT_BRANCH" echo " Expected: $EXPECTED_BASE" echo "" echo "This means the previous phase ended on the wrong branch." echo "Possible causes:" echo "- Code review or quality checks switched branches" echo "- User manually checked out different branch" echo "- Resume from interrupted execution" echo "" echo "To fix:" echo "1. Verify previous phase completed: git log --oneline $EXPECTED_BASE" echo "2. Switch to correct base: cd .worktrees/{runid}-main && git checkout $EXPECTED_BASE" echo "3. Re-run /spectacular:execute" exit 1 fi echo "✅ Phase {phase-id} starting from correct base: $CURRENT_BRANCH" ``` **Multi-repo mode:** In multi-repo, base branch verification is per-repo. For each repo that has tasks in this phase: ```bash # For each repo with tasks in this phase for REPO in ${REPOS_IN_PHASE[@]}; do WORKTREE_PATH="${WORKSPACE_ROOT}/${REPO}/.worktrees/${RUN_ID}-main" # Check if this repo's worktree exists if [ ! -d "$WORKTREE_PATH" ]; then echo "Creating main worktree for repo: ${REPO}" bash </dev/null 2>&1; then echo "❌ ERROR: Branch '$BRANCH' not found" STACK_VALID=0 break fi BRANCH_SHA=$(git rev-parse "$BRANCH") # Check if this commit SHA was already seen if [ -n "${SEEN_COMMITS[$BRANCH_SHA]}" ]; then echo "❌ ERROR: Stack integrity violation" echo " Branch '$BRANCH' points to commit $BRANCH_SHA" echo " But '${SEEN_COMMITS[$BRANCH_SHA]}' already points to that commit" echo "" echo "This means one task created no new commits." echo "Possible causes:" echo "- Task implementation had no changes" echo "- Quality checks blocked commit" echo "- gs branch create failed silently" STACK_VALID=0 break fi SEEN_COMMITS[$BRANCH_SHA]="$BRANCH" echo " ✓ $BRANCH @ $BRANCH_SHA" done if [ $STACK_VALID -eq 0 ]; then echo "" echo "❌ Stack verification FAILED" echo "" echo "To investigate:" echo "1. Check task branch commits: git log --oneline \$BRANCH" echo "2. Review subagent output for failed task" echo "3. Check for quality check failures (test/lint/build)" echo "4. Fix and re-run /spectacular:execute" exit 1 fi echo "✅ Stack integrity verified - all tasks have unique commits" EOF ``` **Multi-repo mode:** Verify stacks in each repo that had tasks in this phase: ```bash # Group tasks by repo declare -A REPO_TASKS for task in ${TASKS[@]}; do REPO_TASKS[${task.repo}]+="${task.branch} " done # Verify each repo's stack ALL_VALID=1 for REPO in "${!REPO_TASKS[@]}"; do echo "📋 Stack for repo: ${REPO}" WORKTREE_PATH="${WORKSPACE_ROOT}/${REPO}/.worktrees/${RUN_ID}-main" bash </dev/null 2>&1; then echo "❌ ERROR: Branch '\$BRANCH' not found in ${REPO}" STACK_VALID=0 break fi BRANCH_SHA=\$(git rev-parse "\$BRANCH") if [ -n "\${SEEN_COMMITS[\$BRANCH_SHA]}" ]; then echo "❌ ERROR: Stack integrity violation in ${REPO}" echo " Branch '\$BRANCH' points to commit \$BRANCH_SHA" echo " But '\${SEEN_COMMITS[\$BRANCH_SHA]}' already points to that commit" STACK_VALID=0 break fi SEEN_COMMITS[\$BRANCH_SHA]="\$BRANCH" echo " ✓ \$BRANCH @ \$BRANCH_SHA" done if [ \$STACK_VALID -eq 0 ]; then exit 1 fi echo "✅ ${REPO} stack integrity verified" EOF if [ $? -ne 0 ]; then ALL_VALID=0 fi done if [ $ALL_VALID -eq 0 ]; then echo "" echo "❌ Multi-repo stack verification FAILED" echo "" echo "To investigate:" echo "1. Check failing repo's task branch commits" echo "2. Review subagent output for failed task" echo "3. Check for quality check failures (test/lint/build)" echo "4. Fix and re-run /spectacular:execute" exit 1 fi echo "✅ All repo stacks verified" ``` **Per-repo stacking result:** ``` Execution order: 1. Task 1.1 (shared-lib) → creates branch in shared-lib 2. Task 1.2 (backend) → creates branch in backend 3. Task 1.3 (backend) → stacks on 1.2 in backend 4. Task 1.4 (frontend) → creates branch in frontend Result: - shared-lib stack: task-1-1 - backend stack: task-1-2 → task-1-3 - frontend stack: task-1-4 ``` **Each `gs branch create` automatically stacked on the previous task's branch within that repo.** **Verification ensures:** Each task created a unique commit (no empty branches or duplicates). **Red flag:** "Run `gs upstack onto` to ensure stacking" - NO. Already stacked naturally. **Red flag:** "Stack across repos" - NO. Each repo has independent stack. ### Step 4: Code Review (Binary Quality Gate) **Check review frequency setting (from execute.md Step 1.7):** ```bash REVIEW_FREQUENCY=${REVIEW_FREQUENCY:-per-phase} ``` **If REVIEW_FREQUENCY is "end-only" or "skip":** ``` Skipping per-phase code review (frequency: {REVIEW_FREQUENCY}) Phase {N} complete - proceeding to next phase ``` Mark phase complete and continue to next phase. **If REVIEW_FREQUENCY is "optimize":** Analyze the completed phase to decide if code review is needed: **High-risk indicators (REVIEW REQUIRED):** - Schema or migration changes - Authentication/authorization logic - External API integrations or webhooks - Foundation phases (Phase 1-2 establishing patterns) - 3+ parallel tasks (coordination complexity) - New architectural patterns introduced - Security-sensitive code (payment, PII, access control) - Complex business logic with multiple edge cases - Changes affecting multiple layers (database → API → UI) **Low-risk indicators (SKIP REVIEW):** - Pure UI component additions (no state/logic) - Documentation or comment updates - Test additions without implementation changes - Refactoring with existing test coverage - Isolated utility functions - Configuration file updates (non-security) **Analyze this phase:** - Phase number: {N} - Tasks completed: {task-list} - Files modified: {file-list} - Types of changes: {describe changes} **Decision:** If ANY high-risk indicator present → Proceed to code review below If ONLY low-risk indicators → Skip review: ``` ✓ Phase {N} assessed as low-risk - skipping review (optimize mode) Reasoning: {brief explanation of why low-risk} Phase {N} complete - proceeding to next phase ``` **If REVIEW_FREQUENCY is "per-phase" OR optimize mode decided to review:** Use `requesting-code-review` skill, then parse results STRICTLY. **AUTONOMOUS EXECUTION:** Code review rejections trigger automatic fix loops, NOT user prompts. Never ask user what to do. 1. **Dispatch code review:** **Single-repo mode:** ``` Skill: requesting-code-review Context provided to reviewer: - WORKTREE: .worktrees/{runid}-main - PHASE: {phase-number} - TASKS: {task-list} - BASE_BRANCH: {base-branch-name} - SPEC: specs/{run-id}-{feature-slug}/spec.md - PLAN: specs/{run-id}-{feature-slug}/plan.md (for phase boundary validation) ``` **Multi-repo mode:** Review each repo that had tasks in this phase: ``` Skill: requesting-code-review Context provided to reviewer: - WORKSPACE_MODE: multi-repo - WORKSPACE_ROOT: {workspace-root} - REPOS_IN_PHASE: {list-of-repos-with-tasks} For each repo: - REPO: {repo-name} - WORKTREE: {repo}/.worktrees/{runid}-main - TASKS: {tasks-in-this-repo} - BASE_BRANCH: {repo-base-branch} - CONSTITUTION: {repo}/docs/constitutions/current/ Cross-repo context: - SPEC: {workspace-root}/specs/{run-id}-{feature-slug}/spec.md - PLAN: {workspace-root}/specs/{run-id}-{feature-slug}/plan.md **CRITICAL - EXHAUSTIVE FIRST-PASS REVIEW:** This is your ONLY opportunity to find issues. Re-review is for verifying fixes, NOT discovering new problems. Check EVERYTHING in this single review: □ Implementation correctness - logic bugs, edge cases, error handling, race conditions □ Test correctness - expectations match actual behavior, coverage is complete, no false positives □ Cross-file consistency - logic coherent across all files, no contradictions □ Architectural soundness - follows patterns, proper separation of concerns, no coupling issues □ Scope adherence - implements ONLY Phase {phase-number} work, no later-phase implementations □ Constitution compliance - follows all project standards and conventions Find ALL issues NOW. If you catch yourself thinking "I'll check that in re-review" - STOP. Check it NOW. Binary verdict required: "Ready to merge? Yes" (only if EVERYTHING passes) or "Ready to merge? No" (list ALL issues found) ``` 2. **Parse "Ready to merge?" field:** - **"Yes"** → APPROVED, continue to next phase - **"No"** or **"With fixes"** → REJECTED, dispatch fix subagent, go to step 3 - **No output / missing field** → RETRY ONCE, if retry fails → STOP - **Soft language** → REJECTED, re-review required 3. **Re-review loop (if REJECTED):** - Track rejections (REJECTION_COUNT) - If count > 3: Escalate to user (architectural issues beyond subagent scope) - Dispatch fix subagent with: * Issues list (severity + file locations) * Context: constitution, spec, plan * Scope enforcement: If scope creep, implement LESS (roll back to phase scope) * Quality checks required - Re-review after fixes (return to step 1) - On approval: Announce completion with iteration count **Critical:** Only "Ready to merge? Yes" allows proceeding. Everything else stops execution. **Phase completion:** - If `REVIEW_FREQUENCY="per-phase"`: Phase complete ONLY when code review returns "Ready to merge? Yes" - If `REVIEW_FREQUENCY="end-only"` or `"skip"`: Phase complete after all tasks finish (code review skipped) ## Rationalization Table | Excuse | Reality | |--------|---------| | "Need manual stacking commands" | `gs branch create` stacks automatically on current HEAD | | "Files don't overlap, could parallelize" | Plan says sequential for semantic dependencies | | "Create phase-specific worktree" | Sequential phases share main worktree (per repo in multi-repo) | | "Review rejected, ask user" | Autonomous execution means automatic fixes | | "Scope creep but quality passes" | Plan violation = failure. Auto-fix to plan | | "Use same worktree for all repos" | Multi-repo: each repo has its own worktree | | "Stack across repos" | Cannot stack across repos - each repo has independent stack | | "Use root CLAUDE.md for all repos" | Multi-repo: read each repo's own CLAUDE.md for setup commands | | "Use root constitution for all repos" | Multi-repo: use each task's repo constitution |