@@ -176,13 +176,75 @@ log "Generating stats..."
176176python3 scripts/build/generate_stats.py . 2> /dev/null || true
177177git add docs/stats.json memory/weekly_summary.md 2> /dev/null || true
178178
179- # ── Final commit and push ──
180- log " Pushing changes..."
179+ # ── Final commit and PR ──
180+ log " Creating pull request..."
181+
182+ BRANCH=" evolution/day-${DAY} "
183+
184+ # Re-calculate day after pull (pull may overwrite DAY_COUNT)
185+ DAY=$(( ($(date - u +% s) - $(date - d "$BIRTH_DATE " +% s 2 >/ dev/ null || date - j - f "% Y-% m-% d" "$BIRTH_DATE " +% s)) / 86400 ))
186+ echo " $DAY " > " ${REPOPATH} /DAY_COUNT"
187+
188+ # Stage and commit all changes
181189if [[ -n $( git status -s) ]]; then
182190 git add -A
183191 git commit -m " iterate: Day $DAY evolution session" 2> /dev/null || true
184192fi
193+
194+ # Pull latest main
185195git pull --rebase origin main 2> /dev/null || true
186- git push origin main 2> /dev/null || log " Push failed"
196+
197+ # Ensure DAY_COUNT is correct after pull
198+ echo " $DAY " > " ${REPOPATH} /DAY_COUNT"
199+ git add DAY_COUNT 2> /dev/null || true
200+ git diff --cached --quiet || git commit --amend --no-edit 2> /dev/null || true
201+
202+ # Check if there are changes to push
203+ if [[ -z $( git diff origin/main HEAD --stat 2> /dev/null) ]]; then
204+ log " No changes to push — skipping PR"
205+ git checkout main 2> /dev/null || true
206+ log " === evolution cycle completed ==="
207+ exit 0
208+ fi
209+
210+ # Create feature branch and push
211+ git checkout -b " $BRANCH " 2> /dev/null || git checkout " $BRANCH "
212+ git push -u origin " $BRANCH " --force-with-lease 2> /dev/null || {
213+ log " Push failed, trying without lease"
214+ git push -u origin " $BRANCH " 2> /dev/null || log " Push failed"
215+ }
216+
217+ # Create PR
218+ PR_TITLE=" iterate: Day $DAY evolution session"
219+ PR_BODY=" ## Evolution Session — Day $DAY
220+
221+ Automated evolution session by iterate-evolve[bot].
222+
223+ ### What changed
224+ - Ran plan → implement → communicate pipeline
225+ - All changes verified with go build + go test
226+
227+ ### Journal
228+ See docs/JOURNAL.md for session details.
229+
230+ ---
231+ *Auto-generated by iterate*"
232+
233+ gh pr create \
234+ --repo " $GITHUB_REPO " \
235+ --title " $PR_TITLE " \
236+ --body " $PR_BODY " \
237+ --base main \
238+ --head " $BRANCH " 2> /dev/null || log " PR creation failed"
239+
240+ # Auto-merge if PR was created
241+ PR_NUMBER=$( gh pr list --repo " $GITHUB_REPO " --head " $BRANCH " --json number --jq ' .[0].number' 2> /dev/null)
242+ if [[ -n " $PR_NUMBER " && " $PR_NUMBER " != " null" ]]; then
243+ log " Enabling auto-merge for PR #$PR_NUMBER "
244+ gh pr merge " $PR_NUMBER " --repo " $GITHUB_REPO " --auto --squash 2> /dev/null || log " Auto-merge setup failed (may need branch protection)"
245+ fi
246+
247+ # Switch back to main
248+ git checkout main 2> /dev/null || true
187249
188250log " === evolution cycle completed ==="
0 commit comments