detecting-agent-environment

ynotradio's avatarfrom ynotradio

Utilities and patterns for detecting execution environment (CI/CD vs local, network access, available ports, timeouts). Use when you need to adapt scripts or workflows based on where the agent is running, or when creating helper scripts that need environment-aware behavior.

⭐0stars🔀1forks📁View on GitHub🕐Updated Jan 5, 2026⬇️1downloads

When & Why to Use This Skill

This Claude skill provides a comprehensive framework for environment detection and agent helper script management. It enables AI agents to dynamically adapt their behavior based on the execution context—such as distinguishing between CI/CD pipelines and local environments—while managing network access, port availability, and performance-based timeouts to ensure resilient and portable automation workflows.

Use Cases

  • Environment-Aware Workflow Adaptation: Automatically switch between optimized, non-interactive CI/CD paths and standard local development modes based on the detected execution environment.
  • Pre-execution Connectivity Checks: Prevent script failures by verifying network access and resource availability before attempting to pull external packages or connect to services.
  • Dynamic Timeout & Performance Management: Implement environment-specific timeouts for critical operations like container startup or dependency installation to handle varying infrastructure speeds.
  • Standardized Agent Observability: Utilize unified logging patterns and exit code handling to ensure agent-generated scripts provide clear, debuggable output in any environment.
namedetecting-agent-environment
descriptionUtilities and patterns for detecting execution environment (CI/CD vs local, network access, available ports, timeouts). Use when you need to adapt scripts or workflows based on where the agent is running, or when creating helper scripts that need environment-aware behavior.

Agent Helper Scripts

Utilities for GitHub Copilot agents working on Y-Not Radio site.

Environment Detection

Use detect-environment.sh to adapt scripts to different environments:

# Source the utility
source bin/agent-helpers/detect-environment.sh

# Print environment info
print_environment

# Check environment
if detect_ci; then
  echo "Running in CI/CD"
  # Use optimized workflow
fi

if ! detect_network; then
  echo "Network restricted - cannot pull packages"
  exit 1
fi

# Get appropriate timeout
TIMEOUT=$(get_timeout "service_ready")
timeout $TIMEOUT bash -c 'until service_ready; do sleep 5; done'

Creating New Helper Scripts

When creating helper scripts:

  1. Source environment detection

    source "$(dirname "$0")/detect-environment.sh"
    print_environment
    
  2. Use appropriate timeouts

    TIMEOUT=$(get_timeout "npm_install")
    timeout $TIMEOUT npm install
    
  3. Provide clear output

    echo "✅ Success message"
    echo "⚠️  Warning message"
    echo "❌ Error message"
    
  4. Exit with proper codes

    exit 0  # Success
    exit 1  # Failure
    
  5. Log to .agent-tmp/

    mkdir -p .agent-tmp
    command 2>&1 | tee .agent-tmp/command.log
    

Before creating scripts or PRs, see:

  • testing-pr-changes skill - Success criteria and testing workflows
  • agent-automation-infrastructure skill - Current automation state and pre-built images

Performance Baselines

Scripts should respect these baselines:

Operation Expected Warning Failure
Container start < 60s 60-120s > 120s
npm install < 120s 120-300s > 300s
Service ready < 180s 180-360s > 360s

If exceeding "Warning" thresholds, report performance issues in PR.