diff --git a/skills/create-php/SKILL.md b/skills/create-php/SKILL.md new file mode 100644 index 00000000..8ffd530f --- /dev/null +++ b/skills/create-php/SKILL.md @@ -0,0 +1,47 @@ +--- +name: create-php-app +description: A skill to create a simple PHP application. +--- + +# Create a new PHP application + +This skill creates a new, simple PHP application. + +## 1. Install PHP + +This step ensures that PHP is installed on the system. + +```bash +if [ "$OS" = "Windows_NT" ]; then + ./scripts/install_php.ps1 +else + ./scripts/install_php.sh +fi +``` + +## 2. Create the project + +Create a new directory with the given workspace name and navigate into it. + +```bash +mkdir -p {{workspace_name}} +cd {{workspace_name}} +``` + +## 3. Copy Template Files + +Copy the PHP template files into the new directory. + +```bash +cp -r ../../php/app/* . +``` + +## 4. Configure Agent Rules + +Create the directory for the AI agent's rules. The skill will then copy the rule file into it. + +```bash +mkdir -p .agents/rules +``` + +(The skill runner will place the content of `resources/ai_rules.md` into `.agents/rules/php.md`) diff --git a/skills/create-php/resources/ai_rules.md b/skills/create-php/resources/ai_rules.md new file mode 100644 index 00000000..42d59c4a --- /dev/null +++ b/skills/create-php/resources/ai_rules.md @@ -0,0 +1,37 @@ +# Gemini AI Rules for PHP Projects + +## 1. Persona & Expertise +You are an expert back-end developer with a deep specialization in modern PHP. You are proficient in object-oriented programming, common design patterns (like MVC), and the broader PHP ecosystem, including Composer for package management. You write secure, performant, and maintainable code. + +## 2. Project Context +This project is a back-end application or API built with PHP. The focus is on creating a secure, performant, and well-structured server-side application. Assume the project uses modern PHP (8.0+) and Composer for dependency management. + +## 3. Coding Standards & Best Practices + +### General +- **Language:** Always use modern, idiomatic PHP, including strict types where appropriate. +- **Dependencies:** Use Composer for managing all project dependencies. After suggesting a new package, remind the user to run `composer require vendor/package`. +- **Testing:** Encourage the use of PHPUnit for unit and integration testing. +- **Decoupling:** Promote the use of service classes and dependency injection to decouple different parts of the application, especially AI-related logic. + +### PHP-Specific +- **Security:** + - **API Keys:** Never hard-code API keys. Store them in environment variables and use a library like `vlucas/phpdotenv` to load them. Access them using `getenv()`. + - **Input Handling:** Sanitize and validate all user input to prevent XSS and other injection attacks. Use prepared statements for all database queries to prevent SQL injection. +- **Error Handling:** + - **Exceptions:** Use `try-catch` blocks to handle exceptions gracefully, especially for external API calls. + - **Logging:** Log errors for debugging purposes but display user-friendly, generic error messages. +- **Performance:** + - **Caching:** Recommend caching strategies (e.g., Redis, Memcached, or file-based caching) for expensive or frequent AI API calls. + - **Asynchronous Processing:** For long-running AI tasks, suggest offloading them to a background job using a message queue (e.g., RabbitMQ, Beanstalkd). +- **API Interaction:** + - **HTTP Client:** Use a robust HTTP client library like Guzzle for making requests to external AI services. + - **Provider SDKs:** If an official PHP SDK is available for the AI service, prefer using it over manual cURL requests. + +## 4. Interaction Guidelines + +- Assume the user is familiar with PHP and basic web development concepts. +- Provide clear and actionable code examples for creating classes, functions, and interacting with AI services. +- Break down complex tasks, like setting up an asynchronous job queue or implementing a caching layer, into smaller, manageable steps. +- If a request is ambiguous, ask for clarification about the desired functionality, the specific AI service being used, or the existing application architecture. +- When discussing security, provide specific libraries and techniques to address common vulnerabilities in PHP applications. \ No newline at end of file diff --git a/skills/create-php/resources/setup_instructions.md b/skills/create-php/resources/setup_instructions.md new file mode 100644 index 00000000..d49b709a --- /dev/null +++ b/skills/create-php/resources/setup_instructions.md @@ -0,0 +1,43 @@ +# PHP Workspace Setup Instructions + +Follow these steps to initialize the workspace. + +## 1. Install PHP (if not already installed) + +This step ensures that PHP is installed on the system. If it's already present, the installation will be skipped. + +```bash +# The skill will automatically detect your OS and run the correct script. +if [ "$OS" = "Windows_NT" ]; then + ./scripts/install_php.ps1 +else + ./scripts/install_php.sh +fi +``` + +## 2. Create the Project + +Create a new directory with the given workspace name and navigate into it. + +```bash +mkdir -p {{workspace_name}} +cd {{workspace_name}} +``` + +## 3. Copy Template Files + +Copy the PHP template files into the new directory. + +```bash +cp -r ../../php/app/* . +``` + +## 4. Configure Agents Rules + +Create the directory for the AI agent's rules. The skill will then copy the rule file into it. + +```bash +mkdir -p .agents/rules +``` + +(The skill runner will place the content of `resources/ai_rules.md` into `.agents/rules/php.md`) diff --git a/skills/create-php/scripts/install_php.ps1 b/skills/create-php/scripts/install_php.ps1 new file mode 100644 index 00000000..ce39e4b3 --- /dev/null +++ b/skills/create-php/scripts/install_php.ps1 @@ -0,0 +1,18 @@ +# A script to install PHP on Windows + +# Check if PHP is already installed +if (Get-Command php -ErrorAction SilentlyContinue) { + Write-Host "PHP is already installed." + exit 0 +} + +# Check if Chocolatey is installed +if (-not (Get-Command choco -ErrorAction SilentlyContinue)) { + Write-Error "Chocolatey is not installed. Please install it first from https://chocolatey.org/install" + exit 1 +} + +# Install PHP +choco install -y php + +Write-Host "PHP installed successfully." diff --git a/skills/create-php/scripts/install_php.sh b/skills/create-php/scripts/install_php.sh new file mode 100644 index 00000000..ed3cdd79 --- /dev/null +++ b/skills/create-php/scripts/install_php.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# A script to install PHP +set -e + +# Check if PHP is already installed +if [ -x "$(command -v php)" ]; then + echo "PHP is already installed." + exit 0 +fi + +# Update package list and install PHP +if [ -x "$(command -v apt-get)" ]; then + apt-get update + apt-get install -y php +elif [ -x "$(command -v yum)" ]; then + yum install -y php +elif [ -x "$(command -v dnf)" ]; then + dnf install -y php +else + echo "Error: Could not find a package manager (apt-get, yum, dnf). Please install PHP manually." >&2 + exit 1 +fi + +echo "PHP installed successfully."