Initial commit
This commit is contained in:
412
skills/ruby-bundler/SKILL.md
Normal file
412
skills/ruby-bundler/SKILL.md
Normal file
@@ -0,0 +1,412 @@
|
||||
# Ruby Bundler Skill
|
||||
|
||||
Intelligent Bundler operations for managing Ruby dependencies.
|
||||
|
||||
## When to Activate
|
||||
|
||||
This skill activates when:
|
||||
- User requests to install gems or dependencies
|
||||
- User mentions Gemfile or bundle commands
|
||||
- User asks about dependency management
|
||||
- Gemfile.lock conflicts detected
|
||||
- Missing gem errors occur
|
||||
|
||||
## Core Capabilities
|
||||
|
||||
### 1. Install Dependencies
|
||||
|
||||
**Basic Installation:**
|
||||
```bash
|
||||
bundle install
|
||||
```
|
||||
|
||||
**Install for specific groups:**
|
||||
```bash
|
||||
# Development and test only
|
||||
bundle install --without production
|
||||
|
||||
# Production only
|
||||
bundle install --deployment
|
||||
```
|
||||
|
||||
**Update Bundler first if needed:**
|
||||
```bash
|
||||
gem install bundler
|
||||
bundle install
|
||||
```
|
||||
|
||||
### 2. Add New Gems
|
||||
|
||||
**Interactive Gem Addition:**
|
||||
|
||||
When user requests: "Add [gem_name] gem"
|
||||
|
||||
1. **Check if gem exists:**
|
||||
- Search RubyGems.org
|
||||
- Show latest version
|
||||
- Show brief description
|
||||
|
||||
2. **Suggest Gemfile entry:**
|
||||
```ruby
|
||||
# For runtime dependency
|
||||
gem 'gem_name', '~> X.Y'
|
||||
|
||||
# For development/test
|
||||
group :development, :test do
|
||||
gem 'gem_name', '~> X.Y'
|
||||
end
|
||||
|
||||
# For test only
|
||||
group :test do
|
||||
gem 'rspec', '~> 3.12'
|
||||
end
|
||||
```
|
||||
|
||||
3. **Add to appropriate group:**
|
||||
- Runtime dependencies → main section
|
||||
- Testing tools → :test group
|
||||
- Development tools → :development group
|
||||
- Code quality → :development (rubocop, etc.)
|
||||
|
||||
4. **Install the gem:**
|
||||
```bash
|
||||
bundle install
|
||||
```
|
||||
|
||||
5. **Verify installation:**
|
||||
```bash
|
||||
bundle list | grep gem_name
|
||||
```
|
||||
|
||||
### 3. Update Dependencies
|
||||
|
||||
**Update all gems:**
|
||||
```bash
|
||||
bundle update
|
||||
```
|
||||
|
||||
**Update specific gem:**
|
||||
```bash
|
||||
bundle update gem_name
|
||||
```
|
||||
|
||||
**Update conservatively (patch versions only):**
|
||||
```bash
|
||||
bundle update --patch
|
||||
```
|
||||
|
||||
**Update minor versions:**
|
||||
```bash
|
||||
bundle update --minor
|
||||
```
|
||||
|
||||
### 4. Audit for Security
|
||||
|
||||
**Check for vulnerabilities:**
|
||||
```bash
|
||||
bundle audit
|
||||
```
|
||||
|
||||
**Install bundler-audit if missing:**
|
||||
```bash
|
||||
gem install bundler-audit
|
||||
bundle audit
|
||||
```
|
||||
|
||||
**Update vulnerable gems:**
|
||||
```bash
|
||||
bundle audit check --update
|
||||
```
|
||||
|
||||
### 5. Clean Up
|
||||
|
||||
**Remove unused gems:**
|
||||
```bash
|
||||
bundle clean
|
||||
```
|
||||
|
||||
**Clean with forced removal:**
|
||||
```bash
|
||||
bundle clean --force
|
||||
```
|
||||
|
||||
### 6. Troubleshoot Issues
|
||||
|
||||
**Common Issues & Solutions:**
|
||||
|
||||
**Issue: "Could not find gem 'X'"**
|
||||
```bash
|
||||
# Solution 1: Update bundler
|
||||
gem install bundler
|
||||
bundle install
|
||||
|
||||
# Solution 2: Clear cache
|
||||
bundle clean --force
|
||||
bundle install
|
||||
|
||||
# Solution 3: Update Gemfile.lock
|
||||
rm Gemfile.lock
|
||||
bundle install
|
||||
```
|
||||
|
||||
**Issue: Version conflicts**
|
||||
```bash
|
||||
# Show dependency tree
|
||||
bundle viz --without production
|
||||
|
||||
# Or use bundle info
|
||||
bundle info gem_name
|
||||
```
|
||||
|
||||
**Issue: Platform-specific gems**
|
||||
```ruby
|
||||
# In Gemfile
|
||||
gem 'pg', platforms: :ruby
|
||||
gem 'sqlite3', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
||||
```
|
||||
|
||||
### 7. Gem Information
|
||||
|
||||
**Show gem details:**
|
||||
```bash
|
||||
bundle info gem_name
|
||||
```
|
||||
|
||||
**List all gems:**
|
||||
```bash
|
||||
bundle list
|
||||
```
|
||||
|
||||
**Show outdated gems:**
|
||||
```bash
|
||||
bundle outdated
|
||||
```
|
||||
|
||||
## Interactive Workflows
|
||||
|
||||
### Workflow 1: Add New Gem
|
||||
|
||||
**User Request:** "Add pry-byebug for debugging"
|
||||
|
||||
**Response:**
|
||||
```
|
||||
I'll add pry-byebug to your Gemfile.
|
||||
|
||||
Gem: pry-byebug
|
||||
Latest Version: 3.10.1
|
||||
Description: Combines pry with byebug for debugging
|
||||
|
||||
This is a development tool, so I'll add it to the :development group.
|
||||
|
||||
Adding to Gemfile:
|
||||
```ruby
|
||||
group :development do
|
||||
gem 'pry-byebug', '~> 3.10'
|
||||
end
|
||||
```
|
||||
|
||||
Running bundle install...
|
||||
✓ Successfully installed pry-byebug 3.10.1
|
||||
|
||||
You can now use it by adding `binding.pry` in your code.
|
||||
```
|
||||
|
||||
### Workflow 2: Update Dependencies
|
||||
|
||||
**User Request:** "Update all my gems"
|
||||
|
||||
**Response:**
|
||||
```
|
||||
Before updating, let me check what's outdated:
|
||||
|
||||
Outdated gems:
|
||||
- rspec: 3.11.0 → 3.12.0 (minor update)
|
||||
- rubocop: 1.45.1 → 1.50.2 (minor update)
|
||||
- nokogiri: 1.14.2 → 1.14.3 (patch update)
|
||||
|
||||
Recommendation:
|
||||
1. Update patch versions first (safest): bundle update --patch
|
||||
2. Update minor versions: bundle update --minor
|
||||
3. Update all: bundle update
|
||||
|
||||
Would you like me to:
|
||||
a) Update patch versions only (safest)
|
||||
b) Update minor versions
|
||||
c) Update everything
|
||||
d) Update specific gems only
|
||||
```
|
||||
|
||||
### Workflow 3: Security Audit
|
||||
|
||||
**User Request:** "Check for security issues"
|
||||
|
||||
**Response:**
|
||||
```
|
||||
Running security audit with bundler-audit...
|
||||
|
||||
Found 2 vulnerabilities:
|
||||
|
||||
1. HIGH: CVE-2023-XXXX in nokogiri (1.14.2)
|
||||
Solution: Update to >= 1.14.3
|
||||
|
||||
2. MEDIUM: CVE-2023-YYYY in rack (2.2.6)
|
||||
Solution: Update to >= 2.2.7
|
||||
|
||||
Recommended action:
|
||||
bundle update nokogiri rack
|
||||
|
||||
Would you like me to update these gems now?
|
||||
```
|
||||
|
||||
## Smart Suggestions
|
||||
|
||||
### Suggest Missing Gems
|
||||
|
||||
When user writes code using common patterns, suggest relevant gems:
|
||||
|
||||
**Pattern: API calls**
|
||||
```ruby
|
||||
# User writes HTTP client code
|
||||
"I notice you're making HTTP requests. Consider adding:"
|
||||
gem 'faraday', '~> 2.7' # Modern HTTP client
|
||||
# or
|
||||
gem 'httparty', '~> 0.21' # Simple HTTP client
|
||||
```
|
||||
|
||||
**Pattern: JSON parsing**
|
||||
```ruby
|
||||
# User parses JSON
|
||||
"For better JSON handling, consider:"
|
||||
gem 'oj', '~> 3.14' # Faster JSON parser
|
||||
```
|
||||
|
||||
**Pattern: Environment variables**
|
||||
```ruby
|
||||
# User uses ENV[]
|
||||
"For environment management, you already have dotenv in common libs!"
|
||||
gem 'dotenv', '~> 2.8'
|
||||
```
|
||||
|
||||
**Pattern: Background jobs**
|
||||
```ruby
|
||||
# User mentions async/background processing
|
||||
"For background jobs, you commonly use:"
|
||||
gem 'sidekiq', '~> 7.0'
|
||||
```
|
||||
|
||||
## Version Constraint Guidelines
|
||||
|
||||
**Pessimistic versioning (~>):**
|
||||
```ruby
|
||||
gem 'rails', '~> 7.0.4' # >= 7.0.4, < 7.1
|
||||
gem 'rspec', '~> 3.12' # >= 3.12, < 4.0
|
||||
```
|
||||
|
||||
**Exact version (avoid unless necessary):**
|
||||
```ruby
|
||||
gem 'specific_gem', '1.2.3' # Only 1.2.3
|
||||
```
|
||||
|
||||
**Greater than or equal:**
|
||||
```ruby
|
||||
gem 'compatible_gem', '>= 2.0' # Any version >= 2.0
|
||||
```
|
||||
|
||||
**Best Practice:** Use pessimistic (~>) for stability
|
||||
|
||||
## Gemfile Organization
|
||||
|
||||
**Recommended Structure:**
|
||||
```ruby
|
||||
source 'https://rubygems.org'
|
||||
|
||||
ruby '3.2.0' # Specify Ruby version
|
||||
|
||||
# Core runtime dependencies
|
||||
gem 'dotenv'
|
||||
gem 'pg', '~> 1.6'
|
||||
|
||||
# Development tools
|
||||
group :development do
|
||||
gem 'pry'
|
||||
gem 'rubocop', require: false
|
||||
end
|
||||
|
||||
# Test tools
|
||||
group :test do
|
||||
gem 'rspec', '~> 3.12'
|
||||
gem 'factory_bot', '~> 6.5'
|
||||
gem 'timecop'
|
||||
end
|
||||
|
||||
# Development & Test
|
||||
group :development, :test do
|
||||
gem 'pry-byebug'
|
||||
end
|
||||
|
||||
# Platform-specific
|
||||
platforms :ruby do
|
||||
gem 'sqlite3', '~> 2.1'
|
||||
end
|
||||
```
|
||||
|
||||
## Response Format
|
||||
|
||||
When performing bundle operations:
|
||||
|
||||
**Action Taken:**
|
||||
- Command executed
|
||||
- Result summary
|
||||
|
||||
**Changes:**
|
||||
- New gems added
|
||||
- Gems updated (old → new version)
|
||||
- Gems removed
|
||||
|
||||
**Next Steps:**
|
||||
- Suggested actions
|
||||
- Related configuration needed
|
||||
- Documentation references
|
||||
|
||||
## Configuration
|
||||
|
||||
Users can customize behavior in `.claude/settings.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": {
|
||||
"rubyist": {
|
||||
"bundler": {
|
||||
"autoInstall": true,
|
||||
"suggestGems": true,
|
||||
"securityAudit": true,
|
||||
"versionStrategy": "pessimistic"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
Always wrap bundle commands with error handling:
|
||||
|
||||
```bash
|
||||
if bundle install; then
|
||||
echo "✓ Successfully installed dependencies"
|
||||
else
|
||||
echo "✗ Installation failed"
|
||||
echo "Trying with bundle update..."
|
||||
bundle update
|
||||
fi
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
1. **Always review Gemfile changes** before committing
|
||||
2. **Commit Gemfile.lock** to ensure consistent environments
|
||||
3. **Use bundle audit regularly** for security
|
||||
4. **Keep gems updated** but test thoroughly
|
||||
5. **Group gems appropriately** (development, test, production)
|
||||
6. **Use pessimistic versioning** for stability
|
||||
7. **Document why** specific versions are pinned
|
||||
98
skills/ruby-bundler/scripts/README.md
Normal file
98
skills/ruby-bundler/scripts/README.md
Normal file
@@ -0,0 +1,98 @@
|
||||
# Bundler Utility Scripts
|
||||
|
||||
Executable shell scripts for common Bundler operations.
|
||||
|
||||
## Scripts
|
||||
|
||||
### bundle_install.sh
|
||||
Install Ruby dependencies with error handling.
|
||||
|
||||
```bash
|
||||
# Basic install
|
||||
./bundle_install.sh
|
||||
|
||||
# Install with options
|
||||
./bundle_install.sh --without production
|
||||
|
||||
# Install for deployment
|
||||
./bundle_install.sh --deployment
|
||||
```
|
||||
|
||||
**Features:**
|
||||
- Checks for Gemfile existence
|
||||
- Auto-installs bundler if missing
|
||||
- Shows helpful error messages
|
||||
- Lists installed gems
|
||||
|
||||
### bundle_add.sh
|
||||
Add a gem to Gemfile and install it.
|
||||
|
||||
```bash
|
||||
# Add to main section
|
||||
./bundle_add.sh pry-byebug '~> 3.10'
|
||||
|
||||
# Add to development group
|
||||
./bundle_add.sh rubocop '~> 1.50' --group=development
|
||||
|
||||
# Add to test group
|
||||
./bundle_add.sh rspec --group=test
|
||||
```
|
||||
|
||||
**Features:**
|
||||
- Automatically detects/creates gem groups
|
||||
- Adds version constraints
|
||||
- Runs bundle install
|
||||
- Shows gem info after install
|
||||
|
||||
### bundle_update.sh
|
||||
Update gems with safety levels.
|
||||
|
||||
```bash
|
||||
# Show outdated gems (no changes)
|
||||
./bundle_update.sh conservative
|
||||
|
||||
# Update patch versions only (safest)
|
||||
./bundle_update.sh patch
|
||||
|
||||
# Update minor versions
|
||||
./bundle_update.sh minor
|
||||
|
||||
# Update all gems
|
||||
./bundle_update.sh all
|
||||
|
||||
# Update specific gem
|
||||
./bundle_update.sh nokogiri
|
||||
```
|
||||
|
||||
**Features:**
|
||||
- Multiple safety modes
|
||||
- Shows git diff of Gemfile.lock changes
|
||||
- Conservative default (shows outdated only)
|
||||
|
||||
### bundle_audit.sh
|
||||
Security audit for dependencies.
|
||||
|
||||
```bash
|
||||
./bundle_audit.sh
|
||||
```
|
||||
|
||||
**Features:**
|
||||
- Auto-installs bundler-audit if needed
|
||||
- Updates vulnerability database
|
||||
- Shows vulnerabilities with fix suggestions
|
||||
- Returns non-zero exit code if vulnerabilities found
|
||||
|
||||
## Usage in Skills
|
||||
|
||||
These scripts can be called by the ruby-bundler skill:
|
||||
|
||||
```ruby
|
||||
# From skill
|
||||
system("#{PLUGIN_DIR}/skills/ruby-bundler/scripts/bundle_install.sh")
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
- Ruby installed
|
||||
- Git (for bundle_update.sh diff)
|
||||
- bundler gem (auto-installed if missing)
|
||||
69
skills/ruby-bundler/scripts/bundle_add.sh
Executable file
69
skills/ruby-bundler/scripts/bundle_add.sh
Executable file
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env bash
|
||||
# Add a gem to Gemfile and install it
|
||||
|
||||
set -e
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "Usage: $0 <gem_name> [version] [--group=GROUP]"
|
||||
echo "Example: $0 pry-byebug '~> 3.10' --group=development"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
GEM_NAME=$1
|
||||
VERSION=${2:-}
|
||||
GROUP=""
|
||||
|
||||
# Parse group argument
|
||||
for arg in "$@"; do
|
||||
if [[ $arg == --group=* ]]; then
|
||||
GROUP="${arg#*=}"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "📦 Adding gem: $GEM_NAME"
|
||||
|
||||
# Check if Gemfile exists
|
||||
if [ ! -f "Gemfile" ]; then
|
||||
echo "❌ Error: No Gemfile found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Determine gem line to add
|
||||
if [ -n "$VERSION" ] && [[ ! $VERSION == --* ]]; then
|
||||
GEM_LINE="gem '$GEM_NAME', '$VERSION'"
|
||||
else
|
||||
GEM_LINE="gem '$GEM_NAME'"
|
||||
fi
|
||||
|
||||
# Add to appropriate group
|
||||
if [ -n "$GROUP" ]; then
|
||||
echo "Adding to group: $GROUP"
|
||||
|
||||
# Check if group exists
|
||||
if grep -q "group :$GROUP do" Gemfile; then
|
||||
# Add to existing group (before the 'end')
|
||||
sed -i.bak "/group :$GROUP do/a\\
|
||||
$GEM_LINE
|
||||
" Gemfile && rm Gemfile.bak
|
||||
else
|
||||
# Create new group at end of file
|
||||
echo "" >> Gemfile
|
||||
echo "group :$GROUP do" >> Gemfile
|
||||
echo " $GEM_LINE" >> Gemfile
|
||||
echo "end" >> Gemfile
|
||||
fi
|
||||
else
|
||||
# Add to main section (after source line)
|
||||
sed -i.bak "/^source /a\\
|
||||
$GEM_LINE
|
||||
" Gemfile && rm Gemfile.bak
|
||||
fi
|
||||
|
||||
echo "✅ Added to Gemfile"
|
||||
echo ""
|
||||
echo "Running bundle install..."
|
||||
bundle install
|
||||
|
||||
echo ""
|
||||
echo "✅ Gem installed successfully"
|
||||
bundle info "$GEM_NAME"
|
||||
32
skills/ruby-bundler/scripts/bundle_audit.sh
Executable file
32
skills/ruby-bundler/scripts/bundle_audit.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
# Security audit for Ruby dependencies
|
||||
|
||||
set -e
|
||||
|
||||
echo "🔒 Running security audit..."
|
||||
|
||||
# Check if bundler-audit is installed
|
||||
if ! gem list bundler-audit -i &> /dev/null; then
|
||||
echo "📦 Installing bundler-audit..."
|
||||
gem install bundler-audit
|
||||
bundle audit --update
|
||||
fi
|
||||
|
||||
# Update vulnerability database
|
||||
echo "Updating vulnerability database..."
|
||||
bundle audit --update
|
||||
|
||||
# Run audit
|
||||
echo ""
|
||||
echo "Checking for vulnerabilities..."
|
||||
if bundle audit check; then
|
||||
echo ""
|
||||
echo "✅ No vulnerabilities found!"
|
||||
else
|
||||
echo ""
|
||||
echo "❌ Vulnerabilities detected!"
|
||||
echo ""
|
||||
echo "To fix, run:"
|
||||
echo " bundle update <gem_name>"
|
||||
exit 1
|
||||
fi
|
||||
39
skills/ruby-bundler/scripts/bundle_install.sh
Executable file
39
skills/ruby-bundler/scripts/bundle_install.sh
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
# Bundle install with error handling and helpful output
|
||||
|
||||
set -e
|
||||
|
||||
echo "📦 Installing Ruby dependencies..."
|
||||
|
||||
# Check if Gemfile exists
|
||||
if [ ! -f "Gemfile" ]; then
|
||||
echo "❌ Error: No Gemfile found in current directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if bundler is installed
|
||||
if ! command -v bundle &> /dev/null; then
|
||||
echo "⚠️ Bundler not found. Installing bundler..."
|
||||
gem install bundler
|
||||
fi
|
||||
|
||||
# Show bundler version
|
||||
echo "Using bundler version: $(bundle --version)"
|
||||
|
||||
# Run bundle install with options
|
||||
if bundle install "$@"; then
|
||||
echo "✅ Dependencies installed successfully"
|
||||
echo ""
|
||||
echo "Installed gems:"
|
||||
bundle list --name-only | head -10
|
||||
total=$(bundle list --name-only | wc -l)
|
||||
echo "... and $(($total - 10)) more gems"
|
||||
else
|
||||
echo "❌ Bundle install failed"
|
||||
echo ""
|
||||
echo "Troubleshooting steps:"
|
||||
echo "1. Try: rm Gemfile.lock && bundle install"
|
||||
echo "2. Update bundler: gem install bundler"
|
||||
echo "3. Check Ruby version: ruby --version"
|
||||
exit 1
|
||||
fi
|
||||
40
skills/ruby-bundler/scripts/bundle_update.sh
Executable file
40
skills/ruby-bundler/scripts/bundle_update.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
# Update gems with safety options
|
||||
|
||||
set -e
|
||||
|
||||
MODE=${1:-conservative}
|
||||
|
||||
echo "📦 Updating Ruby gems (mode: $MODE)..."
|
||||
|
||||
case "$MODE" in
|
||||
patch)
|
||||
echo "Updating patch versions only (safest)"
|
||||
bundle update --patch
|
||||
;;
|
||||
minor)
|
||||
echo "Updating minor versions"
|
||||
bundle update --minor
|
||||
;;
|
||||
conservative)
|
||||
echo "Showing outdated gems first..."
|
||||
bundle outdated
|
||||
echo ""
|
||||
echo "Run with 'patch' or 'minor' or 'all' to update"
|
||||
exit 0
|
||||
;;
|
||||
all)
|
||||
echo "⚠️ Updating all gems (use with caution)"
|
||||
bundle update
|
||||
;;
|
||||
*)
|
||||
echo "Updating specific gem: $MODE"
|
||||
bundle update "$MODE"
|
||||
;;
|
||||
esac
|
||||
|
||||
echo ""
|
||||
echo "✅ Update complete"
|
||||
echo ""
|
||||
echo "Changes:"
|
||||
git diff Gemfile.lock 2>/dev/null || echo "No git repository found"
|
||||
Reference in New Issue
Block a user