Loading...
Loading...
Use to execute an implementation plan with automatic sequential/parallel orchestration - handles worktree verification, resume detection, phase dispatch, and quality verification
npx skill4agent add arittr/spectacular executing-plandecomposing-tasks/spectacular:executeexecuting-sequential-phaseexecuting-parallel-phasephase-task-verificationtests/README.mdCLAUDE.mdexecuting-parallel-phaseexecuting-sequential-phaseunderstanding-cross-phase-stackingvalidating-setup-commandsusing-git-spicerequesting-code-reviewverification-before-completionfinishing-a-development-branchtroubleshooting-executeusing-git-worktrees# Detect workspace mode
REPO_COUNT=$(find . -maxdepth 2 -name ".git" -type d 2>/dev/null | wc -l | tr -d ' ')
if [ "$REPO_COUNT" -gt 1 ]; then
echo "Multi-repo workspace detected ($REPO_COUNT repos)"
WORKSPACE_MODE="multi-repo"
REPOS=$(find . -maxdepth 2 -name ".git" -type d | xargs -I{} dirname {} | sed 's|^\./||' | tr '\n' ' ')
echo "Available repos: $REPOS"
else
echo "Single-repo mode"
WORKSPACE_MODE="single-repo"
fi| Aspect | Single-Repo | Multi-Repo |
|---|---|---|
| Worktree | | Per-task: |
| Spec location | | |
| Setup commands | One CLAUDE.md | Per-repo CLAUDE.md |
| Constitution | | |
| Git-spice stack | Single stack | Per-repo stacks |
**Multi-repo context for phase:**
- WORKSPACE_MODE: multi-repo
- WORKSPACE_ROOT: {absolute path}
- Task repos: {list of repos with tasks in this phase}
- Per-task repo: extracted from plan's `**Repo**: {repo}` field/spectacular:execute {plan-path}/spectacular:execute @specs/a1b2c3-magic-link-auth/plan.mda1b2c3magic-link-auth.worktrees/3a00a7-main/specs/3a00a7-agent-standardization-refactor/plan.md.worktrees/3a00a7-main/specs/3a00a7-agent-standardization-refactor/plan.md3a00a7-agent-standardization-refactor3a00a7# Extract RUN_ID and FEATURE_SLUG from plan path (replace {the-plan-path-user-provided} with actual path)
PLAN_PATH="{the-plan-path-user-provided}"
DIR_NAME=$(echo "$PLAN_PATH" | sed 's|^.*specs/||; s|/plan.md$||')
RUN_ID=$(echo "$DIR_NAME" | cut -d'-' -f1)
FEATURE_SLUG=$(echo "$DIR_NAME" | cut -d'-' -f2-)
echo "Extracted RUN_ID: $RUN_ID"
echo "Extracted FEATURE_SLUG: $FEATURE_SLUG"
# Verify RUN_ID and FEATURE_SLUG are not empty
if [ -z "$RUN_ID" ]; then
echo "Error: Could not extract RUN_ID from plan path: $PLAN_PATH"
exit 1
fi
if [ -z "$FEATURE_SLUG" ]; then
echo "Error: Could not extract FEATURE_SLUG from plan path: $PLAN_PATH"
exit 1
fi$(...){run-id}-task-X-Y-namegit branch | grep "^ {run-id}-"specs/{run-id}-{feature-slug}/spec.mdif [ "$WORKSPACE_MODE" = "multi-repo" ]; then
echo "Multi-repo mode: Worktrees created per-task during execution"
# Verify spec exists at workspace root
if [ ! -f "specs/${RUN_ID}-${FEATURE_SLUG}/plan.md" ]; then
echo "Error: Plan not found at specs/${RUN_ID}-${FEATURE_SLUG}/plan.md"
exit 1
fi
echo "Plan verified: specs/${RUN_ID}-${FEATURE_SLUG}/plan.md"
fi# Get absolute repo root (stay in main repo, don't cd into worktree)
REPO_ROOT=$(git rev-parse --show-toplevel)
# Verify worktree exists
if [ ! -d "$REPO_ROOT/.worktrees/${RUN_ID}-main" ]; then
echo "Error: Worktree not found at .worktrees/${RUN_ID}-main"
echo "Run /spectacular:spec first to create the workspace."
exit 1
fi
# Verify it's a valid worktree
git worktree list | grep "${RUN_ID}-main"git -C .worktrees/{run-id}-main# Get repo root
REPO_ROOT=$(git rev-parse --show-toplevel)
# Check current branch in main worktree
CURRENT_BRANCH=$(git -C "$REPO_ROOT/.worktrees/${RUN_ID}-main" branch --show-current 2>/dev/null || echo "")
# Count existing task branches for this RUN_ID
EXISTING_TASKS=$(git branch 2>/dev/null | grep -c "^ ${RUN_ID}-task-" || echo "0")
# Report status
if [ "$EXISTING_TASKS" -gt 0 ]; then
echo "Found $EXISTING_TASKS existing task branch(es) for RUN_ID: $RUN_ID"
echo " Current branch: $CURRENT_BRANCH"
echo ""
echo "Resuming from current state. The execution will:"
echo "- Sequential phases: Continue from current branch"
echo "- Parallel phases: Skip completed tasks, run remaining"
echo ""
else
echo "No existing work found - starting fresh execution"
echo ""
fi$(...)EXISTING_TASKS > 0EXISTING_TASKS = 0Task 4.2:
Name: Integrate prompts module into generator
Files: - src/generator.ts - src/types.ts
Acceptance Criteria: - Import PromptService from prompts module - Replace manual prompt construction with PromptService.getCommitPrompt() - Update tests to mock PromptService - All tests pass
Dependencies: Task 4.1 (fallback logic removed)repoTask 4.2:
Name: Integrate prompts module into generator
Repo: backend # NEW - required in multi-repo mode
Files: - src/generator.ts - src/types.ts
Acceptance Criteria: - Import PromptService from prompts module - Replace manual prompt construction with PromptService.getCommitPrompt() - Update tests to mock PromptService - All tests pass
Dependencies: Task 4.1 (fallback logic removed)validating-setup-commandsINSTALL_CMDPOSTINSTALL_CMDpackage.jsonpytestruffblackgo testgolangci-lintcargo testcargo clippyTEST_CMDLINT_CMDFORMAT_CMDBUILD_CMD# Check if REVIEW_FREQUENCY env var is set
REVIEW_FREQUENCY=${REVIEW_FREQUENCY:-}REVIEW_FREQUENCYQuestion: "How frequently should code reviews run during execution?"
Header: "Review Frequency"
Options:
1. "After each phase"
Description: "Run code review after every phase completes (safest - catches errors early, prevents compounding issues)"
2. "Optimize automatically"
Description: "Let Claude decide when to review based on phase risk/complexity (RECOMMENDED - balances speed and quality)"
3. "Only at end"
Description: "Skip per-phase reviews, run one review after all phases complete (faster, but errors may compound)"
4. "Skip reviews"
Description: "No automated code reviews (fastest, but requires manual review before merging)"REVIEW_FREQUENCY="per-phase"REVIEW_FREQUENCY="optimize"REVIEW_FREQUENCY="end-only"REVIEW_FREQUENCY="skip"Code review frequency: {REVIEW_FREQUENCY}REVIEW_FREQUENCYWORKSPACE_MODEWORKSPACE_ROOTTASK_REPOWORKSPACE_MODE: multi-repo
WORKSPACE_ROOT: /home/user/workspace
Phase 2 tasks:
- Task 2.1: repo=backend
- Task 2.2: repo=frontend
- Task 2.3: repo=frontendREVIEW_FREQUENCYper-phaseoptimizeend-onlyskipunderstanding-cross-phase-stackingexecuting-sequential-phase{runid}-maings upstack onto{run-id}{feature-slug}specs/{run-id}-{feature-slug}/spec.mdexecuting-parallel-phase{run-id}{feature-slug}specs/{run-id}-{feature-slug}/spec.mdverification-before-completion# Run full test suite
if [ -n "$TEST_CMD" ]; then
$TEST_CMD || { echo "Tests failed"; exit 1; }
fi
# Run linting
if [ -n "$LINT_CMD" ]; then
$LINT_CMD || { echo "Linting failed"; exit 1; }
fi
# Run production build
if [ -n "$BUILD_CMD" ]; then
$BUILD_CMD || { echo "Build failed"; exit 1; }
fi
# Verify all detected checks passed
echo "All quality checks passed - ready to complete"Warning: No test/lint/build commands found in project.
Add to CLAUDE.md or constitution/testing.md for automated quality gates.
Proceeding without verification - manual review recommended.finishing-a-development-branchgs stack submitgs branch creategs repo syncFeature Implementation Complete
**RUN_ID**: {run-id}
**Feature**: {feature-name}
**Workspace Mode**: multi-repo
**Workspace Root**: {path}
## Per-Repo Summary
| Repo | Tasks | Branches | Status |
|------|-------|----------|--------|
| backend | 4 | 4 | Complete |
| frontend | 3 | 3 | Complete |
| shared-lib | 1 | 1 | Complete |
## Branch Stacks (per-repo)
**backend:**
- {runId}-task-1-1-database
- {runId}-task-2-1-api
**frontend:**
- {runId}-task-2-2-hook
- {runId}-task-2-3-ui
## Next Steps
### Submit PRs (per-repo)
```bash
cd backend && gs stack submit
cd ../frontend && gs stack submit
**Single-repo final report:**
```markdown
Feature Implementation Complete
**RUN_ID**: {run-id}
**Feature**: {feature-name}
**Worktree**: .worktrees/{run-id}-main/
**Stack**: {count} task branches (all stacked on {run-id}-main)
## Execution Summary
**Phases Completed**: {count}
- Sequential: {count} phases
- Parallel: {count} phases
**Tasks Completed**: {count}
**Commits**: {count}
**Isolation**: All work completed in worktree. Main repo unchanged.
## Parallelization Results
{For each parallel phase:}
**Phase {id}**: {task-count} tasks in parallel
- Estimated sequential time: {hours}h
- Actual parallel time: {hours}h
- Time saved: {hours}h
**Total Time Saved**: {hours}h ({percent}%)
## Quality Checks
Quality checks are project-specific (detected from CLAUDE.md, constitution, or common patterns):
- Tests passing (if `TEST_CMD` detected)
- Linting clean (if `LINT_CMD` detected)
- Formatting applied (if `FORMAT_CMD` detected)
- Build successful (if `BUILD_CMD` detected)
If no commands detected, quality gates are skipped with warning to user.
- {total-commits} commits across {branch-count} task branches
## Next Steps
### Review Changes (from main repo)
```bash
# All these commands work from main repo root
gs log short # View all branches and commits in stack
gs log long # Detailed view with commit messages
git branch | grep "^ {run-id}-" # List all branches for this run
# To see changes in worktree:
cd .worktrees/{run-id}-main
git diff main..HEAD # See all changes in current stack
cd ../.. # Return to main repo# git-spice commands work from main repo
gs stack submit # Submits entire stack as PRs (per using-git-spice skill)cd .worktrees/{run-id}-main # Navigate to worktree
gs branch create # Creates new branch stacked on current
cd ../.. # Return to main repo when done# From main repo root:
git worktree remove .worktrees/{run-id}-main
# Optional: Delete the {run-id}-main branch
git branch -d {run-id}-main
## Error Handling
**Use the `troubleshooting-execute` skill:**
This skill provides comprehensive diagnostic and recovery strategies for execute command failures:
- Phase execution failures (sequential and parallel)
- Parallel agent failures with 4 recovery options
- Merge conflicts during stacking
- Worktree not found errors
- Parallel task worktree creation failures
The skill includes diagnostic commands, recovery strategies, and prevention guidelines.
Consult this skill when execution fails or produces unexpected results.
## Important Notes
- **Orchestrator delegates, never executes** - The orchestrator NEVER runs git commands directly. All git operations are delegated to subagents (setup, implementation, cleanup)
- **Subagents own their git operations** - Implementation subagents create branches and commit their own work using `gs branch create -m`
- **Skill-driven execution** - Uses using-git-spice, using-git-worktrees, and other superpowers skills
- **Automatic orchestration** - Reads plan strategies, executes accordingly
- **Git-spice stacking** - Sequential tasks stack linearly; parallel tasks branch from same base (per using-git-spice skill)
- **No feature branch** - The stack of task branches IS the feature; never create empty branch upfront
- **Worktree isolation** - Parallel tasks run in separate worktrees (per using-git-worktrees skill)
- **Critical: HEAD detachment** - Parallel task subagents MUST detach HEAD after creating branches to make them accessible in parent repo
- **Context management** - Each task runs in isolated subagent to avoid token bloat
- **Constitution adherence** - All agents follow project constitution (@docs/constitutions/current/)
- **Quality gates** - Tests and linting after every task, code review after every phase
- **Continuous commits** - Small, focused commits with [Task X.Y] markers throughout
Now execute the plan from: {plan-path}