claude-evolve 1.7.14 → 1.7.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -339,38 +339,39 @@ validate_direct_csv_modification() {
339
339
  local expected_count="$2"
340
340
  local idea_type="$3"
341
341
  local ai_model="${4:-}" # AI model that generated the ideas
342
-
342
+ local expected_ids="${5:-}" # Optional: comma or space separated list of expected IDs
343
+
343
344
  # Check if the file was actually modified
344
345
  if [[ ! -f "$temp_csv" ]]; then
345
346
  echo "[ERROR] CSV file was not found after AI modification" >&2
346
347
  return 1
347
348
  fi
348
-
349
+
349
350
  # Get the count before modification from the temp CSV (which was copied from original before AI ran)
350
351
  # We need to track this before the AI runs by reading from the beginning state
351
352
  # First, get a fresh count from the current main CSV (which reflects any previous operations in this session)
352
353
  local current_original_count
353
354
  current_original_count=$(grep -v '^[[:space:]]*$' "$FULL_CSV_PATH" | tail -n +2 | wc -l)
354
-
355
+
355
356
  # Count data rows in the modified temp CSV
356
357
  local new_count
357
358
  new_count=$(grep -v '^[[:space:]]*$' "$temp_csv" | tail -n +2 | wc -l)
358
-
359
-
359
+
360
+
360
361
  # Check if AI overwrote the file instead of appending
361
362
  if [[ $new_count -lt $current_original_count ]]; then
362
363
  echo "[ERROR] AI overwrote the CSV file instead of appending ($new_count < $current_original_count)" >&2
363
364
  head -10 "$temp_csv" >&2
364
365
  return 1
365
366
  fi
366
-
367
+
367
368
  # Check if no changes were made
368
369
  if [[ $new_count -eq $current_original_count ]]; then
369
370
  echo "[ERROR] CSV file wasn't modified - same number of data rows ($new_count = $current_original_count)" >&2
370
371
  head -10 "$temp_csv" >&2
371
372
  return 1
372
373
  fi
373
-
374
+
374
375
  local added_count=$((new_count - current_original_count))
375
376
  if [[ $added_count -ne $expected_count ]]; then
376
377
  echo "[ERROR] Expected to add $expected_count ideas but only added $added_count" >&2
@@ -379,6 +380,29 @@ validate_direct_csv_modification() {
379
380
  return 1
380
381
  fi
381
382
 
383
+ # If expected IDs were provided, validate that the AI used exactly those IDs
384
+ if [[ -n "$expected_ids" ]]; then
385
+ # Get the IDs that were actually added (last N rows of temp CSV)
386
+ local actual_ids
387
+ actual_ids=$(tail -n $added_count "$temp_csv" | cut -d',' -f1 | tr -d '"' | tr '\n' ' ' | xargs)
388
+
389
+ # Normalize expected_ids (convert commas to spaces, trim)
390
+ local expected_ids_normalized
391
+ expected_ids_normalized=$(echo "$expected_ids" | tr ',' ' ' | xargs)
392
+
393
+ # Compare
394
+ if [[ "$actual_ids" != "$expected_ids_normalized" ]]; then
395
+ echo "[ERROR] AI used wrong IDs!" >&2
396
+ echo "[ERROR] Expected: $expected_ids_normalized" >&2
397
+ echo "[ERROR] Actually used: $actual_ids" >&2
398
+ echo "[ERROR] Rejecting this attempt - AI must use the exact IDs specified" >&2
399
+ rm -f "$temp_csv"
400
+ return 1
401
+ fi
402
+
403
+ echo "[INFO] ✓ AI correctly used the specified IDs: $actual_ids" >&2
404
+ fi
405
+
382
406
  # Use proper locking to safely update the CSV
383
407
  echo "[INFO] Acquiring CSV lock to apply changes..."
384
408
 
@@ -706,7 +730,7 @@ get_next_id() {
706
730
  echo "gen${generation}-001"
707
731
  return
708
732
  fi
709
-
733
+
710
734
  # Use Python for proper CSV parsing
711
735
  local max_id
712
736
  max_id=$("$PYTHON_CMD" -c "
@@ -726,11 +750,53 @@ with open('$FULL_CSV_PATH', 'r') as f:
726
750
  max_id = max(max_id, id_num)
727
751
  print(max_id)
728
752
  ")
729
-
753
+
730
754
  # Format next ID with generation and 3-digit number
731
755
  printf "gen%s-%03d" "$generation" $((max_id + 1))
732
756
  }
733
757
 
758
+ # Get the next N available IDs for current generation as a comma-separated list
759
+ get_next_ids() {
760
+ local generation="$1"
761
+ local count="$2"
762
+
763
+ # Get the starting ID number
764
+ local start_id
765
+ if [[ ! -f "$FULL_CSV_PATH" ]]; then
766
+ start_id=1
767
+ else
768
+ # Use Python for proper CSV parsing
769
+ start_id=$("$PYTHON_CMD" -c "
770
+ import csv
771
+ import re
772
+ max_id = 0
773
+ pattern = re.compile(r'^gen${generation}-(\d+)$')
774
+ with open('$FULL_CSV_PATH', 'r') as f:
775
+ reader = csv.reader(f)
776
+ next(reader, None) # Skip header
777
+ for row in reader:
778
+ if row and len(row) > 0:
779
+ id_field = row[0].strip()
780
+ match = pattern.match(id_field)
781
+ if match:
782
+ id_num = int(match.group(1))
783
+ max_id = max(max_id, id_num)
784
+ print(max_id + 1)
785
+ ")
786
+ fi
787
+
788
+ # Generate the list of IDs
789
+ local ids=()
790
+ for ((i=0; i<count; i++)); do
791
+ local id_num=$((start_id + i))
792
+ ids+=("$(printf "gen%s-%03d" "$generation" "$id_num")")
793
+ done
794
+
795
+ # Join with commas
796
+ local IFS=','
797
+ echo "${ids[*]}"
798
+ }
799
+
734
800
 
735
801
  # Get top performers for parent selection (absolute + top novel candidates)
736
802
  get_top_performers() {
@@ -884,21 +950,43 @@ ideate_ai_strategies() {
884
950
  # Generate novel exploration ideas using direct CSV modification
885
951
  generate_novel_ideas_direct() {
886
952
  local count="$1"
887
-
953
+
954
+ # Get the next available ID BEFORE creating temp CSV
955
+ # This ensures each strategy gets unique IDs even in parallel runs
956
+ local next_id
957
+ next_id=$(get_next_id "$CURRENT_GENERATION")
958
+ echo "[INFO] Next available ID for novel ideas: $next_id" >&2
959
+
960
+ # Generate the list of IDs this strategy should use
961
+ local next_id_num
962
+ next_id_num=$(echo "$next_id" | grep -o '[0-9]*$')
963
+ local required_ids=()
964
+ for ((i=0; i<count; i++)); do
965
+ required_ids+=("$(printf "gen%s-%03d" "$CURRENT_GENERATION" $((next_id_num + i)))")
966
+ done
967
+ local required_ids_str="${required_ids[*]}"
968
+
888
969
  # Create temporary CSV copy in evolution directory (so AI can access it)
889
970
  local temp_csv="$FULL_EVOLUTION_DIR/temp-csv-$$.csv"
890
971
  cp "$FULL_CSV_PATH" "$temp_csv"
891
-
892
- echo "[INFO] Generating $count novel exploration ideas..."
972
+
973
+ # Pre-populate the CSV with stub rows containing the correct IDs
974
+ # This ensures the AI can't possibly use wrong IDs - it just fills in descriptions
975
+ echo "[INFO] Pre-populating CSV with stub rows: $required_ids_str"
976
+ for id in "${required_ids[@]}"; do
977
+ echo "$id,,\"[PLACEHOLDER: Replace this with your algorithmic idea]\",,pending" >> "$temp_csv"
978
+ done
979
+
980
+ echo "[INFO] Generating $count novel exploration ideas with IDs: $required_ids_str"
893
981
  local data_rows=$(grep -v '^[[:space:]]*$' "$FULL_CSV_PATH" | tail -n +2 | wc -l)
894
-
982
+
895
983
  # Use relative paths and change to evolution directory so AI can access files
896
984
  local temp_csv_basename=$(basename "$temp_csv")
897
-
985
+
898
986
  # Get existing Python files for this generation to avoid ID collisions
899
987
  local existing_py_files=$(get_existing_py_files_for_generation "$CURRENT_GENERATION")
900
-
901
- local prompt="I need you to use your file editing capabilities to APPEND exactly $count novel algorithmic ideas to the CSV file: $temp_csv_basename
988
+
989
+ local prompt="I need you to use your file editing capabilities to fill in PLACEHOLDER descriptions in the CSV file: $temp_csv_basename
902
990
 
903
991
  Current evolution context:
904
992
  - Generation: $CURRENT_GENERATION
@@ -907,21 +995,23 @@ Current evolution context:
907
995
 
908
996
  IMPORTANT: DO NOT read algorithm.py or any evolution_*.py files. Focus on creative ideation based on the brief and CSV context only. Reading code files wastes tokens and time.
909
997
 
998
+ CRITICAL TASK:
999
+ The CSV file already contains $count stub rows with these IDs: $required_ids_str
1000
+ Each stub row has a PLACEHOLDER description like: \"[PLACEHOLDER: Replace this with your algorithmic idea]\"
1001
+ Your job is to REPLACE each PLACEHOLDER with a real algorithmic idea description.
1002
+
910
1003
  CRITICAL INSTRUCTIONS:
911
- 1. Use the Read tool to examine the current CSV file
912
- IMPORTANT: If the CSV file is large (>200 lines), read it in chunks using the offset and limit parameters to avoid context overload
913
- Example: Read(file_path='temp-csv-123.csv', offset=0, limit=100) then Read(offset=100, limit=100), etc.
914
- 2. DO NOT DELETE OR REPLACE ANY EXISTING ROWS - YOU MUST PRESERVE ALL EXISTING DATA
915
- 3. Find the highest ID number for generation $CURRENT_GENERATION (e.g., if gen$CURRENT_GENERATION-003 exists, next should be gen$CURRENT_GENERATION-004)
916
- 4. If no gen$CURRENT_GENERATION entries exist yet, start with gen$CURRENT_GENERATION-001"
917
-
1004
+ 1. Use the Read tool to examine the CSV file (read from the END to see the placeholder rows)
1005
+ Example: Read the last 20 lines to see the placeholders
1006
+ 2. DO NOT ADD OR DELETE ANY ROWS - only EDIT the placeholder descriptions
1007
+ 3. DO NOT CHANGE THE IDs - they are already correct
1008
+ 4. Use the Edit tool to replace each PLACEHOLDER description with a real idea
1009
+ 5. Each replacement should be one clear sentence describing a novel algorithmic approach"
1010
+
918
1011
  if [[ -n "$existing_py_files" ]]; then
919
1012
  prompt+="
920
- 5. IMPORTANT: The following IDs already have Python files and MUST NOT be reused: $existing_py_files
921
- 6. Skip these IDs when assigning new IDs (e.g., if gen$CURRENT_GENERATION-001 and gen$CURRENT_GENERATION-002 exist as Python files, start with gen$CURRENT_GENERATION-003)"
922
- else
923
- prompt+="
924
- 5. No existing Python files found for generation $CURRENT_GENERATION"
1013
+ 5. IMPORTANT: The following IDs already have Python files: $existing_py_files
1014
+ (This is informational only - use the IDs specified above)"
925
1015
  fi
926
1016
 
927
1017
  prompt+="
@@ -965,13 +1055,13 @@ CRITICAL: Do NOT use any git commands (git add, git commit, git reset, etc.). On
965
1055
  # Restore working directory
966
1056
  cd "$original_pwd"
967
1057
 
968
-
969
- # Validate that the CSV file was actually modified
970
- if ! validate_direct_csv_modification "$temp_csv" "$count" "novel" "$ai_response"; then
1058
+
1059
+ # Validate that the CSV file was actually modified with correct IDs
1060
+ if ! validate_direct_csv_modification "$temp_csv" "$count" "novel" "$ai_response" "$required_ids_str"; then
971
1061
  rm -f "$temp_csv"
972
1062
  return 1
973
1063
  fi
974
-
1064
+
975
1065
  echo "[INFO] Novel exploration ideas generated successfully"
976
1066
  return 0
977
1067
  }
@@ -980,25 +1070,48 @@ CRITICAL: Do NOT use any git commands (git add, git commit, git reset, etc.). On
980
1070
  generate_hill_climbing_direct() {
981
1071
  local count="$1"
982
1072
  local top_performers="$2"
983
-
1073
+
1074
+ # Get the next available ID BEFORE creating temp CSV
1075
+ local next_id
1076
+ next_id=$(get_next_id "$CURRENT_GENERATION")
1077
+ echo "[INFO] Next available ID for hill climbing: $next_id" >&2
1078
+
1079
+ # Generate the list of IDs this strategy should use
1080
+ local next_id_num
1081
+ next_id_num=$(echo "$next_id" | grep -o '[0-9]*$')
1082
+ local required_ids=()
1083
+ for ((i=0; i<count; i++)); do
1084
+ required_ids+=("$(printf "gen%s-%03d" "$CURRENT_GENERATION" $((next_id_num + i)))")
1085
+ done
1086
+ local required_ids_str="${required_ids[*]}"
1087
+
984
1088
  # Create temporary CSV copy in evolution directory (so AI can access it)
985
1089
  local temp_csv="$FULL_EVOLUTION_DIR/temp-csv-$$.csv"
986
1090
  cp "$FULL_CSV_PATH" "$temp_csv"
987
-
988
- echo "[INFO] Generating $count hill climbing ideas..."
1091
+
1092
+ # Pre-populate the CSV with stub rows containing the correct IDs and parent IDs
1093
+ echo "[INFO] Pre-populating CSV with stub rows: $required_ids_str"
1094
+ # Use first parent as default for stubs (AI will adjust if needed)
1095
+ local first_parent_id
1096
+ first_parent_id=$(echo "$valid_parent_ids" | cut -d',' -f1)
1097
+ for id in "${required_ids[@]}"; do
1098
+ echo "$id,$first_parent_id,\"[PLACEHOLDER: Replace with parameter tuning idea]\",,pending" >> "$temp_csv"
1099
+ done
1100
+
1101
+ echo "[INFO] Generating $count hill climbing ideas with IDs: $required_ids_str"
989
1102
  local data_rows=$(grep -v '^[[:space:]]*$' "$FULL_CSV_PATH" | tail -n +2 | wc -l)
990
-
1103
+
991
1104
  # Get existing Python files for this generation to avoid ID collisions
992
1105
  local existing_py_files=$(get_existing_py_files_for_generation "$CURRENT_GENERATION")
993
-
1106
+
994
1107
  # Extract just the IDs from top performers for clarity
995
1108
  local valid_parent_ids
996
1109
  valid_parent_ids=$(echo "$top_performers" | cut -d',' -f1 | paste -sd ',' -)
997
-
1110
+
998
1111
  # Use relative paths and change to evolution directory so AI can access files
999
1112
  local temp_csv_basename=$(basename "$temp_csv")
1000
-
1001
- local prompt="I need you to use your file editing capabilities to APPEND exactly $count parameter tuning ideas to the CSV file: $temp_csv_basename
1113
+
1114
+ local prompt="I need you to use your file editing capabilities to fill in PLACEHOLDER descriptions in the CSV file: $temp_csv_basename
1002
1115
 
1003
1116
  IMPORTANT: You MUST use one of these exact parent IDs: $valid_parent_ids
1004
1117
 
@@ -1019,28 +1132,21 @@ If you must read source files:
1019
1132
 
1020
1133
  Most of the time, you can infer parameters from descriptions like "RSI with threshold 30" or "MA period 20".
1021
1134
 
1022
- CRITICAL INSTRUCTIONS:
1023
- 1. Use the Read tool to examine the current CSV file
1024
- IMPORTANT: If the CSV file is large (>200 lines), read it in chunks using the offset and limit parameters to avoid context overload
1025
- Example: Read(file_path='temp-csv-123.csv', offset=0, limit=100) then Read(offset=100, limit=100), etc.
1026
- 2. DO NOT DELETE OR REPLACE ANY EXISTING ROWS - YOU MUST PRESERVE ALL EXISTING DATA
1027
- 3. Find the highest ID number for generation $CURRENT_GENERATION (e.g., if gen$CURRENT_GENERATION-003 exists, next should be gen$CURRENT_GENERATION-004)
1028
- 4. If no gen$CURRENT_GENERATION entries exist yet, start with gen$CURRENT_GENERATION-001
1029
- 5. Use the Edit or MultiEdit tool to APPEND exactly $count new rows AT THE END of the CSV file
1030
- 6. For each idea, create a row with: id,parent_id,description,,pending
1031
- 7. Each parent_id MUST be one of: $valid_parent_ids
1032
- 8. CRITICAL CSV FORMATTING RULES:
1033
- - ALWAYS wrap the description field in double quotes
1034
- - If the description contains quotes, escape them by doubling them (\" becomes \"\")
1035
- - Example: gen01-001,gen00-000,\"Lower rsi_entry from 21 to 18\",,pending
1036
- - BAD: gen01-001,gen00-000,Lower rsi_entry from 21 to 18,,pending
1037
- - NEVER omit quotes around descriptions - this causes CSV parsing errors
1038
- 9. Each description should focus on adjusting specific parameters that exist in the parent's source code
1039
- 10. Include current and new parameter values - for example: \"Lower rsi_entry from 21 to 18\"
1135
+ CRITICAL TASK:
1136
+ The CSV file already contains $count stub rows with these IDs: $required_ids_str
1137
+ Each stub row has a PLACEHOLDER description like: \"[PLACEHOLDER: Replace with parameter tuning idea]\"
1138
+ Your job is to REPLACE each PLACEHOLDER with a real parameter tuning idea.
1040
1139
 
1041
- IMPORTANT: You must APPEND new rows to the existing CSV file. DO NOT replace the file contents. All existing rows must remain unchanged.
1042
- CRITICAL: You must use your file editing tools (Edit/MultiEdit) to modify the CSV file. DO NOT return CSV text - use your tools to edit the file directly.
1043
- CRITICAL: Do NOT use any git commands (git add, git commit, git reset, etc.). Only modify the file directly."
1140
+ CRITICAL INSTRUCTIONS:
1141
+ 1. Use the Read tool to examine the CSV file (read from the END to see the placeholder rows)
1142
+ 2. DO NOT ADD OR DELETE ANY ROWS - only EDIT the placeholder descriptions
1143
+ 3. DO NOT CHANGE THE IDs - they are already correct
1144
+ 4. Use the Edit tool to replace each PLACEHOLDER description with a parameter tuning idea
1145
+ 5. You may also change the parent_id field if needed to reference a different top performer
1146
+ 6. Each description should focus on adjusting specific parameters - include current and new values
1147
+ Example: \"Lower rsi_entry from 21 to 18\" or \"Increase MA period from 20 to 50\"
1148
+ 7. CRITICAL: When editing, preserve the CSV formatting with proper quoting
1149
+ 8. DO NOT use any git commands (git add, git commit, git reset, etc.). Only modify the file directly."
1044
1150
 
1045
1151
  # Change to evolution directory so AI can access files
1046
1152
  local original_pwd=$(pwd)
@@ -1062,13 +1168,13 @@ CRITICAL: Do NOT use any git commands (git add, git commit, git reset, etc.). On
1062
1168
  # Restore working directory
1063
1169
  cd "$original_pwd"
1064
1170
 
1065
-
1066
- # Validate that the CSV file was actually modified
1067
- if ! validate_direct_csv_modification "$temp_csv" "$count" "hill-climbing" "$ai_response"; then
1171
+
1172
+ # Validate that the CSV file was actually modified with correct IDs
1173
+ if ! validate_direct_csv_modification "$temp_csv" "$count" "hill-climbing" "$ai_response" "$required_ids_str"; then
1068
1174
  rm -f "$temp_csv"
1069
1175
  return 1
1070
1176
  fi
1071
-
1177
+
1072
1178
  echo "[INFO] Hill climbing ideas generated successfully"
1073
1179
  return 0
1074
1180
  }
@@ -1077,25 +1183,47 @@ CRITICAL: Do NOT use any git commands (git add, git commit, git reset, etc.). On
1077
1183
  generate_structural_mutation_direct() {
1078
1184
  local count="$1"
1079
1185
  local top_performers="$2"
1080
-
1186
+
1187
+ # Get the next available ID BEFORE creating temp CSV
1188
+ local next_id
1189
+ next_id=$(get_next_id "$CURRENT_GENERATION")
1190
+ echo "[INFO] Next available ID for structural mutation: $next_id" >&2
1191
+
1192
+ # Generate the list of IDs this strategy should use
1193
+ local next_id_num
1194
+ next_id_num=$(echo "$next_id" | grep -o '[0-9]*$')
1195
+ local required_ids=()
1196
+ for ((i=0; i<count; i++)); do
1197
+ required_ids+=("$(printf "gen%s-%03d" "$CURRENT_GENERATION" $((next_id_num + i)))")
1198
+ done
1199
+ local required_ids_str="${required_ids[*]}"
1200
+
1081
1201
  # Create temporary CSV copy in evolution directory (so AI can access it)
1082
1202
  local temp_csv="$FULL_EVOLUTION_DIR/temp-csv-$$.csv"
1083
1203
  cp "$FULL_CSV_PATH" "$temp_csv"
1084
-
1085
- echo "[INFO] Generating $count structural mutation ideas..."
1204
+
1205
+ # Pre-populate the CSV with stub rows
1206
+ echo "[INFO] Pre-populating CSV with stub rows: $required_ids_str"
1207
+ local first_parent_id
1208
+ first_parent_id=$(echo "$valid_parent_ids" | cut -d',' -f1)
1209
+ for id in "${required_ids[@]}"; do
1210
+ echo "$id,$first_parent_id,\"[PLACEHOLDER: Replace with structural modification idea]\",,pending" >> "$temp_csv"
1211
+ done
1212
+
1213
+ echo "[INFO] Generating $count structural mutation ideas with IDs: $required_ids_str"
1086
1214
  local data_rows=$(grep -v '^[[:space:]]*$' "$FULL_CSV_PATH" | tail -n +2 | wc -l)
1087
-
1215
+
1088
1216
  # Get existing Python files for this generation to avoid ID collisions
1089
1217
  local existing_py_files=$(get_existing_py_files_for_generation "$CURRENT_GENERATION")
1090
-
1218
+
1091
1219
  # Extract just the IDs from top performers for clarity
1092
1220
  local valid_parent_ids
1093
1221
  valid_parent_ids=$(echo "$top_performers" | cut -d',' -f1 | paste -sd ',' -)
1094
-
1222
+
1095
1223
  # Use relative paths and change to evolution directory so AI can access files
1096
1224
  local temp_csv_basename=$(basename "$temp_csv")
1097
-
1098
- local prompt="I need you to use your file editing capabilities to APPEND exactly $count structural modification ideas to the CSV file: $temp_csv_basename
1225
+
1226
+ local prompt="I need you to use your file editing capabilities to fill in PLACEHOLDER descriptions in the CSV file: $temp_csv_basename
1099
1227
 
1100
1228
  IMPORTANT: You MUST use one of these exact parent IDs: $valid_parent_ids
1101
1229
 
@@ -1108,28 +1236,20 @@ IMPORTANT: DO NOT read evolution_*.py files. Generate structural ideas based ONL
1108
1236
  - Your knowledge of common algorithmic structures and patterns
1109
1237
  Reading code files wastes tokens and time. Focus on high-level architectural ideas based on the descriptions.
1110
1238
 
1111
- CRITICAL INSTRUCTIONS:
1112
- 1. Use the Read tool to examine the current CSV file
1113
- IMPORTANT: If the CSV file is large (>200 lines), read it in chunks using the offset and limit parameters to avoid context overload
1114
- Example: Read(file_path='temp-csv-123.csv', offset=0, limit=100) then Read(offset=100, limit=100), etc.
1115
- 2. DO NOT DELETE OR REPLACE ANY EXISTING ROWS - YOU MUST PRESERVE ALL EXISTING DATA
1116
- 3. Find the highest ID number for generation $CURRENT_GENERATION (e.g., if gen$CURRENT_GENERATION-003 exists, next should be gen$CURRENT_GENERATION-004)
1117
- 4. If no gen$CURRENT_GENERATION entries exist yet, start with gen$CURRENT_GENERATION-001
1118
- 5. Use the Edit or MultiEdit tool to APPEND exactly $count new rows AT THE END of the CSV file
1119
- 6. For each idea, create a row with: id,parent_id,description,,pending
1120
- 7. Each parent_id MUST be one of: $valid_parent_ids
1121
- 8. CRITICAL CSV FORMATTING RULES:
1122
- - ALWAYS wrap the description field in double quotes
1123
- - If the description contains quotes, escape them by doubling them (\" becomes \"\")
1124
- - Example: gen01-001,gen00-000,\"Add ML-based regime detection using LSTM\",,pending
1125
- - BAD: gen01-001,gen00-000,Add ML-based regime detection using LSTM,,pending
1126
- - NEVER omit quotes around descriptions - this causes CSV parsing errors
1127
- 9. Each description should focus on architectural/structural changes based on the parent's actual code
1128
- 10. Reference actual components/methods found in the source code
1239
+ CRITICAL TASK:
1240
+ The CSV file already contains $count stub rows with these IDs: $required_ids_str
1241
+ Each stub row has a PLACEHOLDER description like: \"[PLACEHOLDER: Replace with structural modification idea]\"
1242
+ Your job is to REPLACE each PLACEHOLDER with a real structural modification idea.
1129
1243
 
1130
- IMPORTANT: You must APPEND new rows to the existing CSV file. DO NOT replace the file contents. All existing rows must remain unchanged.
1131
- CRITICAL: You must use your file editing tools (Edit/MultiEdit) to modify the CSV file. DO NOT return CSV text - use your tools to edit the file directly.
1132
- CRITICAL: Do NOT use any git commands (git add, git commit, git reset, etc.). Only modify the file directly."
1244
+ CRITICAL INSTRUCTIONS:
1245
+ 1. Use the Read tool to examine the CSV file (read from the END to see the placeholder rows)
1246
+ 2. DO NOT ADD OR DELETE ANY ROWS - only EDIT the placeholder descriptions
1247
+ 3. DO NOT CHANGE THE IDs - they are already correct
1248
+ 4. Use the Edit tool to replace each PLACEHOLDER description with a structural modification idea
1249
+ 5. You may also change the parent_id field if needed to reference a different top performer
1250
+ 6. Each description should focus on architectural/structural changes
1251
+ 7. CRITICAL: When editing, preserve the CSV formatting with proper quoting
1252
+ 8. DO NOT use any git commands (git add, git commit, git reset, etc.). Only modify the file directly."
1133
1253
 
1134
1254
  # Change to evolution directory so AI can access files
1135
1255
  local original_pwd=$(pwd)
@@ -1151,13 +1271,13 @@ CRITICAL: Do NOT use any git commands (git add, git commit, git reset, etc.). On
1151
1271
  # Restore working directory
1152
1272
  cd "$original_pwd"
1153
1273
 
1154
-
1155
- # Validate that the CSV file was actually modified
1156
- if ! validate_direct_csv_modification "$temp_csv" "$count" "structural" "$ai_response"; then
1274
+
1275
+ # Validate that the CSV file was actually modified with correct IDs
1276
+ if ! validate_direct_csv_modification "$temp_csv" "$count" "structural" "$ai_response" "$required_ids_str"; then
1157
1277
  rm -f "$temp_csv"
1158
1278
  return 1
1159
1279
  fi
1160
-
1280
+
1161
1281
  echo "[INFO] Structural mutation ideas generated successfully"
1162
1282
  return 0
1163
1283
  }
@@ -1166,25 +1286,47 @@ CRITICAL: Do NOT use any git commands (git add, git commit, git reset, etc.). On
1166
1286
  generate_crossover_direct() {
1167
1287
  local count="$1"
1168
1288
  local top_performers="$2"
1169
-
1289
+
1290
+ # Get the next available ID BEFORE creating temp CSV
1291
+ local next_id
1292
+ next_id=$(get_next_id "$CURRENT_GENERATION")
1293
+ echo "[INFO] Next available ID for crossover: $next_id" >&2
1294
+
1295
+ # Generate the list of IDs this strategy should use
1296
+ local next_id_num
1297
+ next_id_num=$(echo "$next_id" | grep -o '[0-9]*$')
1298
+ local required_ids=()
1299
+ for ((i=0; i<count; i++)); do
1300
+ required_ids+=("$(printf "gen%s-%03d" "$CURRENT_GENERATION" $((next_id_num + i)))")
1301
+ done
1302
+ local required_ids_str="${required_ids[*]}"
1303
+
1170
1304
  # Create temporary CSV copy in evolution directory (so AI can access it)
1171
1305
  local temp_csv="$FULL_EVOLUTION_DIR/temp-csv-$$.csv"
1172
1306
  cp "$FULL_CSV_PATH" "$temp_csv"
1173
-
1174
- echo "[INFO] Generating $count crossover hybrid ideas..."
1307
+
1308
+ # Pre-populate the CSV with stub rows
1309
+ echo "[INFO] Pre-populating CSV with stub rows: $required_ids_str"
1310
+ local first_parent_id
1311
+ first_parent_id=$(echo "$valid_parent_ids" | cut -d',' -f1)
1312
+ for id in "${required_ids[@]}"; do
1313
+ echo "$id,$first_parent_id,\"[PLACEHOLDER: Replace with crossover hybrid idea]\",,pending" >> "$temp_csv"
1314
+ done
1315
+
1316
+ echo "[INFO] Generating $count crossover hybrid ideas with IDs: $required_ids_str"
1175
1317
  local data_rows=$(grep -v '^[[:space:]]*$' "$FULL_CSV_PATH" | tail -n +2 | wc -l)
1176
-
1318
+
1177
1319
  # Get existing Python files for this generation to avoid ID collisions
1178
1320
  local existing_py_files=$(get_existing_py_files_for_generation "$CURRENT_GENERATION")
1179
-
1321
+
1180
1322
  # Extract just the IDs from top performers for clarity
1181
1323
  local valid_parent_ids
1182
1324
  valid_parent_ids=$(echo "$top_performers" | cut -d',' -f1 | paste -sd ',' -)
1183
-
1325
+
1184
1326
  # Use relative paths and change to evolution directory so AI can access files
1185
1327
  local temp_csv_basename=$(basename "$temp_csv")
1186
-
1187
- local prompt="I need you to use your file editing capabilities to APPEND exactly $count hybrid combination ideas to the CSV file: $temp_csv_basename
1328
+
1329
+ local prompt="I need you to use your file editing capabilities to fill in PLACEHOLDER descriptions in the CSV file: $temp_csv_basename
1188
1330
 
1189
1331
  IMPORTANT: You MUST use ONLY these exact parent IDs: $valid_parent_ids
1190
1332
 
@@ -1197,28 +1339,20 @@ IMPORTANT: DO NOT read evolution_*.py files. Generate crossover ideas based ONLY
1197
1339
  - Your knowledge of how different algorithmic approaches can be combined
1198
1340
  Reading code files wastes tokens and time. Focus on combining the described features creatively.
1199
1341
 
1200
- CRITICAL INSTRUCTIONS:
1201
- 1. Use the Read tool to examine the current CSV file
1202
- IMPORTANT: If the CSV file is large (>200 lines), read it in chunks using the offset and limit parameters to avoid context overload
1203
- Example: Read(file_path='temp-csv-123.csv', offset=0, limit=100) then Read(offset=100, limit=100), etc.
1204
- 2. DO NOT DELETE OR REPLACE ANY EXISTING ROWS - YOU MUST PRESERVE ALL EXISTING DATA
1205
- 3. Find the highest ID number for generation $CURRENT_GENERATION (e.g., if gen$CURRENT_GENERATION-003 exists, next should be gen$CURRENT_GENERATION-004)
1206
- 4. If no gen$CURRENT_GENERATION entries exist yet, start with gen$CURRENT_GENERATION-001
1207
- 5. Use the Edit or MultiEdit tool to APPEND exactly $count new rows AT THE END of the CSV file
1208
- 6. For each idea, create a row with: id,parent_id,description,,pending
1209
- 7. Each parent_id MUST be one of: $valid_parent_ids (choose the primary parent)
1210
- 8. CRITICAL CSV FORMATTING RULES:
1211
- - ALWAYS wrap the description field in double quotes
1212
- - If the description contains quotes, escape them by doubling them (\" becomes \"\")
1213
- - Example: gen01-001,gen00-000,\"Combine gen01-123's RSI logic with gen01-456's volatility scaling\",,pending
1214
- - BAD: gen01-001,gen00-000,Combine gen01-123's RSI logic with gen01-456's volatility scaling,,pending
1215
- - NEVER omit quotes around descriptions - this causes CSV parsing errors
1216
- 9. Each description should combine actual elements from 2+ algorithms based on their source code
1217
- 10. Reference specific components/features found in the actual source code
1342
+ CRITICAL TASK:
1343
+ The CSV file already contains $count stub rows with these IDs: $required_ids_str
1344
+ Each stub row has a PLACEHOLDER description like: \"[PLACEHOLDER: Replace with crossover hybrid idea]\"
1345
+ Your job is to REPLACE each PLACEHOLDER with a real crossover/hybrid idea that combines 2+ algorithms.
1218
1346
 
1219
- IMPORTANT: You must APPEND new rows to the existing CSV file. DO NOT replace the file contents. All existing rows must remain unchanged.
1220
- CRITICAL: You must use your file editing tools (Edit/MultiEdit) to modify the CSV file. DO NOT return CSV text - use your tools to edit the file directly.
1221
- CRITICAL: Do NOT use any git commands (git add, git commit, git reset, etc.). Only modify the file directly."
1347
+ CRITICAL INSTRUCTIONS:
1348
+ 1. Use the Read tool to examine the CSV file (read from the END to see the placeholder rows)
1349
+ 2. DO NOT ADD OR DELETE ANY ROWS - only EDIT the placeholder descriptions
1350
+ 3. DO NOT CHANGE THE IDs - they are already correct
1351
+ 4. Use the Edit tool to replace each PLACEHOLDER description with a crossover idea
1352
+ 5. You may also change the parent_id field if needed (choose the primary parent)
1353
+ 6. Each description should combine actual elements from 2+ top performers
1354
+ 7. CRITICAL: When editing, preserve the CSV formatting with proper quoting
1355
+ 8. DO NOT use any git commands (git add, git commit, git reset, etc.). Only modify the file directly."
1222
1356
 
1223
1357
  # Change to evolution directory so AI can access files
1224
1358
  local original_pwd=$(pwd)
@@ -1240,13 +1374,13 @@ CRITICAL: Do NOT use any git commands (git add, git commit, git reset, etc.). On
1240
1374
  # Restore working directory
1241
1375
  cd "$original_pwd"
1242
1376
 
1243
-
1244
- # Validate that the CSV file was actually modified
1245
- if ! validate_direct_csv_modification "$temp_csv" "$count" "crossover" "$ai_response"; then
1377
+
1378
+ # Validate that the CSV file was actually modified with correct IDs
1379
+ if ! validate_direct_csv_modification "$temp_csv" "$count" "crossover" "$ai_response" "$required_ids_str"; then
1246
1380
  rm -f "$temp_csv"
1247
1381
  return 1
1248
1382
  fi
1249
-
1383
+
1250
1384
  echo "[INFO] Crossover hybrid ideas generated successfully"
1251
1385
  return 0
1252
1386
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-evolve",
3
- "version": "1.7.14",
3
+ "version": "1.7.16",
4
4
  "bin": {
5
5
  "claude-evolve": "./bin/claude-evolve",
6
6
  "claude-evolve-main": "./bin/claude-evolve-main",