@@ -94,20 +94,27 @@ if [[ -f "${REPOPATH}/.iterate/ISSUES_TODAY.md" ]] && grep -q "Issue #" "${REPOP
9494 HAS_ISSUES=true
9595fi
9696
97- # ── Clean stale plan ──
98- rm -f " $PLAN_FILE "
97+ PR_STATE_FILE=" ${REPOPATH} /.iterate/pr_state.json"
9998
100- # ── Phase 1: Planning ──
101- log " Phase 1: Planning..."
102- if ! ./iterate --phase plan --gh-owner GrayCodeAI --gh-repo iterate 2>> " $LOG_FILE " ; then
103- log " WARNING: plan phase exited with error — checking for fallback"
104- fi
99+ # ── Resume detection: skip completed phases on re-run ──
100+ # If pr_state.json exists, a PR was already created — skip phases 1-3.
101+ if [[ -f " $PR_STATE_FILE " ]]; then
102+ log " Detected existing pr_state.json — resuming from Phase 4 (Review)"
103+ else
104+ # ── Clean stale plan ──
105+ rm -f " $PLAN_FILE "
106+
107+ # ── Phase 1: Planning ──
108+ log " Phase 1: Planning..."
109+ if ! ./iterate --phase plan --gh-owner GrayCodeAI --gh-repo iterate 2>> " $LOG_FILE " ; then
110+ log " WARNING: plan phase exited with error — checking for fallback"
111+ fi
105112
106- # Fallback plan if agent didn't create one
107- if [[ ! -f " $PLAN_FILE " ]]; then
108- log " Agent did not create SESSION_PLAN.md — writing fallback"
109- if [[ " $HAS_ISSUES " == " true" ]]; then
110- cat > " $PLAN_FILE " << 'EOF '
113+ # Fallback plan if agent didn't create one
114+ if [[ ! -f " $PLAN_FILE " ]]; then
115+ log " Agent did not create SESSION_PLAN.md — writing fallback"
116+ if [[ " $HAS_ISSUES " == " true" ]]; then
117+ cat > " $PLAN_FILE " << 'EOF '
111118## Session Plan
112119
113120Session Title: Address community issues
@@ -120,8 +127,8 @@ Issue: multiple
120127### Issue Responses
121128- TBD
122129EOF
123- else
124- cat > " $PLAN_FILE " << 'EOF '
130+ else
131+ cat > " $PLAN_FILE " << 'EOF '
125132## Session Plan
126133
127134Session Title: General self-improvement
@@ -133,42 +140,43 @@ Issue: none
133140
134141### Issue Responses
135142EOF
143+ fi
136144 fi
137- fi
138-
139- # ── Phase 2: Implementation ──
140- log " Phase 2: Implementation..."
141- sleep 5 # Brief pause between phases
142- if ! ./iterate --phase implement --gh-owner GrayCodeAI --gh-repo iterate 2>> " $LOG_FILE " ; then
143- log " WARNING: implement phase exited with error — continuing"
144- fi
145-
146- # Update DAY_COUNT before creating PR
147- echo " $DAY " > " ${REPOPATH} /DAY_COUNT"
148- git add DAY_COUNT 2> /dev/null || true
149- git diff --cached --quiet || git commit -m " chore: update DAY_COUNT to day $DAY " 2> /dev/null || true
150-
151- # ── Track coverage and generate stats before PR ──
152- log " Tracking test coverage..."
153- python3 scripts/build/track_coverage.py . 2> /dev/null || true
154- git add memory/coverage_history.jsonl 2> /dev/null || true
155- git diff --cached --quiet || git commit -m " chore: update coverage history" 2> /dev/null || true
156-
157- log " Generating stats..."
158- python3 scripts/build/generate_stats.py . 2> /dev/null || true
159- git add docs/stats.json memory/weekly_summary.md 2> /dev/null || true
160- git diff --cached --quiet || git commit -m " chore: update stats" 2> /dev/null || true
161145
162- log " Generating dashboard..."
163- python3 scripts/build/generate_dashboard.py . 2> /dev/null || true
164- git add docs/dashboard.html 2> /dev/null || true
165- git diff --cached --quiet || git commit -m " chore: update metrics dashboard" 2> /dev/null || true
146+ # ── Phase 2: Implementation ──
147+ log " Phase 2: Implementation..."
148+ sleep 5 # Brief pause between phases
149+ if ! ./iterate --phase implement --gh-owner GrayCodeAI --gh-repo iterate 2>> " $LOG_FILE " ; then
150+ log " WARNING: implement phase exited with error — continuing"
151+ fi
166152
167- # ── Phase 3: Pull Request ──
168- log " Phase 3: Pull Request..."
169- sleep 5
170- if ! ./iterate --phase pr --gh-owner GrayCodeAI --gh-repo iterate 2>> " $LOG_FILE " ; then
171- log " WARNING: PR phase exited with error — continuing"
153+ # Update DAY_COUNT before creating PR
154+ echo " $DAY " > " ${REPOPATH} /DAY_COUNT"
155+ git add DAY_COUNT 2> /dev/null || true
156+ git diff --cached --quiet || git commit -m " chore: update DAY_COUNT to day $DAY " 2> /dev/null || true
157+
158+ # ── Track coverage and generate stats before PR ──
159+ log " Tracking test coverage..."
160+ python3 scripts/build/track_coverage.py . 2> /dev/null || true
161+ git add memory/coverage_history.jsonl 2> /dev/null || true
162+ git diff --cached --quiet || git commit -m " chore: update coverage history" 2> /dev/null || true
163+
164+ log " Generating stats..."
165+ python3 scripts/build/generate_stats.py . 2> /dev/null || true
166+ git add docs/stats.json memory/weekly_summary.md 2> /dev/null || true
167+ git diff --cached --quiet || git commit -m " chore: update stats" 2> /dev/null || true
168+
169+ log " Generating dashboard..."
170+ python3 scripts/build/generate_dashboard.py . 2> /dev/null || true
171+ git add docs/dashboard.html 2> /dev/null || true
172+ git diff --cached --quiet || git commit -m " chore: update metrics dashboard" 2> /dev/null || true
173+
174+ # ── Phase 3: Pull Request ──
175+ log " Phase 3: Pull Request..."
176+ sleep 5
177+ if ! ./iterate --phase pr --gh-owner GrayCodeAI --gh-repo iterate 2>> " $LOG_FILE " ; then
178+ log " WARNING: PR phase exited with error — continuing"
179+ fi
172180fi
173181
174182BRANCH=" evolution/day-${DAY} "
@@ -231,10 +239,37 @@ gh api repos/"$GITHUB_REPO"/branches --jq '.[].name' 2>/dev/null | grep "^evolut
231239 fi
232240done
233241
242+ <<< <<< < Updated upstream
234243# ── Cost estimation ──
235244SESSION_DURATION=$SECONDS
236245log " Session duration: ${SESSION_DURATION} s"
237246log " Estimated cost: ~\$ 0.00 (depends on API usage)"
247+ =======
248+ # ── Generate stats ──
249+ log " Generating stats..."
250+ python3 scripts/build/generate_stats.py . 2> /dev/null || true
251+ git add docs/stats.json memory/weekly_summary.md 2> /dev/null || true
252+
253+ # ── Final commit and push ──
254+ log " Pushing changes..."
255+
256+ # Re-calculate day after pull (pull may overwrite DAY_COUNT)
257+ DAY=$(( ($(date - u +% s) - $(date - d "$BIRTH_DATE " +% s 2 >/ dev/ null || date - j - f "% Y-% m-% d" "$BIRTH_DATE " +% s)) / 86400 ))
258+ echo " $DAY " > " ${REPOPATH} /DAY_COUNT"
259+
260+ if [[ -n $( git status -s) ]]; then
261+ git add -A
262+ git commit -m " iterate: Day $DAY evolution session" 2> /dev/null || true
263+ fi
264+ git pull --rebase origin main 2> /dev/null || true
265+
266+ # Always ensure DAY_COUNT is correct after pull
267+ echo " $DAY " > " ${REPOPATH} /DAY_COUNT"
268+ git add DAY_COUNT 2> /dev/null || true
269+ git commit --amend --no-edit 2> /dev/null || git commit -m " iterate: Day $DAY evolution session" 2> /dev/null || true
270+
271+ git push origin main 2> /dev/null || log " Push failed"
272+ >>>>>>> Stashed changes
238273
239274# ── Summary ──
240275log " === evolution cycle completed ==="
0 commit comments