examples - MadBomber/aia GitHub Wiki

Examples

This page provides practical examples of how to use AIA for various tasks and workflows.

Quick Start Examples

Simple Question Prompt

# Create a basic question prompt
echo "What is [TOPIC]?" > ~/.prompts/ask.txt

# Use the prompt
aia ask
# You'll be prompted to enter a value for TOPIC

Interactive Chat

# Start a basic chat session
aia --chat

# Chat with a specific role
aia --chat --role expert

# Chat with tools enabled
aia --chat --tools shared

Practical Prompt Examples

Code Review Prompt

# ~/.prompts/code_review.txt
//config model = gpt-4
//config temperature = 0.3

Review this code for:
- Best practices adherence
- Security vulnerabilities
- Performance issues
- Maintainability concerns

Code to review:
//include [CODE_FILE]

Usage: aia code_review mycode.rb

Meeting Notes Processor

# ~/.prompts/meeting_notes.txt
//config model = gpt-4o-mini
//pipeline format,action_items

Raw meeting notes:
//include [NOTES_FILE]

Please clean up and structure these meeting notes.

Documentation Generator

# ~/.prompts/document.txt
//config model = gpt-4
//shell find [PROJECT_DIR] -name "*.rb" | head -10

Generate documentation for the Ruby project shown above.
Include: API references, usage examples, and setup instructions.

System Analysis Helper

# ~/.prompts/system_check.txt
//config model = gpt-4o-mini

As a system administrator on a $(uname -s) platform, analyze this system:

Current system info: $(uname -a)
System load: $(uptime)
Disk usage: $(df -h | head -5)
Memory info: $(free -h)

Please provide insights on: [ANALYSIS_FOCUS]

Workflow Examples

Prompt Sequences with --next

# Command line chaining
aia analyze --next summarize --next report

# Or define in prompt files:
# analyze.txt contains: //next summarize
# summarize.txt contains: //next report

Pipeline Workflows with --pipeline

# Command line pipeline
aia research --pipeline analyze,summarize,report,present

# Or in prompt file:
//pipeline analyze,summarize,report,present

Research Workflow Example

Create these connected prompts:

research.txt:

//config model = gpt-4
//next analyze

Research the topic: [RESEARCH_TOPIC]
Provide comprehensive background information.

analyze.txt:

//config out_file = analysis.md
//next summarize

Analyze the research data and identify key insights.

summarize.txt:

//config out_file = summary.md

Create a concise summary of the analysis with actionable recommendations.

Usage: aia research

Executable Prompts

Weather Report Script

#!/usr/bin/env aia run --no-out_file
# Get current weather for a city

What's the current weather in [CITY]?
Include temperature, conditions, and 3-day forecast.
Format as a brief, readable summary.

Make executable and use:

chmod +x weather_report
./weather_report
./weather_report | glow  # Render with glow

Daily Standup Generator

#!/usr/bin/env aia run
# File: daily_standup

<% require 'date' %>
Daily standup for <%= Date.today.strftime('%B %d, %Y') %>

<% if Date.today.monday? %>
Focus areas: Week planning and goal setting
<% elsif Date.today.friday? %>
Focus areas: Week wrap-up and reflection
<% end %>

Current time: <%= Time.now.strftime('%I:%M %p') %>

Help me structure my standup around: [DAILY_FOCUS]

Advanced ERB Examples

Conditional Content

# ~/.prompts/env_specific.txt
<% if ENV['USER'] == 'admin' %>
You have admin privileges. Consider security implications.
<% else %>
You have standard user privileges.
<% end %>

Current working directory: <%= Dir.pwd %>
Available environment: <%= ENV.keys.grep(/AIA/).join(', ') %>

Please help with: [TASK]

Dynamic Configuration

# ~/.prompts/smart_config.txt
<% 
  # Automatically adjust model based on task complexity
  if prompt_text.include?('complex') || prompt_text.include?('detailed')
    model = 'gpt-4'
    temp = 0.8
  else
    model = 'gpt-4o-mini' 
    temp = 0.5
  end
%>

//config model = <%= model %>
//config temperature = <%= temp %>

Task to handle: [TASK_DESCRIPTION]

Tool Integration Examples

Using Shared Tools

# Start chat with all shared tools
aia --chat --tools shared

# Use specific tools only
aia --chat --tools shared --allowed_tools read_file,write_file,run_shell_command

# Combine shared tools with custom tools
aia --chat --tools shared,~/my-tools/

Custom Tool Development

# ~/.prompts/tools/text_analyzer.rb
require 'ruby_llm/tool'

module Tools
  class TextAnalyzer < RubyLLM::Tool
    description "Analyze text for word count, readability, and sentiment"
    param :text, desc: "Text to analyze"
    param :analysis_type, desc: "Type of analysis: 'basic', 'readability', 'sentiment'"

    def execute(text:, analysis_type: 'basic')
      words = text.split
      sentences = text.split(/[.!?]+/)
      
      result = {
        word_count: words.length,
        sentence_count: sentences.length,
        character_count: text.length,
        avg_words_per_sentence: words.length.to_f / sentences.length
      }

      case analysis_type
      when 'readability'
        result[:readability_score] = calculate_flesch_score(text)
      when 'sentiment'
        result[:sentiment] = analyze_sentiment(text)
      end

      result
    rescue => e
      { error: e.message }
    end

    private

    def calculate_flesch_score(text)
      # Simplified Flesch reading ease calculation
      words = text.split.length
      sentences = text.split(/[.!?]+/).length
      syllables = count_syllables(text)
      
      206.835 - (1.015 * words / sentences) - (84.6 * syllables / words)
    end

    def count_syllables(text)
      # Simplified syllable counting
      text.downcase.scan(/[aeiouy]+/).length
    end

    def analyze_sentiment(text)
      positive_words = %w[good great excellent amazing wonderful fantastic]
      negative_words = %w[bad terrible awful horrible disappointing]
      
      positive_count = positive_words.count { |word| text.downcase.include?(word) }
      negative_count = negative_words.count { |word| text.downcase.include?(word) }
      
      if positive_count > negative_count
        'positive'
      elsif negative_count > positive_count
        'negative'
      else
        'neutral'
      end
    end
  end
end

Specialized Workflows

Blog Post Creation Pipeline

# ~/.prompts/blog_post.txt
//config model = gpt-4
//pipeline outline,write,edit,format

Create a blog post about: [TOPIC]

Target audience: [AUDIENCE]
Desired length: [LENGTH]
Key points to cover: [KEY_POINTS]

Create supporting prompts:

  • outline.txt - Creates blog post structure
  • write.txt - Writes full content
  • edit.txt - Edits and improves
  • format.txt - Final formatting

Code Analysis Suite

# ~/.prompts/code_analysis.txt
//config model = gpt-4
//pipeline security_check,performance_review,style_check,documentation_check

//include [CODE_FILE]

Perform comprehensive code analysis on the above file.

Project Documentation Generator

# ~/.prompts/doc_generator.txt
//config model = gpt-4
//config out_file = project_docs.md

Project structure:
//shell find [PROJECT_DIR] -type f -name "*.rb" -o -name "*.md" -o -name "*.yml" | head -20

README content:
//include [PROJECT_DIR]/README.md

Generate comprehensive project documentation including:
- Project overview and purpose
- Installation and setup instructions
- API documentation with examples
- Configuration options
- Usage patterns and best practices
- Troubleshooting guide

Tips from the Author

Most Versatile Prompt

# ~/.prompts/ad_hoc.txt
[WHAT_NOW_HUMAN]

Perfect for any quick question without cluttering shell history:

aia ad_hoc

Recommended Shell Setup

# ~/.bashrc_aia
export AIA_PROMPTS_DIR=~/.prompts
export AIA_OUT_FILE=./temp.md
export AIA_MODEL=gpt-4o-mini
export AIA_VERBOSE=true  # Shows spinner while waiting

alias chat='aia --chat --terse'
alias ask='aia ad_hoc'
alias review='aia code_review'
alias doc='aia document'

Prompt Organization Strategy

~/.prompts/
├── daily/           # Daily workflow prompts
│   ├── standup.txt
│   ├── planning.txt
│   └── review.txt
├── development/     # Coding and review prompts
│   ├── code_review.txt
│   ├── refactor.txt
│   ├── debug.txt
│   └── document.txt
├── research/        # Research and analysis
│   ├── analyze.txt
│   ├── summarize.txt
│   └── report.txt
├── roles/          # System prompts
│   ├── expert.txt
│   ├── teacher.txt
│   ├── code_reviewer.txt
│   └── researcher.txt
├── workflows/      # Multi-step pipelines
│   ├── blog_post.txt
│   ├── documentation.txt
│   └── analysis_suite.txt
└── tools/          # Custom tools
    ├── text_analyzer.rb
    ├── file_processor.rb
    └── api_client.rb

Security Best Practices

Safe Prompt Patterns

# ✅ Good: Use parameters for sensitive data
//config api_key = [API_KEY]
//config database_url = [DATABASE_URL]

# ❌ Bad: Hardcode secrets
//config api_key = sk-1234567890abcdef

# ✅ Good: Validate shell commands
//shell ls -la [SAFE_DIRECTORY]
//shell git status

# ❌ Dangerous: Avoid destructive commands
//shell rm -rf [DIRECTORY]  # Be very careful!

File Permissions

# Set restrictive permissions on prompts directory
chmod 700 ~/.prompts
chmod 600 ~/.prompts/*.txt

# Create separate directory for shared/untrusted prompts
mkdir ~/shared-prompts
chmod 755 ~/shared-prompts

Input Validation in Tools

# Always validate inputs in custom tools
def execute(file_path:)
  # Validate file path
  unless file_path.match?(/\A[\w\-\/\.]+\z/)
    return { error: "Invalid file path" }
  end
  
  # Check if file exists and is readable
  unless File.readable?(file_path)
    return { error: "File not found or not readable" }
  end
  
  # Proceed with safe operation
  File.read(file_path)
end

Troubleshooting Examples

Debug Mode Usage

# Enable debug output for troubleshooting
aia --debug --verbose my_prompt

# Check configuration
aia --config

# List available models
aia --available_models

Common Error Patterns

# Prompt not found - use fuzzy search
aia --fuzzy

# Shell command issues - test separately
echo "Test: $(date)"

# Model errors - verify model name
aia --model gpt-4o my_prompt  # Correct
aia --model gpt4 my_prompt    # Incorrect

Related Topics

⚠️ **GitHub.com Fallback** ⚠️