Initial commit

This commit is contained in:
Zhongwei Li
2025-11-29 17:59:24 +08:00
commit b704bccc5f
6 changed files with 803 additions and 0 deletions

244
commands/deploy.md Normal file
View File

@@ -0,0 +1,244 @@
You are managing a deployment system. The user wants to deploy to an environment.
## Task: Deploy Application
Parse the environment from arguments: $ARGUMENTS
Expected format: /deploy [environment]
Valid environments: dev, uat, prod
### Step 1: Parse and Validate Environment
Extract the environment name from $ARGUMENTS.
If no environment provided, show error and STOP:
```
❌ Error: No environment specified
Usage: /deploy [environment]
Available environments:
• dev - Development environment (deploy_dev branch)
• uat - User Acceptance Testing (deploy_uat branch)
• prod - Production environment (deploy_prod branch)
Example: /deploy dev
```
### Step 2: Load Configuration
Run CLI to get configuration:
```bash
node deployment/cli/deploy-cli.js config
```
If configuration not found (error in output), show error and STOP:
```
❌ Error: Deployment not configured
💡 Run /deploy:init to set up deployment
```
Parse the JSON output and extract:
- mainBranch
- buildCommand
- environments.{env} configuration
If the requested environment doesn't exist in config, show available environments and STOP:
```
❌ Error: Unknown environment "{env}"
Available environments: {list from config}
💡 Edit .claude/deployment.config.json to add custom environments
```
### Step 3: Run Pre-Deployment Validation
Run CLI validation for the target environment:
```bash
node deployment/cli/deploy-cli.js validate --check-git --env {environment}
```
Parse the JSON output.
If `success: false`, show all errors and STOP:
```
🚫 Deployment blocked by safety checks:
{for each error:}
❌ {error.message}
💡 Fix: {error.fix}
Please resolve these issues before deploying.
```
If warnings exist (success: true but warnings present), show warnings but continue:
```
⚠️ Warnings detected:
{for each warning:}
• {warning.message}
💡 {warning.fix}
Continuing with deployment...
```
### Step 4: Determine Source Branch
Based on environment configuration:
- If environment has `sourceBranch`: Use that branch
- If environment has `sourceEnvironment`: Use that environment's deployment branch
Example:
- dev: source is "main" (sourceBranch)
- uat: source is "deploy_dev" (from sourceEnvironment: "dev")
- prod: source is "deploy_uat" (from sourceEnvironment: "uat")
Store the source branch and deployment branch for later steps.
### Step 5: Run Build Validation
Show progress:
```
🔨 Running build validation...
Command: {buildCommand}
```
Execute the build command:
```bash
{buildCommand}
```
Monitor the output.
**If build succeeds:**
```
✓ Build completed successfully
```
Proceed to Step 6.
**If build fails:**
Show the build errors:
```
❌ Build failed with errors:
{build_error_output}
What would you like to do?
```
Use AskUserQuestion:
```json
{
"questions": [{
"question": "Build failed. How should we proceed?",
"header": "Action",
"multiSelect": false,
"options": [
{"label": "Show me the errors, I'll fix them", "description": "Stop deployment, let me fix manually"},
{"label": "Try to auto-fix", "description": "Let Claude attempt to fix the errors"},
{"label": "Cancel deployment", "description": "Stop the deployment process"}
]
}]
}
```
- If "Show me" or "Cancel": STOP with guidance
- If "Try to auto-fix": Attempt to fix, then re-run build
- If second build fails: STOP and ask user to fix manually
### Step 6: Checkout and Update Source Branch
Ensure we're on the correct source branch and it's up-to-date:
```bash
git fetch origin && git checkout {source_branch} && git pull origin {source_branch}
```
Verify the branch is clean and up-to-date.
### Step 7: Merge to Deployment Branch
Get the deployment branch from config: `environments.{env}.branch`
```bash
git checkout {deployment_branch} && git pull origin {deployment_branch} && git merge {source_branch} --no-ff -m "Deploy {source_branch} to {environment} environment"
```
**If merge conflicts occur:**
```
❌ Merge conflict detected
Conflicting files:
{list files from git status}
You need to resolve these conflicts manually:
1. The merge is in progress with conflicts
2. Resolve conflicts in the files listed above
3. Run: git add . && git commit
4. Then retry: /deploy {environment}
Aborting deployment.
```
Run: `git merge --abort`
STOP execution.
**If merge succeeds:**
```
✓ Merged {source_branch} → {deployment_branch}
```
### Step 8: Push to Trigger Deployment
Push the deployment branch to trigger Netlify auto-deploy:
```bash
git push origin {deployment_branch}
```
If push fails, show error:
```
❌ Push failed
{error output}
💡 Check your remote connection and permissions
```
STOP execution.
### Step 9: Display Success Message
Show deployment confirmation:
```
✓ Deployment initiated successfully
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🚀 Environment: {environment}
📦 Branch: {deployment_branch}
🔗 Source: {source_branch}
📊 Netlify will now build and deploy automatically
Check your Netlify dashboard for deployment status
💡 Next steps:
{if dev} → After testing, deploy to UAT: /deploy uat
{if uat} → After approval, deploy to prod: /deploy prod
{if prod} → Monitor production for any issues
🔍 To check status: Visit your Netlify dashboard
```
---
**IMPORTANT:**
- Always validate before executing
- Show clear progress updates
- Handle errors gracefully with recovery options
- Enforce environment progression (dev → uat → prod)
- Never skip safety checks

176
commands/init.md Normal file
View File

@@ -0,0 +1,176 @@
You are managing a deployment configuration system. The user wants to initialize deployment settings for their project.
## Task: Initialize Deployment Configuration
This command sets up deployment configuration for the project. This is a one-time setup.
### Step 1: Check for Existing Configuration
Run the CLI to check if configuration already exists:
```bash
node deployment/cli/deploy-cli.js config 2>&1
```
If the output contains "Configuration not found", proceed to Step 2.
If configuration exists, show this error and STOP:
```
❌ Error: Deployment configuration already exists
📁 Location: .claude/deployment.config.json
💡 To view current config: Run node deployment/cli/deploy-cli.js config
💡 To modify: Edit .claude/deployment.config.json directly
```
### Step 2: Gather Configuration Details
Ask the user the following questions using AskUserQuestion tool:
```json
{
"questions": [
{
"question": "What is your main development branch?",
"header": "Main Branch",
"multiSelect": false,
"options": [
{"label": "main", "description": "Default branch named 'main'"},
{"label": "master", "description": "Legacy default branch 'master'"},
{"label": "develop", "description": "Use 'develop' as main branch"}
]
},
{
"question": "What command should run to build your project?",
"header": "Build Command",
"multiSelect": false,
"options": [
{"label": "npm run build", "description": "Node.js project with npm"},
{"label": "yarn build", "description": "Node.js project with yarn"},
{"label": "pnpm build", "description": "Node.js project with pnpm"},
{"label": "make build", "description": "Project with Makefile"}
]
}
]
}
```
Store the user's answers for Step 3.
### Step 3: Create Configuration
Use the CLI to initialize the configuration with user's choices:
```bash
node deployment/cli/deploy-cli.js init --main-branch {user_main_branch} --build-command "{user_build_command}"
```
**Expected output**: JSON with success: true
If the command fails, show error and STOP:
```
❌ Error: Failed to initialize configuration
{error_message}
💡 Check that .claude/ directory is writable
```
### Step 4: Verify Configuration Created
Read the created configuration to verify:
```bash
node deployment/cli/deploy-cli.js config
```
Parse the JSON output and extract the environments.
### Step 5: Display Configuration Summary
Show the user what was configured:
```
✓ Deployment configuration initialized
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📁 Location: .claude/deployment.config.json
📋 Configuration:
Main Branch: {main_branch}
Build Command: {build_command}
🌍 Environments configured:
• dev (deploy_dev) ← {main_branch}
• uat (deploy_uat) ← deploy_dev
• prod (deploy_prod) ← deploy_uat
🔒 Safety Features:
✓ Uncommitted files check
✓ Branch validation
✓ Clean build requirement
💡 Next Steps:
1. Review config: Edit .claude/deployment.config.json if needed
2. Create deployment branches (see below)
3. Deploy to dev: /deploy dev
```
### Step 6: Offer to Create Deployment Branches
Ask the user:
```
The following deployment branches need to exist in your repository:
- deploy_dev
- deploy_uat
- deploy_prod
Would you like me to create these branches now?
```
Use AskUserQuestion:
```json
{
"questions": [{
"question": "Create deployment branches?",
"header": "Setup",
"multiSelect": false,
"options": [
{"label": "Yes", "description": "Create all deployment branches from main"},
{"label": "No", "description": "I'll create them manually later"}
]
}]
}
```
If user selects "Yes":
```bash
git checkout {main_branch} && git pull origin {main_branch} && git checkout -b deploy_dev && git push -u origin deploy_dev && git checkout -b deploy_uat && git push -u origin deploy_uat && git checkout -b deploy_prod && git push -u origin deploy_prod && git checkout {main_branch}
```
Show success message:
```
✓ Deployment branches created successfully
• deploy_dev
• deploy_uat
• deploy_prod
All branches have been pushed to origin.
You're ready to deploy!
```
If user selects "No":
```
💡 Remember to create these branches manually:
git checkout {main_branch}
git checkout -b deploy_dev && git push -u origin deploy_dev
git checkout -b deploy_uat && git push -u origin deploy_uat
git checkout -b deploy_prod && git push -u origin deploy_prod
```
---
**IMPORTANT:**
- Use CLI for all config operations (plan mode support)
- Validate user input before proceeding
- Provide clear next steps
- Make it interactive and user-friendly