Buổi 15: Automation & Custom Skills — Build Your Workflow ⚡
Thành quả: Tạo 1 custom skill cá nhân + 1 skill chain tự động
🎯 Mục Tiêu
- Tạo custom skill với SKILL.md format
- Design skill chain cho workflow cá nhân
- Hiểu cm-skill-chain, cm-skill-evolution
- Share skills với team (cm-skill-share)
- Monitor skill health (cm-skill-health)
📖 Phần 1: Custom Skill Structure
Anatomy of a SKILL.md
markdown
---
name: my-deploy-checker
description: Pre-deploy verification for my team's Node.js apps.
Runs health checks, validates environment, and sends Slack notification.
ALWAYS trigger for: deploy, ship, release, "go live", pre-deploy check
---
# My Deploy Checker
## When to Use
- Before deploying ANY Node.js application
- When asked to "ship", "deploy", "go live"
- As part of release workflow
## Prerequisites
- Node.js 20+ installed
- Slack webhook URL configured
- GitHub Actions access
## Workflow
### Step 1: Environment Verification
```bash
# Check Node version
node --version | grep -E "v2[0-9]" || echo "⚠️ Node 20+ required"
# Check environment variables
required_vars=("DATABASE_URL" "JWT_SECRET" "REDIS_URL")
for var in "${required_vars[@]}"; do
if [ -z "${!var}" ]; then
echo "❌ Missing: $var"
exit 1
fi
done
echo "✅ Environment verified"Step 2: Run Test Gate
→ Invoke cm-test-gate → All 4 layers must pass
Step 3: Build Verification
bash
npm run build
if [ $? -ne 0 ]; then
echo "❌ Build failed"
exit 1
fi
echo "✅ Build successful"Step 4: Notify Team
bash
curl -X POST $SLACK_WEBHOOK_URL \
-H "Content-Type: application/json" \
-d "{\"text\": \"🚀 Deploy starting: $(git log -1 --format='%s')\"}"Integration
- Works with: cm-safe-deploy, cm-test-gate, cm-identity-guard
- Chain: cm-identity-guard → my-deploy-checker → cm-safe-deploy
Troubleshooting
| Issue | Solution |
|---|---|
| Slack notification fails | Check SLACK_WEBHOOK_URL |
| Build fails | Check node_modules, run npm ci |
| Tests fail | Fix tests before deploy |
---
## 📖 Phần 2: Skill Design Patterns
### Pattern 1: Wrapper Skill
Extends an existing skill with team-specific defaults:
```markdown
---
name: team-code-review
description: Team-specific code review with our conventions
---
## Workflow
### Step 1: Run cm-code-review
→ Use standard code review
### Step 2: Additional Checks
- [ ] Vietnamese comments for business logic?
- [ ] API versioning maintained?
- [ ] Database migration backward compatible?
- [ ] i18n keys added for new strings?
### Step 3: Approval Rules
- Frontend changes: Need Design review
- Backend API changes: Need Senior review
- Database schema: Need DBA review
- Security-related: Need Security Lead reviewPattern 2: Automation Skill
Automates a repetitive workflow:
markdown
---
name: create-feature
description: Automate new feature setup with branching, scaffold, and tests
---
## Workflow
### Step 1: Create Branch
```bash
git checkout develop
git pull origin develop
git checkout -b feature/${FEATURE_NAME}Step 2: Scaffold Files
bash
mkdir -p src/features/${FEATURE_NAME}
touch src/features/${FEATURE_NAME}/index.ts
touch src/features/${FEATURE_NAME}/${FEATURE_NAME}.service.ts
touch src/features/${FEATURE_NAME}/${FEATURE_NAME}.controller.ts
touch src/features/${FEATURE_NAME}/${FEATURE_NAME}.test.ts
touch src/features/${FEATURE_NAME}/${FEATURE_NAME}.routes.tsStep 3: Generate Test Template
→ AI generates test file with AAA pattern
Step 4: Update CONTINUITY.md
→ Add feature to active work
### Pattern 3: Knowledge Skill
Captures domain-specific knowledge:
```markdown
---
name: vietnam-ecommerce
description: Vietnam e-commerce domain knowledge for dev teams
---
## Payment Gateways
- MoMo: REST API, webhook for status
- VNPay: Redirect flow, IPN callback
- ZaloPay: App-to-app, miniapp
## Tax Rules
- VAT: 10% (2024), 8% reduced
- Invoice: e-invoice required for B2B > 20M VND
## Shipping
- GHN, GHTK, J&T: API integration patterns
- Weight-based pricing vs location-based📖 Phần 3: Skill Chains
cm-skill-chain Architecture
Chain Definition:
name: feature-delivery
steps:
1. cm-planning (input: requirement)
2. cm-tdd (input: plan → output: tests)
3. cm-execution (input: tests → output: code)
4. cm-quality-gate (input: code → pass/fail)
5. cm-code-review (input: code → feedback)
6. cm-safe-deploy (input: build → live URL)
Chain Runner:
mode: sequential (default)
on_failure: stop (or: retry, skip, rollback)
notifications: slackCreate Your Chain
markdown
## My Feature Delivery Chain
### Trigger
"Build feature: [description]"
### Steps
1. **Identity** → cm-identity-guard
- Verify: git user, deploy target
2. **Plan** → cm-planning
- Input: Feature description
- Output: implementation_plan.md
- Gate: User approves plan
3. **Branch** → create-feature (custom skill)
- Input: Feature name from plan
- Output: Branch + scaffold
4. **Code (TDD)** → cm-tdd + cm-execution
- Input: Plan requirements
- Output: Tests + implementation
- Gate: All tests pass
5. **Quality** → cm-quality-gate
- Input: Code changes
- Gate: Lint + test + coverage pass
6. **Review** → cm-code-review
- Input: PR
- Gate: Reviewer approves
7. **Ship** → cm-safe-deploy
- Input: Merged code
- Output: Live URL
- Gate: Smoke test passes
8. **Document** → cm-continuity
- Update CONTINUITY.md with feature status📖 Phần 4: Skill Evolution
cm-skill-evolution — 3 Modes
| Mode | When | Action |
|---|---|---|
| FIX | Skill breaks or degrades | Patch specific issue |
| DERIVED | Need variation for new context | Fork + customize |
| CAPTURED | Novel workflow succeeds | Create new skill from session |
Evolution Process
1. Detect: cm-skill-health shows degraded score
2. Analyze: What changed? New deps? New patterns?
3. Evolve: Apply FIX/DERIVED/CAPTURED
4. Test: Run skill in test scenario
5. Deploy: Update skill file
6. Monitor: Track health scoreSharing Skills
bash
# Export skill
cm-skill-share export my-deploy-checker --output ./exported-skills/
# Import skill
cm-skill-share import ./received-skills/team-review.md
# Community catalog
cm-skill-share browse --tag "deployment"
cm-skill-share browse --tag "react"🧪 Lab: Create Your Skills
Task 1: Custom Skill (30 min)
Create a skill that automates YOUR most repeated workflow:
Ideas:
- PR creation with auto-filled template
- Environment setup for new dev
- Daily standup report from git log
- Database backup verification
- API documentation regeneration
- Performance benchmark runnerTask 2: Skill Chain (30 min)
Chain 3+ skills into an automated workflow:
Example chains:
- "Morning Routine": git pull → run tests → check security → status report
- "Feature Sprint": plan → scaffold → code → test → review → deploy
- "Bug Fix Express": reproduce → debug → fix → test → deploy → notify🎓 Tóm Tắt
| Concept | Key Point |
|---|---|
| Custom Skills | SKILL.md with trigger words, steps, integration points |
| Patterns | Wrapper, Automation, Knowledge |
| Skill Chains | Sequential execution with gates at each step |
| Evolution | FIX → DERIVED → CAPTURED modes |
| Sharing | Export/import, team catalog |
⏭️ Buổi tiếp theo
Buổi 16: Capstone — Production Full-Stack Application 🎓