Sync tasks.md with actual completion status (GitHub issue or reality check)
Fix tasks.md when it's out of sync with GitHub issues or actual work completed. Use this when progress percentages are wrong or after manual work without updating tasks.md.
/plugin marketplace add anton-abyzov/specweave/plugin install sw@specweavePurpose: Fix tasks.md when it's out of sync with reality (GitHub issue, git history, or actual files).
Use When:
/progress shows wrong completion %Detect Active Increment
Compare Sources
Show Diff
Sync Status Check:
tasks.md: 5/24 complete (21%)
GitHub #4: 24/24 complete (100%) ✓ TRUTH
Git commits: 24 task commits found
Mismatch detected! tasks.md is stale.
Offer Fix
Options:
1. Auto-sync from GitHub issue (recommended)
2. Auto-sync from git history
3. Manual review (show each task)
4. Cancel
Update tasks.md
# Auto-detect and sync
/sw:sync-tasks
# Sync specific increment
/sw:sync-tasks 0007
# Force sync from GitHub (skip git check)
/sw:sync-tasks --source=github
# Dry run (show what would change)
/sw:sync-tasks --dry-run
ACTIVE_INCREMENT=$(find .specweave/increments -name "tasks.md" -exec grep -l "Status: In Progress" {} \; | head -1)
if [[ -z "$ACTIVE_INCREMENT" ]]; then
echo "No active increment found"
exit 0
fi
INCREMENT_DIR=$(dirname "$ACTIVE_INCREMENT")
INCREMENT_ID=$(basename "$INCREMENT_DIR" | grep -oE "^[0-9]+")
# Check if GitHub sync is enabled
GITHUB_ISSUE=$(grep "github-issue:" "$INCREMENT_DIR/spec.md" | cut -d':' -f2 | tr -d ' ')
if [[ -n "$GITHUB_ISSUE" ]]; then
# Fetch issue body
ISSUE_BODY=$(gh issue view "$GITHUB_ISSUE" --json body --jq '.body')
# Count completed checkboxes
GH_TOTAL=$(echo "$ISSUE_BODY" | grep -c "^- \[")
GH_COMPLETE=$(echo "$ISSUE_BODY" | grep -c "^- \[x\]")
echo "GitHub Issue #$GITHUB_ISSUE: $GH_COMPLETE/$GH_TOTAL complete"
else
echo "No GitHub issue linked (skipping GitHub sync)"
fi
TASKS_TOTAL=$(grep -c "^#### T-" "$INCREMENT_DIR/tasks.md")
TASKS_COMPLETE=$(grep -A1 "^#### T-" "$INCREMENT_DIR/tasks.md" | grep -c "\*\*Status\*\*: \[x\] completed")
echo "tasks.md: $TASKS_COMPLETE/$TASKS_TOTAL complete"
if [[ "$GH_COMPLETE" -ne "$TASKS_COMPLETE" ]]; then
echo "⚠️ Mismatch detected!"
echo " GitHub: $GH_COMPLETE/$GH_TOTAL"
echo " tasks.md: $TASKS_COMPLETE/$TASKS_TOTAL"
echo ""
# Offer to sync
read -p "Sync tasks.md from GitHub issue? (y/n): " CONFIRM
if [[ "$CONFIRM" == "y" ]]; then
sync_from_github "$INCREMENT_DIR" "$GITHUB_ISSUE"
fi
else
echo "✓ tasks.md is in sync with GitHub issue"
fi
sync_from_github() {
local increment_dir="$1"
local github_issue="$2"
# Parse GitHub issue checklist
gh issue view "$github_issue" --json body --jq '.body' | while IFS= read -r line; do
if [[ "$line" =~ ^\-\ \[x\]\ (T-[0-9]{3}) ]]; then
# Task is complete in GitHub, mark in tasks.md
TASK_ID="${BASH_REMATCH[1]}"
mark_task_complete "$increment_dir" "$TASK_ID"
fi
done
# Recalculate progress
recalculate_progress "$increment_dir"
echo "✓ Synced tasks.md from GitHub issue #$github_issue"
}
mark_task_complete() {
local increment_dir="$1"
local task_id="$2"
# Find task and update status
sed -i '' "/^#### $task_id:/,/^\*\*Status\*\*:/ s/\*\*Status\*\*: \[ \] pending/\*\*Status\*\*: [x] completed/" "$increment_dir/tasks.md"
}
recalculate_progress() {
local increment_dir="$1"
local total=$(grep -c "^#### T-" "$increment_dir/tasks.md")
local completed=$(grep -A1 "^#### T-" "$increment_dir/tasks.md" | grep -c "\*\*Status\*\*: \[x\] completed")
local progress=$((completed * 100 / total))
# Update header
sed -i '' "s/\*\*Completed\*\*: [0-9]*/\*\*Completed\*\*: $completed/" "$increment_dir/tasks.md"
sed -i '' "s/\*\*Progress\*\*: [0-9]*%/\*\*Progress\*\*: $progress%/" "$increment_dir/tasks.md"
echo "✓ Progress updated: $completed/$total ($progress%)"
}
🔄 Syncing tasks.md status...
Active Increment: 0007-smart-increment-discipline
Status Comparison:
├─ tasks.md: 1/24 complete (4%)
├─ GitHub #4: 24/24 complete (100%)
└─ Mismatch: 23 tasks out of sync ⚠️
Sync Source:
✓ GitHub issue #4 (most reliable)
Updating tasks.md...
├─ T-001: [ ] → [x] ✓
├─ T-002: [ ] → [x] ✓
├─ T-003: [ ] → [x] ✓
...
└─ T-024: [ ] → [x] ✓
Progress recalculated:
├─ Completed: 1 → 24
├─ Progress: 4% → 100%
└─ Status: In Progress → Complete
✓ tasks.md synced successfully!
Next: Run /sw:progress to verify
# Check sync status before showing progress
/sw:sync-tasks --validate
# If out of sync, warn user
# Validate tasks.md is in sync
/sw:sync-tasks --validate
# Fail validation if mismatch detected
# Ensure tasks.md is current before closing
/sw:sync-tasks --auto
# Auto-sync if needed, then proceed
This command ensures /progress and /done always show accurate status!