agentleFS
28672032962867203296/hermes-agent/skills/software-development/feature-flags/SKILL.md

feature-flags

Skill0 starsChanged 3 months agoMITView on GitHub

功能开关:灰度发布、A/B测试、Kill Switch、配置热更新.

13 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use data-visualization and git-workflow.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • AnthropicSkill

    data-visualization

    Create effective data visualizations with Python (matplotlib, seaborn, plotly). Use when building charts, choosing the right chart type for a dataset, creating publication-quality figures, or applying design principles like accessibility and color theory.

    Also in 3 projects that use this

  • Microsoft AzureSkill

    git-workflow

    Squad branching model: dev-first workflow with insiders preview channel

    Also in 3 projects that use this

The file

Files
SKILL.md

功能开关(Feature Flags)

为什么需要

不用开关:
新功能上线 → 全量用户 → 出Bug → 紧急回滚 → 30分钟

用开关:
新功能上线 → 5%用户 → 出Bug → 关开关 → 5秒

实现

# 简单开关(配置文件)
class FeatureFlags:
    def __init__(self):
        self._flags = {
            "new_ui": False,
            "ai_search": True,
            "beta_feature": False,
        }

    def is_enabled(self, flag):
        return self._flags.get(flag, False)

    def toggle(self, flag, value):
        self._flags[flag] = value

# 按用户灰度
def is_enabled_for_user(feature, user_id):
    if feature == "new_ui" and int(user_id) % 100 < 10:
        return True  # 10% 用户看到
    return False

# 按比例灰度
import hashlib
def is_in_rollout(feature, user_id, percentage=10):
    h = hashlib.md5(f"{feature}:{user_id}".encode()).hexdigest()
    return int(h[:8], 16) % 100 < percentage

四种开关类型

发布开关:新功能上线时用,稳定后删除
实验开关:A/B 测试用,测完删除
运维开关:紧急关功能(Kill Switch),长期保留
权限开关:按用户等级开放,长期保留

最佳实践

1. 开关有生命周期(稳定后删除,不堆积)
2. 开关有负责人(谁加的,什么时候删)
3. 开关可监控(哪些用户看到了)
4. 默认安全(新开关默认关)
5. 不要嵌套开关(A开关里判断B开关 → 测试爆炸)

Kill Switch

每个关键功能加一个 Kill Switch:
- 出问题秒级关闭
- 不影响其他功能
- 运维可控(不依赖开发)

例子:
if feature_flags.is_enabled("payment_gateway_v2"):
    process_v2()
else:
    process_v1()  # 回退到旧版

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.