-
Notifications
You must be signed in to change notification settings - Fork 0
Fixes #<issue-number>: Enhance agentpr with multiline command extraction and AI model selection #10
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.
- Modify `agentcommit.fish` to include `--edit -m` flag for `git commit` command, allowing users to edit the commit message in an editor before committing. - Update `agentissue.fish` to include `--editor` flag for `gh issue create` command, enabling in-editor editing of issue details. - Enhance `agentpr.fish` to include `--editor` flag for `gh pr create` command, facilitating in-editor editing of pull request details. - Improve `agentpr.fish` to correctly display newlines in the pull request body when extracted from the `gh` command.
- Simplified AI agent's commit message output format to be just the message text, removing the `git commit -m ...` wrapper and markdown code blocks. - Updated internal parsing logic to directly handle the plain commit message text. - Clarified and refined commit message formatting instructions for the AI agent. - Adjusted dry-run response to align with the new output format.
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 enhances the agentpr toolset by adding the ability to select specific AI models for generating pull requests and fixing an issue where multiline GitHub commands were not correctly extracted. It also introduces fish shell completions for all the agent commands, improving usability.
Highlights
- AI Model Selection: The
agentaskfunction now supports specifying the AI agent and model to use via command-line arguments (--agentand-m/--model). This allows users to choose between Claude, Gemini, and OpenAI models. - Multiline Command Extraction: The
agentprfunction now correctly extracts multilineghcommands from the AI agent's response, ensuring that complex pull request descriptions are properly handled. - Completions: Added fish shell completions for
agentask,agentcommit,agentissue, andagentprto improve the user experience. - Agentask Functionality: The
agentaskfunction now includes helper functions to get available agents and models, and validates the agent and model selections.
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 suite of fish shell functions (agentask, agentcommit, agentissue, agentpr) that wrap AI agents to automate development tasks. The changes add support for selecting AI models and improve multiline input handling.
My review focuses on enhancing the maintainability, correctness, and robustness of these new scripts. Key feedback includes fixing a critical command injection vulnerability, resolving global variable leaks, and improving the parsing of AI-generated output. The overall implementation is strong, and with these changes, the new tools will be more reliable and easier to maintain.
| printf '%s\n' "$commit_message" | bat --language markdown --style plain --paging never | ||
|
|
||
| # Create git command with --edit flag and copy to clipboard | ||
| set -l git_command_with_editor "git commit --edit -m \"$commit_message\"" |
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 construction of the git commit command is unsafe. If the $commit_message variable contains special characters, particularly double quotes, it will break the command string and cause a syntax error when the user pastes it into their terminal.
To fix this, you should use string escape to ensure the commit message is safely embedded within the command string. This will correctly quote and escape the message as needed.
set -l git_command_with_editor "git commit --edit -m (string escape -- \"$commit_message\")"
| printf '%s\n' "$git_command_with_editor" | pbcopy | ||
| echo "📋 Commit command copied to clipboard" | ||
| 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 _agentcommit_parse_args function defines global variables (_agentcommit_args, _agentcommit_dry_run, _agentcommit_help) which are not cleaned up on the normal execution path. This pollutes the global shell environment and can lead to unexpected behavior in subsequent commands.
You should erase these variables at the end of the function to ensure a clean state, just as you do in the --help path.
printf '%s\n' "$git_command_with_editor" | pbcopy
echo "📋 Commit command copied to clipboard"
# Clean up global variables
set -e _agentcommit_args _agentcommit_dry_run _agentcommit_help
| begin | ||
| set -l IFS | ||
| set gh_command (printf '%s\n' "$response" | rg -oP '<github>\K.*?(?=</github>)' | string trim) | ||
| 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 ripgrep command used here to extract the gh command is not robust for multiline content within the <github> tags. rg processes input line-by-line by default, and the regex .*? will not match across newlines. If the AI formats the gh command across multiple lines, this extraction will fail.
The agentpr.fish script uses a more robust sed-based approach for this. You should adopt the same method here for consistency and correctness.
begin
set -l IFS
# Extract content between <github> and </github> tags, handling multiline content
set gh_command (printf '%s\n' "$response" | sed -n '/<github>/,/\<\/github>/p' | sed '1s/<github>//; $s/\<\/github>//' | string join '\n' | string trim)
end
| echo " $gh_command_with_editor" | ||
|
|
||
| # 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 is incomplete. The _agentissue_debug variable, set in _agentissue_parse_args, is not being erased at the end of the function's successful execution path. This pollutes the global scope and could affect subsequent command executions.
set -e _agentissue_args _agentissue_description _agentissue_all_files _agentissue_dry_run _agentissue_help _agentissue_debug
- Refactor `agentissue.fish` and `agentpr.fish` to parse structured AI responses for GitHub issue and pull request fields. - Transition from extracting a `gh` command string within `<github>` tags to directly parsing `TITLE`, `BODY`, and other specific fields. - Enhance robustness and control over generated GitHub commands by reconstructing them from individual parsed fields. - Update debug output to display extracted fields for better troubleshooting. - Adjust `bat` paging to `never` for displaying issue/PR information.
Summary
This pull request enhances the
agentprfunctionality by adding support for multiline GitHub command extraction and allowing the selection of an AI model for PR generation.Changes Made
feat(agentpr): Enhance PR generation with AI model selection: Implemented the ability to choose an AI model when generating pull requests.fix(agentpr): Handle multiline GitHub command extraction: Fixed an issue where multiline GitHub commands were not correctly extracted.Test Plan
Manual testing is required to verify:
Breaking Changes
None.