1+ #! /bin/bash
2+
3+ # Research Paper Improvement Pipeline Loop
4+ # Hardcoded to use research_paper_improvement_gemini_pro_delayed.yaml
5+ # Chains iterations by feeding outputs back as inputs
6+
7+ PIPELINE_FILE=" research_paper_improvement_gemini_pro_delayed.yaml"
8+
9+ # Check if the pipeline file exists
10+ if [ ! -f " $PIPELINE_FILE " ]; then
11+ echo " Error: Pipeline file '$PIPELINE_FILE ' not found!"
12+ exit 1
13+ fi
14+
15+ echo " Starting research paper improvement pipeline loop"
16+ echo " Pipeline: $PIPELINE_FILE "
17+ echo " Press Ctrl+C to stop"
18+ echo " "
19+
20+ counter=1
21+ while true ; do
22+ timestamp=$( date -u +" %Y%m%d%H%M" )
23+ echo " === Research Paper Improvement Run #$counter $( date -u) ==="
24+
25+ # Create temporary YAML with unique timestamp
26+ cp " $PIPELINE_FILE " " ${PIPELINE_FILE} .tmp"
27+
28+ # Replace {{timestamp}} markers in output_to_file fields with current timestamp
29+ sed -i " s|{{timestamp}}|$timestamp |g" " ${PIPELINE_FILE} .tmp"
30+
31+ # Find the most recent output file to use as input for next iteration
32+ if [ $counter -gt 1 ]; then
33+ # Look for latest file in outputs directory (where files are actually saved)
34+ latest_file=$( ls -t ./outputs/202* _improved_chiral_narrative_synthesis.md 2> /dev/null | head -1)
35+ if [ -n " $latest_file " ]; then
36+ echo " 🔄 Using previous output as input: $latest_file "
37+ # Update the file path in the YAML to point to the latest output
38+ sed -i ' s|path: "\.\./research_papers/tex/ResearchProposal-ChiralNarrativeSynthesis_3\.tex"|path: "' " $latest_file " ' "|g' " ${PIPELINE_FILE} .tmp"
39+ sed -i ' s|path: \.\./research_papers/tex/ResearchProposal-ChiralNarrativeSynthesis_3\.tex|path: "' " $latest_file " ' "|g' " ${PIPELINE_FILE} .tmp"
40+ else
41+ echo " ⚠️ No previous output found, using original research proposal"
42+ fi
43+ else
44+ echo " 🚀 First run - using original research proposal"
45+ fi
46+
47+ # Run the pipeline
48+ echo " 🧠 Executing Gemini research improvement..."
49+ start_time=$( date +%s)
50+
51+ if timeout 3600 mix pipeline.run.live " ${PIPELINE_FILE} .tmp" ; then
52+ end_time=$( date +%s)
53+ duration=$(( end_time - start_time))
54+ echo " ✅ Pipeline completed successfully in ${duration} s"
55+
56+ # Check if new output file was created
57+ latest_after=$( ls -t ./outputs/202* _improved_chiral_narrative_synthesis.md 2> /dev/null | head -1)
58+ if [ " $latest_after " != " $latest_file " ]; then
59+ echo " 📄 New improved paper created: $latest_after "
60+
61+ # Show file size for progress tracking
62+ if [ -f " $latest_after " ]; then
63+ size=$( wc -l < " $latest_after " 2> /dev/null || echo " unknown" )
64+ echo " 📊 Paper length: $size lines"
65+ fi
66+ else
67+ echo " ⚠️ WARNING: No new output file detected!"
68+ fi
69+ else
70+ end_time=$( date +%s)
71+ duration=$(( end_time - start_time))
72+ echo " ❌ Pipeline failed or timed out after ${duration} s"
73+
74+ # Show current outputs for debugging
75+ echo " 📁 Current outputs:"
76+ ls -lt ./outputs/202* _improved_chiral_narrative_synthesis.md 2> /dev/null | head -3
77+ fi
78+
79+ # Clean up temp file
80+ rm " ${PIPELINE_FILE} .tmp"
81+
82+ echo " === Completed Research Paper Improvement Run #$counter , waiting 5 seconds... ==="
83+ sleep 5
84+ (( counter++ ))
85+ done
0 commit comments