-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(scripts): update context extraction and placeholder handling #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…pdate-agent-context.sh
There was a problem hiding this 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 issues with variable handling and escaping in the update-agent-context.sh
script to improve reliability and maintainability. The script updates agent context files based on feature branch changes.
- Escapes square brackets in
sed
placeholder replacements to prevent regex interpretation - Fixes Bash variable references within embedded Python code by using environment variables
- Improves regex patterns for extracting markdown metadata from plan files
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
if "$NEW_LANG" and f"# {NEW_LANG}" not in content: | ||
commands_section = re.search(r'## Commands\n\`\`\`bash\n(.*?)\n\`\`\`', content, re.DOTALL) | ||
if new_lang and new_lang not in content: | ||
commands_section = re.search(r'## Commands\n```bash\n(.*?)\n```', content, re.DOTALL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the previous comment, the regex patterns with backticks in raw strings should be escaped as r'## Commands\\n```bash\\n(.*?)\\n```'
to ensure proper matching of markdown code blocks.
Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
if "$NEW_PROJECT_TYPE" == "web" and "frontend/" not in content: | ||
struct_section = re.search(r'## Project Structure\n\`\`\`\n(.*?)\n\`\`\`', content, re.DOTALL) | ||
if new_project_type == "web" and "frontend/" not in content: | ||
struct_section = re.search(r'## Project Structure\n```\n(.*?)\n```', content, re.DOTALL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex patterns for matching markdown code blocks are duplicated across multiple sections. Consider extracting these into reusable functions or constants to improve maintainability.
Copilot uses AI. Check for mistakes.
value=$(grep "^\\*\\*${field}\\*\\*: " "$plan_file" 2>/dev/null | head -1 | sed "s|^\\*\\*${field}\\*\\*: ||") | ||
# Filter out "NEEDS CLARIFICATION" for all except Project Type | ||
if [[ "$field" == "Storage" ]]; then | ||
value=$(echo "$value" | grep -v "N/A" | grep -v "NEEDS CLARIFICATION") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using multiple grep commands with pipes creates unnecessary subprocesses. Consider using a single grep with alternation pattern: grep -v -E '(N/A|NEEDS CLARIFICATION)'
.
value=$(echo "$value" | grep -v "N/A" | grep -v "NEEDS CLARIFICATION") | |
value=$(echo "$value" | grep -v -E 'N/A|NEEDS CLARIFICATION') |
Copilot uses AI. Check for mistakes.
value=$(grep "^\\*\\*${field}\\*\\*: " "$plan_file" 2>/dev/null | head -1 | sed "s|^\\*\\*${field}\\*\\*: ||") | ||
# Filter out "NEEDS CLARIFICATION" for all except Project Type | ||
if [[ "$field" == "Storage" ]]; then | ||
value=$(echo "$value" | grep -v "N/A" | grep -v "NEEDS CLARIFICATION") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using multiple grep commands with pipes creates unnecessary subprocesses. Consider using a single grep with alternation pattern: grep -v -E '(N/A|NEEDS CLARIFICATION)'
.
value=$(echo "$value" | grep -v "N/A" | grep -v "NEEDS CLARIFICATION") | |
value=$(echo "$value" | grep -v -E 'N/A|NEEDS CLARIFICATION') |
Copilot uses AI. Check for mistakes.
This pull request refines and improves the
scripts/update-agent-context.sh
script, focusing on better handling of special characters in placeholders, more robust environment variable passing to the embedded Python script, and improved maintainability. The changes also fix quoting and escaping issues and ensure that Bash variables are properly referenced in both shell and Python code.Shell script improvements:
sed
commands now properly escape square brackets in placeholders (e.g.,[PROJECT NAME]
), ensuring accurate and reliable text substitution. [1] [2]Python integration and variable handling:
os.environ
for improved clarity and reliability.General maintainability and correctness:
These changes collectively make the script more robust and easier to maintain, while fixing subtle bugs related to string escaping and variable usage.
fix #47
fix #154