feature-flags – skill Khác cho agent AI
Triển khai feature flag để phát hành tính năng dần dần bằng LaunchDarkly, Unleash hoặc giải pháp tự xây dựng.
Cài skill feature-flags bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/feature-flags-7a504.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /feature-flags – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/feature-flags-7a504.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $feature-flags – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/feature-flags-7a504.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /feature-flags – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/feature-flags-7a504.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /feature-flags – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Feature Flags
Control feature releases and enable progressive rollout with feature flag systems.
Prerequisites
- Application code access
- Feature flag service or self-hosted solution
- Basic understanding of deployment patterns
Feature Flag Types
| Type | Purpose | Example |
|------|---------|---------|
| Release | Control feature visibility | New checkout flow |
| Experiment | A/B testing | Button color test |
| Ops | Runtime configuration | Rate limiting |
| Entitlement presentation | Display already-authorized features | Premium UI visibility |
| Kill Switch | Emergency disable | Third-party integration |
Feature flags do not replace server-side authorization. Never trust client evaluation or a client-supplied identity for access to protected data or paid operations. Keep server SDK keys out of browsers; minimize personal attributes sent to providers. SDK snippets are historical sketches: pin compatible package versions and verify current schemas. Custom examples omit storage/rule helpers and production error/cache handling.
LaunchDarkly
SDK Setup (Node.js)
const LaunchDarkly = require('launchdarkly-node-server-sdk');
const client = LaunchDarkly.init(process.env.LAUNCHDARKLY_SDK_KEY);
await client.waitForInitialization();
// Evaluate flag
const user = {
key: 'user-123',
email: '[email protected]',
custom: {
plan: 'premium',
company: 'acme'
}
};
const showNewFeature = await client.variation('new-checkout', user, false);
if (showNewFeature) {
// New feature code
} else {
// Existing code
}React SDK
import { withLDProvider, useFlags, useLDClient } from 'launchdarkly-react-client-sdk';
// Provider setup
export default withLDProvider({
clientSideID: 'your-client-side-id',
user: {
key: 'user-123',
email: '[email protected]'
}
})(App);
// Using flags in component
function FeatureComponent() {
const { newCheckout, experimentVariant } = useFlags();
const ldClient = useLDClient();
// Track events
const handleClick = () => {
ldClient?.track('checkout-started');
};
if (newCheckout) {
return <NewCheckout onClick={handleClick} />;
}
return <OldCheckout onClick={handleClick} />;
}Targeting Rules
# LaunchDarkly targeting configuration
flag: new-checkout
targeting:
# Individual users
targets:
- variation: true
values: ['user-123', 'user-456']
# Rules
rules:
# Beta users
- variation: true
clauses:
- attribute: email
op: endsWith
values: ['@company.com']
# Premium plan
- variation: true
clauses:
- attribute: plan
op: in
values: ['premium', 'enterprise']
# Percentage rollout
- variation: true
rollout:
variations:
- variation: true
weight: 20000 # 20%
- variation: false
weight: 80000 # 80%
# Default
fallthrough:
variation: falseUnleash
Local Development Server Setup
Disposable local demonstration only: replace the image tag with a reviewed digest and supply a unique local database password through ignored environment configuration. Do not expose this service publicly or reuse these settings in production.
# docker-compose.yml
version: '3.8'
services:
unleash:
image: unleashorg/unleash-server:<reviewed-version-or-digest>
ports:
- "127.0.0.1:4242:4242"
environment:
- DATABASE_URL=postgres://postgres:${UNLEASH_DB_PASSWORD:?set local password}@db/unleash
- DATABASE_SSL=false
depends_on:
- db
db:
image: postgres:15
environment:
- POSTGRES_PASSWORD=${UNLEASH_DB_PASSWORD:?set local password}
- POSTGRES_DB=unleash
volumes:
- postgres-data:/var/lib/postgresql/data
volumes:
postgres-data:SDK Setup (Node.js)
const { initialize } = require('unleash-client');
const unleash = initialize({
url: 'http://localhost:4242/api',
appName: 'my-app',
customHeaders: {
Authorization: 'your-api-token'
}
});
unleash.on('ready', () => {
// Check feature
const isEnabled = unleash.isEnabled('new-checkout');
// With context
const context = {
userId: 'user-123',
properties: {
plan: 'premium'
}
};
const isEnabledForUser = unleash.isEnabled('new-checkout', context);
// Get variant
const variant = unleash.getVariant('experiment-flag', context);
console.log(variant.name); // 'control' or 'treatment'
});Activation Strategies
# Standard strategies
strategies:
- name: default
# On/off for everyone
- name: userWithId
parameters:
userIds: 'user-1,user-2,user-3'
- name: gradualRolloutUserId
parameters:
percentage: 25
groupId: 'new-feature'
- name: gradualRolloutRandom
parameters:
percentage: 50
- name: flexibleRollout
parameters:
rollout: 30
stickiness: userId
groupId: 'checkout-exp'Custom Implementation
Database-Backed Flags
# models.py
from django.db import models
class FeatureFlag(models.Model):
name = models.CharField(max_length=100, unique=True)
enabled = models.BooleanField(default=False)
rollout_percentage = models.IntegerField(default=0)
allowed_users = models.JSONField(default=list)
rules = models.JSONField(default=dict)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
# service.py
import hashlib
class FeatureFlagService:
def __init__(self):
self._cache = {}
def is_enabled(self, flag_name, user_id=None, context=None):
flag = self._get_flag(flag_name)
if not flag or not flag.enabled:
return False
# Check user allowlist
if user_id and user_id in flag.allowed_users:
return True
# Check rules
if context and self._evaluate_rules(flag.rules, context):
return True
# Check percentage rollout
if flag.rollout_percentage > 0 and user_id:
return self._is_in_rollout(flag_name, user_id, flag.rollout_percentage)
return flag.rollout_percentage == 100
def _is_in_rollout(self, flag_name, user_id, percentage):
hash_input = f"{flag_name}:{user_id}"
hash_value = int(hashlib.md5(hash_input.encode()).hexdigest(), 16)
return (hash_value % 100) < percentage
def _evaluate_rules(self, rules, context):
for rule in rules.get('rules', []):
if self._evaluate_rule(rule, context):
return True
return FalseRedis-Backed Flags
import redis
import json
class RedisFeatureFlags:
def __init__(self, redis_url):
self.redis = redis.from_url(redis_url)
self.prefix = 'feature_flag:'
def set_flag(self, name, config):
key = f"{self.prefix}{name}"
self.redis.set(key, json.dumps(config))
def is_enabled(self, name, user_id=None):
key = f"{self.prefix}{name}"
data = self.redis.get(key)
if not data:
return False
config = json.loads(data)
if not config.get('enabled', False):
return False
# User allowlist
if user_id in config.get('users', []):
return True
# Percentage rollout
percentage = config.get('percentage', 0)
if percentage == 100:
return True
if percentage > 0 and user_id:
return self._hash_user(name, user_id) < percentage
return False
def _hash_user(self, flag, user_id):
import hashlib
hash_input = f"{flag}:{user_id}"
return int(hashlib.sha256(hash_input.encode()).hexdigest(), 16) % 100Testing with Feature Flags
Unit Testing
// Jest mocking
jest.mock('launchdarkly-node-server-sdk', () => ({
init: jest.fn(() => ({
waitForInitialization: jest.fn().mockResolvedValue(undefined),
variation: jest.fn()
}))
}));
describe('Checkout', () => {
it('shows new checkout when flag enabled', async () => {
const ldClient = require('launchdarkly-node-server-sdk').init();
ldClient.variation.mockResolvedValue(true);
const result = await renderCheckout(user);
expect(result).toContain('NewCheckout');
});
it('shows old checkout when flag disabled', async () => {
const ldClient = require('launchdarkly-node-server-sdk').init();
ldClient.variation.mockResolvedValue(false);
const result = await renderCheckout(user);
expect(result).toContain('OldCheckout');
});
});Integration Testing
# pytest sketch: client must be supplied and the application must be wired
# to use this feature_flags test double; defining it alone do… (nội dung đầy đủ có trong gói tải về)
Skill liên quan
- featured-snippet-optimizer – Tối ưu Featured Snippet. Dùng khi làm việc với câu hỏi mục tiêu và đoạn văn hiện có.
- featured-tool-schema-generator – Featured Tool Schema Generator. Dùng khi làm việc với URL trang công cụ và các chức năng…
- ffuf-claude-skill – Fuzzing web với ffuf
- filesystem-context – Dùng để quản lý ngữ cảnh dựa trên file, khám phá ngữ cảnh động và giảm tình trạng phình…
- film-crew – Biến ý tưởng video AI một dòng thành danh sách shot và prompt cho từng shot, sẵn sàng…
- fitness-analyzer – Phân tích dữ liệu vận động, nhận diện mô hình tập luyện, đánh giá tiến độ thể hình và…
- yuanbao – Nhóm Yuanbao (元宝): @mention người dùng, truy vấn thông tin và thành viên.
- footval-scout-and-rank-players – Tuyển chọn và xếp hạng cầu thủ bóng đá với FootVal: danh sách rút gọn theo giải đấu, vị…