You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds an AI-powered Bash assistant using OpenRouter API. Provides commands, explanations, and error suggestions.
Features:
Trigger using pgi "your query"
Only runs on demand (doesn’t slow shell)
Requires API key via AI_PROMPTGEN_API_KEY in .bashrc
PR Type
Enhancement
Description
Add new promptgenai plugin for AI-powered Bash assistance
Implement pgi command with OpenRouter API integration
Include error handling and JSON response parsing
Require API key configuration via environment variable
Diagram Walkthrough
flowchart LR
A["User Query"] --> B["pgi command"]
B --> C["API Key Check"]
C --> D["OpenRouter API Call"]
D --> E["JSON Response Parsing"]
E --> F["Command/Explanation Output"]
Loading
File Walkthrough
Relevant files
Enhancement
promptgenai.plugin.sh
New AI-powered Bash assistant plugin
plugins/promptgenai/promptgenai.plugin.sh
Create new plugin with pgi function for AI assistance
Implement OpenRouter API integration with Mixtral model
Add input validation and error handling
Include JSON response parsing with fallback error display
Here are some key observations to aid the review process:
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 Security concerns
Sensitive information exposure: The API key is passed directly in the curl command arguments, making it visible in process lists (ps aux) and potentially logged in shell history or system logs. Additionally, the input sanitization only escapes double quotes but doesn't handle other JSON-breaking characters, which could potentially lead to JSON injection if malicious input is provided.
The API key is exposed in the curl command through process arguments, making it visible in process lists and potentially logged in shell history or system logs.
local response=$(curl -s https://openrouter.ai/api/v1/chat/completions \ -H "Authorization: Bearer $AI_PROMPTGEN_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "mistralai/mixtral-8x7b-instruct", "messages": [ { "role": "system", "content": "You are a bash expert. Reply with commands and explanations. Provide only relevant and copyable command blocks where applicable." }, { "role": "user", "content": "'"${query//\"/\\\"}"'" } ] }')
The query parameter escaping on line 28 only handles double quotes but may not properly handle other special characters that could break the JSON structure or cause injection issues.
The curl command lacks proper error handling and timeout configuration. Network failures or API timeouts could cause the function to hang indefinitely or fail silently.
-local response=$(curl -s https://openrouter.ai/api/v1/chat/completions \+local response=$(curl -s --max-time 30 --fail https://openrouter.ai/api/v1/chat/completions \
-H "Authorization: Bearer $AI_PROMPTGEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "mistralai/mixtral-8x7b-instruct",
"messages": [
{
"role": "system",
"content": "You are a bash expert. Reply with commands and explanations. Provide only relevant and copyable command blocks where applicable."
},
{
"role": "user",
"content": "'"${query//\"/\\\"}"'"
}
]
}')
+if [[ $? -ne 0 ]]; then+ echo "❌ Failed to connect to API"+ return 1+fi+
Apply / Chat
Suggestion importance[1-10]: 7
__
Why: The suggestion correctly points out that the curl command could hang indefinitely and proposes adding a timeout and failure flag, which significantly improves the script's robustness.
Medium
Check jq availability before use
The function should check if jq is available before using it. If jq is not installed, the function will fail with an unclear error message.
-if echo "$response" | jq -e '.choices[0].message.content' > /dev/null; then- echo "$response" | jq -r '.choices[0].message.content'+if command -v jq >/dev/null 2>&1; then+ if echo "$response" | jq -e '.choices[0].message.content' > /dev/null; then+ echo "$response" | jq -r '.choices[0].message.content'+ else+ echo "⚠️ Something went wrong."+ echo "Raw response:"+ echo "$response"+ fi
else
- echo "⚠️ Something went wrong."- echo "Raw response:"- echo "$response"+ echo "❌ jq is required but not installed"+ return 1
fi
Apply / Chat
Suggestion importance[1-10]: 6
__
Why: This is a good suggestion for improving user experience by checking for the jq dependency and providing a clear error message if it's not installed, preventing a cryptic command failure.
Low
Improve JSON string escaping
The JSON escaping only handles double quotes but ignores other special characters like newlines, backslashes, and control characters that could break the JSON structure.
Why: The suggestion correctly identifies that the current JSON escaping is incomplete and could fail with special characters, but the proposed sed solution is overly complex and potentially incorrect.
Low
More
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
New Plugin: promptgenai
Adds an AI-powered Bash assistant using OpenRouter API. Provides commands, explanations, and error suggestions.
Features:
pgi "your query"AI_PROMPTGEN_API_KEYin.bashrcPR Type
Enhancement
Description
Add new
promptgenaiplugin for AI-powered Bash assistanceImplement
pgicommand with OpenRouter API integrationInclude error handling and JSON response parsing
Require API key configuration via environment variable
Diagram Walkthrough
File Walkthrough
promptgenai.plugin.sh
New AI-powered Bash assistant pluginplugins/promptgenai/promptgenai.plugin.sh
pgifunction for AI assistance