Skip to content

Conversation

valdezm
Copy link

@valdezm valdezm commented Sep 25, 2025

Problem

The update-agent-context.sh script was failing to update agent files like CLAUDE.md that were manually created and didn't follow the expected template structure. The script expected files to have "Active Technologies" and "Recent Changes" sections, but when these sections didn't exist, the script would silently process the file without making any changes.

Solution

This PR enhances the script to:

  1. Detect missing sections: Added logic to check if the required "Active Technologies" and "Recent Changes" sections exist in the target file
  2. Auto-append missing sections: If sections don't exist, automatically add them at the end of the file
  3. Preserve existing content: All manually-created content in agent files is preserved
  4. Fix syntax errors: Corrected bash syntax issues in grep command handling
  5. Improve robustness: Handle files that don't follow the template structure gracefully

Changes Made

  • Added section detection logic using grep -q to check for section headers
  • Added conditional logic to append missing sections at the end of existing files
  • Fixed bash syntax errors that were causing issues with variable assignments
  • Maintained backward compatibility with files that already have the correct structure

Testing

Tested with a manually-created CLAUDE.md file that lacked the required sections. The script now successfully:

  • Detects the missing sections
  • Adds them at the end of the file
  • Populates them with information from the current feature's plan.md
  • Preserves all existing content

Impact

This fix ensures that the update-agent-context.sh script works reliably with both:

  • Files created from templates (existing functionality preserved)
  • Manually-created agent files (new functionality added)

No breaking changes - existing workflows continue to work as before.

…es/Recent Changes sections

- Add section detection logic to check if required sections exist
- Automatically append missing sections at end of file if they don't exist
- Preserve existing manually-created content in agent files
- Fix bash syntax errors in grep command handling
- Improve robustness for files that don't follow template structure

This fixes an issue where the script would silently fail to update agent files
like CLAUDE.md that were manually created with different section structures.
@valdezm valdezm requested a review from localden as a code owner September 25, 2025 21:45
@Copilot Copilot AI review requested due to automatic review settings September 25, 2025 21:45
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the update-agent-context.sh script to handle agent files that don't follow the expected template structure. The script now detects missing "Active Technologies" and "Recent Changes" sections and automatically appends them to files that lack these sections, while preserving all existing content.

  • Adds section detection logic to check for required headers
  • Implements auto-append functionality for missing sections
  • Maintains backward compatibility with existing template-structured files

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

local tech_entries_added=false
local changes_entries_added=false
local existing_changes_count=0
local file_ended=false
Copy link

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable file_ended is declared but never used in the diff. If this variable isn't used elsewhere in the function, consider removing it to avoid confusion.

Suggested change
local file_ended=false

Copilot uses AI. Check for mistakes.

@localden localden self-assigned this Sep 30, 2025
@localden localden added templates Related to template definition and not the CLI. merge-candidate Reasonable change that is going to be merged after a review. labels Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-candidate Reasonable change that is going to be merged after a review. templates Related to template definition and not the CLI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants