-
Notifications
You must be signed in to change notification settings - Fork 0
Fixes #issue-number: Enhance PR generation and handle multiline GitHub command extraction #9
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
Conversation
- Improve agentask with better model management, argument parsing, help messages, and debugging capabilities - Ensure agentask robustly handles multiline AI responses - Refactor agentcommit for improved argument handling and a stricter conventional commit message generation prompt - Enhance agentcommit's parsing of AI responses to reliably extract the git commit command - Update agentcommit completions to inherit from agentask for better user experience
- Refactor argument parsing into a dedicated `_agentcommit_parse_args` function for better organization - Introduce global variables for parsed arguments and flags to enhance state management and readability - Extract help message display logic into a `_agentcommit_show_help` function for modularity - Update the list of allowed conventional commit types to include `ci` - Replace old argument variables with new global variables for consistency across the script
- Improve AI prompt for GitHub issue generation with detailed instructions and output rules - Add --debug flag for verbose output of prompts and AI responses - Refine argument parsing to correctly pass unknown options to agentask - Enhance parsing of AI response using ripgrep for robustness - Improve display of generated issue with bat for readability - Implement dry-run mode with fake response for testing parsing - Add clipboard integration for the generated gh command - Update help message with new options and usage examples - Inherit completions from agentask for agentissue command
- Refactor agentpr for improved maintainability and clarity. - Add --agent and --model options to specify AI models for PR generation. - Update PR prompt with detailed instructions for AI, including issue extraction, commit analysis, and required sections. - Implement robust parsing of AI response to extract gh command, title, and body. - Improve error handling for empty AI responses and missing gh command. - Enhance debug logging for prompt, agentask arguments, and raw AI response. - Integrate bat for better display of generated PR title and description. - Refine dry-run mode to include git log context for agentask. - Suppress agentask stderr output by default unless --debug is enabled.
- Update sed command to correctly extract content between <github> and </github> tags, including multiline responses. - Ensure the gh_command variable can properly capture and process GitHub commands that span multiple lines within the AI's response.
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.
Summary of Changes
Hello @chicham, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a new foundational AI interaction utility (agentask) and refactors the existing agentpr, agentcommit, and agentissue functions to leverage it. The primary goal is to enhance the generation of structured GitHub pull requests, commit messages, and issues by improving AI model selection, prompt engineering, and crucially, robustly extracting multiline commands from AI responses. Additionally, new Fish shell completions are added to streamline the usage of these tools.
Highlights
- Core AI Agent Utility (
agentask): Introduced a new centralagentaskFish shell function that serves as a flexible wrapper for querying various AI models (Claude, Gemini, OpenAI). It supports command-line queries, piped input for context, model selection, dry-run mode for prompt inspection, and debug output. - Enhanced Pull Request Generation (
agentpr): Theagentprfunction has been significantly enhanced to generate comprehensive GitHub pull requests. It now leveragesagentaskto analyze git commit history and a detailed prompt to create PR titles (following 'Fixes #issue-number:' format) and bodies with structured sections (Summary, Changes Made, Test Plan, Breaking Changes). A key improvement is robustly extracting thegh pr createcommand, including multiline content, from the AI's response. - Improved Commit Message Generation (
agentcommit): Theagentcommitfunction has been refactored to use the newagentaskutility. It generates conventional commit messages by providing staged git changes as context to the AI, and includes robust parsing to extract thegit commitcommand, even when the AI's response contains multiline markdown code blocks. - Streamlined Issue Generation (
agentissue): Theagentissuefunction has also been refactored to utilizeagentaskfor generating comprehensive GitHub issues. It constructs detailed prompts for the AI to create issues with structured sections (Description, Acceptance Criteria, Technical Requirements, Implementation Notes) and reliably extracts thegh issue createcommand from the AI's output, handling multiline content within the command's body argument. - New Fish Shell Completions: New completion files have been added for
agentask,agentcommit,agentissue, andagentpr. These provide intelligent tab completion, including dynamic suggestions for AI agents and models based on user input, significantly improving the user experience for these commands.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request introduces a powerful set of new agent functions and their corresponding completions, which is a fantastic addition. The core logic in agentask is solid and provides a great foundation.
My review focuses on improving the robustness and security of the new scripts. I've identified a couple of critical issues, including a potential command injection vulnerability via printf and a bug that would corrupt multiline commit messages. I've also provided suggestions to improve argument parsing and make the AI response parsing more resilient.
Overall, this is excellent work that will significantly enhance the developer workflow. Addressing these points will make the new tools even more reliable and secure.
| set -l temp_lines $git_command_lines | ||
| set git_command_lines | ||
| printf '%s\n' "$temp_lines" | while read --line line | ||
| set -a git_command_lines $line | ||
| end | ||
| end |
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.
This block of code converts the git_command_lines variable from a multiline string to a list of strings. This is not only unnecessarily complex, but it introduces a critical bug later in the script. At line 195, "$git_command_lines" is used. When git_command_lines is a list, this syntax joins the list elements with spaces, which corrupts any multiline commit message by squashing it into a single line.
| set -l IFS | ||
| set issue_title (printf '%s\n' "$gh_command" | awk -F'--title "' '{if(NF>1){split($2,a,"\""); print a[1]}}') | ||
| set -l raw_body (printf '%s\n' "$gh_command" | awk -F'--body "' '{if(NF>1){split($2,a,"\" --"); print a[1]}}') | ||
| set issue_body (printf "$raw_body") |
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.
| set -l IFS | ||
| set pr_title (printf '%s\n' "$gh_command" | awk -F'--title "' '{if(NF>1){split($2,a,"\""); print a[1]}}') | ||
| set -l raw_body (printf '%s\n' "$gh_command" | awk -F'--body "' '{if(NF>1){split($2,a,"\" --"); print a[1]}}') | ||
| set pr_body (printf "$raw_body") |
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.
| set -l parsing_flags true | ||
| for arg in $argv | ||
| if test "$parsing_flags" = "true" | ||
| switch $arg | ||
| case '-a' '--all_files' | ||
| set _agentissue_all_files true | ||
| case '-d' '--dry-run' | ||
| set _agentissue_dry_run true | ||
| case '-h' '--help' | ||
| set _agentissue_help true | ||
| case '--debug' | ||
| set _agentissue_debug true | ||
| case '-*' | ||
| set -a _agentissue_args $arg | ||
| case '*' | ||
| set parsing_flags false | ||
| set -a _agentissue_description $arg | ||
| end | ||
| else | ||
| set -a _agentissue_description $arg | ||
| end | ||
| end |
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 argument parsing logic is fragile because it stops parsing flags as soon as it encounters a non-flag argument. For example, agentissue "my issue" --debug would fail to recognize the --debug flag, treating it as part of the description. All arguments should be parsed regardless of their position.
| set -l gh_command | ||
| begin | ||
| set -l IFS | ||
| set gh_command (printf '%s\n' "$response" | rg -oP '<github>\K.*?(?=</github>)' | string trim) |
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 ripgrep command used to extract the gh command from between the <github> tags does not handle multiline content correctly. The . in the regex pattern does not match newline characters by default. If the AI returns a formatted, multiline gh command, this parsing will fail.
To fix this, you can add the (?s) single-line/dotall flag to your regex.
set gh_command (printf '%s\n' "$response" | rg -oP '(?s)<github>\K.*?(?=</github>)' | string trim)
| set -g CLAUDE_MODELS "claude-opus-4@20250514" "claude-sonnet-4@20250514" "claude-3-7-sonnet@20250219" "claude-3-5-haiku@20241022" | ||
| set -g GEMINI_MODELS "gemini-2.5-pro" "gemini-2.5-flash" | ||
| set -g OPENAI_MODELS "gpt-4o" "gpt-4" "gpt-3.5-turbo" |
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.
| echo " $gh_command" | ||
|
|
||
| # Clean up global variables | ||
| set -e _agentissue_args _agentissue_description _agentissue_all_files _agentissue_dry_run _agentissue_help |
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 cleanup of global variables at the end of the function is missing _agentissue_debug. This variable will persist in the shell session after the function exits, which can lead to unexpected behavior in subsequent commands.
set -e _agentissue_args _agentissue_description _agentissue_all_files _agentissue_dry_run _agentissue_help _agentissue_debug
| begin | ||
| set -l IFS | ||
| set pr_title (printf '%s\n' "$gh_command" | awk -F'--title "' '{if(NF>1){split($2,a,"\""); print a[1]}}') | ||
| set -l raw_body (printf '%s\n' "$gh_command" | awk -F'--body "' '{if(NF>1){split($2,a,"\" --"); print a[1]}}') |
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.
Summary\nThis pull request introduces enhancements to the
agentprfunctionality, focusing on improving pull request generation and robustly handling multiline GitHub command extraction. It also includes general improvements to other agent scripts and fish functions.\n\n## Changes Made\n-fix(agentpr): Handle multiline GitHub command extraction\n-feat(agentpr): Enhance PR generation with AI model selection\n-refactor(agentissue): Enhance issue generation and UX\n-refactor(agentcommit): Improve script maintainability\n-feat(fish): Enhance agentask and agentcommit functions\n\n## Test Plan\nManual testing of PR generation, AI model selection, and multiline command extraction. Verification ofagentissue,agentcommit, andagentaskfunctionalities.\n\n## Breaking Changes\nNone.