-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
673 lines (566 loc) · 21.1 KB
/
entrypoint.sh
File metadata and controls
673 lines (566 loc) · 21.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
#!/bin/bash
set -e
# ===========================================
# ORCHESTRATION MODE
# ===========================================
# If ORCHESTRATE_MODE=smart, run the full orchestration loop
# Otherwise, run a single role (original behavior)
ORCHESTRATE_MODE="${ORCHESTRATE_MODE:-}"
AGENT_ROLE="${AGENT_ROLE:-developer}"
# Orchestration settings
MAX_CYCLES="${MAX_CYCLES:-20}"
MAX_DEV_CYCLES="${MAX_DEV_CYCLES:-5}"
REVIEW_EVERY="${REVIEW_EVERY:-3}"
# Tracking for orchestration
TOTAL_CYCLES=0
DEV_CYCLES=0
DEV_CYCLES_SINCE_REVIEW=0
REVIEW_CYCLES=0
DEPLOY_ATTEMPTS=0
MARKETER_RAN=0
# ===========================================
# LOGGING SETUP
# ===========================================
SESSION_TIMESTAMP=$(date -u +%Y%m%d-%H%M%S)
SESSION_ID="${SESSION_TIMESTAMP}-${ORCHESTRATE_MODE:-$AGENT_ROLE}"
LOG_DIR="/project/.knowledge/logs"
LOG_FILE="${LOG_DIR}/${SESSION_ID}.log"
SESSION_START=$(date -u +%Y-%m-%dT%H:%M:%SZ)
echo "=========================================="
echo " Comet Apps Agent Framework"
if [ "$ORCHESTRATE_MODE" = "smart" ]; then
echo " Mode: SMART ORCHESTRATION"
echo " Max Cycles: $MAX_CYCLES"
else
echo " Role: ${AGENT_ROLE^^}"
fi
echo " Session: ${SESSION_ID}"
echo "=========================================="
# Check for required environment variable
if [ -z "$ANTHROPIC_API_KEY" ]; then
echo "ERROR: ANTHROPIC_API_KEY environment variable is required"
exit 1
fi
# Export GH_TOKEN for gh CLI
export GH_TOKEN="$GITHUB_TOKEN"
# Configure git to use the token for push
git config --global credential.helper store
git config --global url."https://${GITHUB_TOKEN}@github.com/".insteadOf "https://github.com/"
# Configure Vercel CLI (if token provided)
if [ -n "$VERCEL_TOKEN" ]; then
echo "🔧 Configuring Vercel CLI authentication..."
# Check if token starts/ends with quotes (common .env mistake)
if [[ "$VERCEL_TOKEN" == \"*\" ]] || [[ "$VERCEL_TOKEN" == \'*\' ]]; then
echo " ⚠️ Stripping quotes from token..."
VERCEL_TOKEN="${VERCEL_TOKEN%\"}"
VERCEL_TOKEN="${VERCEL_TOKEN#\"}"
VERCEL_TOKEN="${VERCEL_TOKEN%\'}"
VERCEL_TOKEN="${VERCEL_TOKEN#\'}"
fi
# Remove any embedded quote characters
if [[ "$VERCEL_TOKEN" == *'"'* ]] || [[ "$VERCEL_TOKEN" == *"'"* ]]; then
VERCEL_TOKEN=$(echo "$VERCEL_TOKEN" | tr -d '"'"'")
fi
export VERCEL_TOKEN="$VERCEL_TOKEN"
# Find the real vercel binary
VERCEL_REAL=$(which vercel 2>/dev/null || echo "")
if [ -n "$VERCEL_REAL" ]; then
# Create wrapper in user's home bin directory
mkdir -p ~/bin
cat > ~/bin/vercel << WRAPPER
#!/bin/bash
exec $VERCEL_REAL --token "\$VERCEL_TOKEN" "\$@"
WRAPPER
chmod +x ~/bin/vercel
# Add ~/bin to PATH at the front
export PATH="$HOME/bin:$PATH"
# Verify authentication works
echo " Testing authentication..."
if ~/bin/vercel whoami > /dev/null 2>&1; then
echo " ✓ Vercel authenticated as: $(~/bin/vercel whoami)"
else
echo " ❌ Vercel authentication FAILED"
echo " Token length: ${#VERCEL_TOKEN}, starts with: ${VERCEL_TOKEN:0:3}..."
fi
else
echo " ⚠ Vercel CLI not found, skipping wrapper setup"
fi
fi
# ===========================================
# Branch Configuration
# ===========================================
PROJECT_BRANCH="${PROJECT_BRANCH:-release/dev}"
STAGING_BRANCH="${STAGING_BRANCH:-release/stage}"
PRODUCTION_BRANCH="${PRODUCTION_BRANCH:-release/prod}"
# ===========================================
# STEP 1: Setup Project Repo
# ===========================================
echo ""
echo "📦 Setting up project repository..."
if [ -n "$PROJECT_NAME" ]; then
[[ "$PROJECT_NAME" != agent-* ]] && PROJECT_NAME="agent-${PROJECT_NAME}"
if [ -z "$GITHUB_TOKEN" ]; then
echo "ERROR: GITHUB_TOKEN required"
exit 1
fi
GITHUB_USER=$(gh api user --jq .login)
if gh repo view "$PROJECT_NAME" > /dev/null 2>&1; then
echo " Repository exists: $PROJECT_NAME"
else
echo " Creating: $PROJECT_NAME"
gh repo create "$PROJECT_NAME" --private --description "Auto-created by Comet Agent" --clone=false
fi
if [ -z "$(ls -A /project 2>/dev/null)" ]; then
echo " Cloning..."
gh repo clone "$PROJECT_NAME" /project 2>/dev/null || {
cd /project && git init
git remote add origin "https://${GITHUB_TOKEN}@github.com/${GITHUB_USER}/${PROJECT_NAME}.git"
}
fi
cd /project
echo " 📍 https://github.com/$GITHUB_USER/$PROJECT_NAME"
else
echo " Using local directory"
[ ! -d "/project/.git" ] && cd /project && git init
cd /project
fi
echo " ✓ Repo ready"
# ===========================================
# STEP 1b: Clone Boilerplate (if project is empty)
# ===========================================
echo ""
echo "📦 Checking for boilerplate..."
cd /project
if [ ! -f "/project/package.json" ]; then
if [ -n "$BOILERPLATE_REPO" ]; then
echo " Project is empty, cloning boilerplate: $BOILERPLATE_REPO"
TEMP_BOILERPLATE="/tmp/boilerplate"
rm -rf "$TEMP_BOILERPLATE"
gh repo clone "$BOILERPLATE_REPO" "$TEMP_BOILERPLATE" 2>/dev/null || {
echo "ERROR: Could not clone boilerplate: $BOILERPLATE_REPO"
exit 1
}
rm -rf "$TEMP_BOILERPLATE/.git"
cp -r "$TEMP_BOILERPLATE"/* /project/ 2>/dev/null || true
cp -r "$TEMP_BOILERPLATE"/.[!.]* /project/ 2>/dev/null || true
rm -rf "$TEMP_BOILERPLATE"
git add -A
git commit -m "[agent] Initialize from SaaS Boilerplate" || true
echo " ✓ Boilerplate cloned and committed"
else
echo " ⚠ Project is empty and BOILERPLATE_REPO not set"
fi
else
echo " ✓ Project already has code"
fi
# ===========================================
# STEP 1c: Setup Branch Structure
# ===========================================
echo ""
echo "🌿 Setting up branch structure..."
git fetch origin --quiet 2>/dev/null || true
create_branch_if_missing() {
local branch_name=$1
local base_branch=$2
if git ls-remote --heads origin "$branch_name" | grep -q "$branch_name"; then
return 0
fi
if git show-ref --verify --quiet "refs/heads/$branch_name"; then
return 0
fi
echo " Creating $branch_name..."
if [ -n "$base_branch" ] && git show-ref --verify --quiet "refs/heads/$base_branch"; then
git branch "$branch_name" "$base_branch"
elif [ -n "$base_branch" ] && git ls-remote --heads origin "$base_branch" | grep -q "$base_branch"; then
git fetch origin "$base_branch:$branch_name"
elif git show-ref --verify --quiet "refs/heads/main"; then
git branch "$branch_name" main
elif git ls-remote --heads origin main | grep -q main; then
git fetch origin main:main 2>/dev/null || true
git branch "$branch_name" main 2>/dev/null || git branch "$branch_name"
else
git checkout -b "$branch_name" 2>/dev/null || git checkout "$branch_name"
return 0
fi
git push -u origin "$branch_name" 2>/dev/null || true
}
create_branch_if_missing "$PRODUCTION_BRANCH" ""
create_branch_if_missing "$STAGING_BRANCH" "$PRODUCTION_BRANCH"
create_branch_if_missing "$PROJECT_BRANCH" "$STAGING_BRANCH"
git checkout "$PROJECT_BRANCH" 2>/dev/null || git checkout -b "$PROJECT_BRANCH"
git pull origin "$PROJECT_BRANCH" 2>/dev/null || true
echo " ✓ Branch structure ready"
# ===========================================
# STEP 2: Initialize Knowledge
# ===========================================
echo ""
echo "🧠 Setting up knowledge store..."
cd /project
KNOWLEDGE_DIR="/project/.knowledge"
if [ -d "$KNOWLEDGE_DIR" ] && [ -f "$KNOWLEDGE_DIR/context/current.json" ]; then
echo " Knowledge store exists"
else
echo " Initializing from template..."
if [ -n "$KNOWLEDGE_TEMPLATE" ]; then
TEMP_TEMPLATE="/tmp/knowledge-template"
rm -rf "$TEMP_TEMPLATE"
gh repo clone "$KNOWLEDGE_TEMPLATE" "$TEMP_TEMPLATE" 2>/dev/null || {
echo "ERROR: Could not clone template: $KNOWLEDGE_TEMPLATE"
exit 1
}
mkdir -p "$KNOWLEDGE_DIR"
cp -r "$TEMP_TEMPLATE"/* "$KNOWLEDGE_DIR/" 2>/dev/null || true
cp -r "$TEMP_TEMPLATE"/.[!.]* "$KNOWLEDGE_DIR/" 2>/dev/null || true
rm -rf "$KNOWLEDGE_DIR/.git"
echo " ✓ Template copied to .knowledge/"
else
mkdir -p "$KNOWLEDGE_DIR/context" "$KNOWLEDGE_DIR/memory" "$KNOWLEDGE_DIR/decisions" "$KNOWLEDGE_DIR/work" "$KNOWLEDGE_DIR/logs"
cat > "$KNOWLEDGE_DIR/context/current.json" << 'EOF'
{"phase": "new", "current_task": null, "next_actions": [], "session_notes": [], "updated_at": null}
EOF
cat > "$KNOWLEDGE_DIR/context/project.json" << 'EOF'
{"name": "", "description": "", "status": "new", "tech_stack": {}, "features": []}
EOF
cat > "$KNOWLEDGE_DIR/context/objectives.json" << 'EOF'
{"mission": "", "current_objectives": [], "success_metrics": []}
EOF
echo " ✓ Minimal structure created"
fi
git add .knowledge/
git commit -m "[agent] Initialize knowledge store" || true
fi
# ===========================================
# STEP 2b: Apply BUILD_TASK override
# ===========================================
if [ -n "$BUILD_TASK" ]; then
echo " 📝 Applying BUILD_TASK..."
CURRENT_FILE="$KNOWLEDGE_DIR/context/current.json"
cat > "$CURRENT_FILE" << EOF
{
"phase": "new",
"current_task": "$BUILD_TASK",
"next_actions": [],
"session_notes": [],
"updated_at": "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
}
EOF
OBJECTIVES_FILE="$KNOWLEDGE_DIR/context/objectives.json"
cat > "$OBJECTIVES_FILE" << EOF
{
"mission": "$BUILD_TASK",
"current_objectives": ["Complete the build task"],
"success_metrics": ["Task completed successfully", "Code works as expected"],
"updated_at": "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
}
EOF
git add .knowledge/
git commit -m "[agent] Set build task from environment" || true
echo " ✓ Task set: ${BUILD_TASK:0:50}..."
fi
echo " ✓ Knowledge ready"
# ===========================================
# Initialize Session Log
# ===========================================
mkdir -p "$LOG_DIR"
cat > "$LOG_FILE" << EOF
================================================================================
COMET AGENT SESSION LOG
================================================================================
Session ID: ${SESSION_ID}
Mode: ${ORCHESTRATE_MODE:-single-role}
Role: ${AGENT_ROLE}
Project: ${PROJECT_NAME}
Branch: ${PROJECT_BRANCH}
Started: ${SESSION_START}
================================================================================
EOF
# ===========================================
# HELPER FUNCTIONS
# ===========================================
# Read current phase from knowledge store
get_current_phase() {
local current_file="/project/.knowledge/context/current.json"
if [ -f "$current_file" ]; then
grep -o '"phase"[[:space:]]*:[[:space:]]*"[^"]*"' "$current_file" 2>/dev/null | head -1 | cut -d'"' -f4
else
echo "new"
fi
}
# Get backlog count
get_backlog_count() {
local backlog_file="/project/.knowledge/work/backlog.json"
if [ -f "$backlog_file" ]; then
grep -c '"id"' "$backlog_file" 2>/dev/null || echo "0"
else
echo "0"
fi
}
# Get in-progress count
get_in_progress_count() {
local progress_file="/project/.knowledge/work/in-progress.json"
if [ -f "$progress_file" ]; then
grep -c '"id"' "$progress_file" 2>/dev/null || echo "0"
else
echo "0"
fi
}
# Decide next role based on phase
decide_next_role() {
local phase=$(get_current_phase)
local backlog=$(get_backlog_count)
local in_progress=$(get_in_progress_count)
case "$phase" in
"new"|"")
echo "initiator"
;;
"initialized")
echo "planner"
;;
"planned"|"building")
if [ "$backlog" -eq 0 ] && [ "$in_progress" -eq 0 ] && [ "$DEV_CYCLES" -gt 0 ]; then
echo "reviewer"
elif [ "$DEV_CYCLES_SINCE_REVIEW" -ge "$REVIEW_EVERY" ]; then
echo "reviewer"
elif [ "$DEV_CYCLES" -ge "$MAX_DEV_CYCLES" ]; then
echo "reviewer"
else
echo "developer"
fi
;;
"reviewed"|"needs_fixes")
echo "developer"
;;
"ready_for_marketing")
echo "marketer"
;;
"ready_for_staging"|"ready_for_deployment")
# Run marketer before deployer if not already run
if [ "$MARKETER_RAN" -eq 0 ]; then
echo "marketer"
else
echo "deployer"
fi
;;
"deployment_failed")
echo "developer"
;;
"staged"|"deployed")
echo "done"
;;
"blocked"|"stuck")
echo "abort"
;;
"complete"|"done")
echo "done"
;;
*)
echo "developer"
;;
esac
}
# Load role prompt and run Claude
run_role() {
local role=$1
local role_upper=$(echo "$role" | tr '[:lower:]' '[:upper:]')
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🎭 Running: ${role_upper}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Validate deployer env vars
if [ "$role" = "deployer" ]; then
MISSING_VARS=""
[ -z "$VERCEL_TOKEN" ] && MISSING_VARS="$MISSING_VARS VERCEL_TOKEN"
if [ -n "$MISSING_VARS" ]; then
echo " ❌ FATAL: Missing required variables:$MISSING_VARS"
return 1
fi
fi
# Load context
local PROJECT_CONTEXT=""
[ -f "$KNOWLEDGE_DIR/context/project.json" ] && PROJECT_CONTEXT=$(cat "$KNOWLEDGE_DIR/context/project.json")
local OBJECTIVES_CONTEXT=""
[ -f "$KNOWLEDGE_DIR/context/objectives.json" ] && OBJECTIVES_CONTEXT=$(cat "$KNOWLEDGE_DIR/context/objectives.json")
local CURRENT_CONTEXT=""
[ -f "$KNOWLEDGE_DIR/context/current.json" ] && CURRENT_CONTEXT=$(cat "$KNOWLEDGE_DIR/context/current.json")
# Load role instructions
local ROLE_FILE="/agent/roles/${role}.txt"
local ROLE_INSTRUCTIONS=""
if [ -f "$ROLE_FILE" ]; then
ROLE_INSTRUCTIONS=$(cat "$ROLE_FILE")
else
ROLE_INSTRUCTIONS="You are an autonomous AI agent. Read your context and do appropriate work."
fi
# Build prompt
local PROMPT="$ROLE_INSTRUCTIONS
---
## Your Project Repository
All work happens in /project:
- **Code**: /project/src, /project/package.json, etc.
- **Knowledge**: /project/.knowledge/ (your memory)
## Git Branch Workflow
**IMPORTANT: You work on the \`$PROJECT_BRANCH\` branch ONLY.**
Branch Structure:
- **$PROJECT_BRANCH** (YOU ARE HERE) - Development work happens here
- **$STAGING_BRANCH** - Pre-production staging (merge when ready)
- **$PRODUCTION_BRANCH** - Production (NEVER push directly - human-controlled)
### When Committing:
\`\`\`bash
git add -A
git commit -m \"[agent:$role] description\"
git push origin $PROJECT_BRANCH
\`\`\`
## Current Context
### Project
\`\`\`json
$PROJECT_CONTEXT
\`\`\`
### Objectives
\`\`\`json
$OBJECTIVES_CONTEXT
\`\`\`
### Current State
\`\`\`json
$CURRENT_CONTEXT
\`\`\`
---
Begin working now."
# Run Claude
echo "🤖 Starting Claude Code..."
echo " Role: $role"
echo " Branch: $PROJECT_BRANCH"
echo ""
{
echo ""
echo "━━━ Role: $role ━━━"
echo "Started: $(date -u +%Y-%m-%dT%H:%M:%SZ)"
echo ""
} >> "$LOG_FILE"
if [ "$LOG_FORMAT" = "json" ]; then
claude -p "$PROMPT" \
--dangerously-skip-permissions \
--output-format stream-json \
--verbose 2>&1 | tee -a "$LOG_FILE"
else
claude -p "$PROMPT" \
--dangerously-skip-permissions \
--output-format stream-json \
--verbose 2>&1 | /agent/format-logs.sh | tee -a "$LOG_FILE"
fi
echo ""
echo "✅ ${role_upper} completed"
# Commit any changes
cd /project
git add -A
git commit -m "[agent:${role}] Session work" 2>/dev/null || true
git push origin "$PROJECT_BRANCH" 2>/dev/null || true
return 0
}
# ===========================================
# MAIN EXECUTION
# ===========================================
if [ "$ORCHESTRATE_MODE" = "smart" ]; then
# ===========================================
# SMART ORCHESTRATION MODE
# ===========================================
echo ""
echo "╔══════════════════════════════════════════════════════════════╗"
echo "║ 🎯 SMART ORCHESTRATION MODE ║"
echo "╚══════════════════════════════════════════════════════════════╝"
echo ""
echo " Max cycles: $MAX_CYCLES"
echo " Max dev cycles: $MAX_DEV_CYCLES"
echo " Review every: $REVIEW_EVERY dev cycles"
echo ""
ORCHESTRATION_START=$(date +%s)
while [ "$TOTAL_CYCLES" -lt "$MAX_CYCLES" ]; do
TOTAL_CYCLES=$((TOTAL_CYCLES + 1))
echo ""
echo "🎯 [ORCHESTRATOR] Cycle $TOTAL_CYCLES of $MAX_CYCLES"
# Decide next role
NEXT_ROLE=$(decide_next_role)
PHASE=$(get_current_phase)
echo " Phase: $PHASE → Role: $NEXT_ROLE"
case "$NEXT_ROLE" in
"done")
echo ""
echo "✅ Orchestration complete - project finished!"
break
;;
"abort")
echo ""
echo "❌ Orchestration aborted - project blocked"
exit 1
;;
"initiator"|"planner")
run_role "$NEXT_ROLE"
;;
"developer")
run_role "developer"
DEV_CYCLES=$((DEV_CYCLES + 1))
DEV_CYCLES_SINCE_REVIEW=$((DEV_CYCLES_SINCE_REVIEW + 1))
;;
"reviewer")
run_role "reviewer"
DEV_CYCLES_SINCE_REVIEW=0
REVIEW_CYCLES=$((REVIEW_CYCLES + 1))
;;
"marketer")
run_role "marketer"
MARKETER_RAN=1
;;
"deployer")
run_role "deployer"
DEPLOY_ATTEMPTS=$((DEPLOY_ATTEMPTS + 1))
;;
*)
echo " ⚠ Unknown role: $NEXT_ROLE, defaulting to developer"
run_role "developer"
DEV_CYCLES=$((DEV_CYCLES + 1))
;;
esac
# Brief pause between cycles
sleep 2
done
# Summary
ORCHESTRATION_END=$(date +%s)
DURATION=$((ORCHESTRATION_END - ORCHESTRATION_START))
MINUTES=$((DURATION / 60))
SECONDS=$((DURATION % 60))
echo ""
echo "╔══════════════════════════════════════════════════════════════╗"
echo "║ 🎉 ORCHESTRATION COMPLETE ║"
echo "╚══════════════════════════════════════════════════════════════╝"
echo ""
echo " Duration: ${MINUTES}m ${SECONDS}s"
echo " Total cycles: $TOTAL_CYCLES"
echo " Dev cycles: $DEV_CYCLES"
echo " Reviews: $REVIEW_CYCLES"
echo " Marketing: $MARKETER_RAN"
echo " Deploy attempts: $DEPLOY_ATTEMPTS"
echo " Final phase: $(get_current_phase)"
echo ""
echo " Repository: https://github.com/$GITHUB_USER/$PROJECT_NAME"
echo ""
else
# ===========================================
# SINGLE ROLE MODE (Original Behavior)
# ===========================================
run_role "$AGENT_ROLE"
fi
# ===========================================
# Commit Session Log
# ===========================================
SESSION_END=$(date -u +%Y-%m-%dT%H:%M:%SZ)
{
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Session completed: $SESSION_END"
echo "=========================================="
} >> "$LOG_FILE"
echo ""
echo "📝 Saving session log..."
cd /project
git add ".knowledge/logs/${SESSION_ID}.log" 2>/dev/null || true
git commit -m "[agent] Session log: ${SESSION_ID}" 2>/dev/null || true
git push origin "$PROJECT_BRANCH" 2>/dev/null || true
echo " ✓ Log committed"