💫 Toolkit to help you get started with SDD or any other process!
Fix update-agent-context.sh to handle files without Active Technologies/Recent Changes sections
Mark09cf4f6cc4b7
diff --git a/scripts/bash/update-agent-context.sh b/scripts/bash/update-agent-context.shindex d3cc422ed..a7fafc402 100644--- a/scripts/bash/update-agent-context.sh+++ b/scripts/bash/update-agent-context.sh@@ -388,12 +388,25 @@ update_existing_agent_file() {new_change_entry="- $CURRENT_BRANCH: Added $NEW_DB"fi+ # Check if sections exist in the file+ local has_active_technologies=0+ local has_recent_changes=0++ if grep -q "^## Active Technologies" "$target_file" 2>/dev/null; then+ has_active_technologies=1+ fi++ if grep -q "^## Recent Changes" "$target_file" 2>/dev/null; then+ has_recent_changes=1+ fi+# Process file line by linelocal in_tech_section=falselocal in_changes_section=falselocal tech_entries_added=falselocal changes_entries_added=falselocal existing_changes_count=0+ local file_ended=falsewhile IFS= read -r line || [[ -n "$line" ]]; do# Handle Active Technologies section@@ -454,6 +467,22 @@ update_existing_agent_file() {# Post-loop check: if we're still in the Active Technologies section and haven't added new entriesif [[ $in_tech_section == true ]] && [[ $tech_entries_added == false ]] && [[ ${#new_tech_entries[@]} -gt 0 ]]; thenprintf '%s\n' "${new_tech_entries[@]}" >> "$temp_file"+ tech_entries_added=true+ fi++ # If sections don't exist, add them at the end of the file+ if [[ $has_active_technologies -eq 0 ]] && [[ ${#new_tech_entries[@]} -gt 0 ]]; then+ echo "" >> "$temp_file"+ echo "## Active Technologies" >> "$temp_file"+ printf '%s\n' "${new_tech_entries[@]}" >> "$temp_file"+ tech_entries_added=true+ fi++ if [[ $has_recent_changes -eq 0 ]] && [[ -n "$new_change_entry" ]]; then+ echo "" >> "$temp_file"+ echo "## Recent Changes" >> "$temp_file"+ echo "$new_change_entry" >> "$temp_file"+ changes_entries_added=truefi# Move temp file to target atomically