Agent Skillszerx-lab/zap › add-feature-flag

add-feature-flag

GitHub

指导在Warp代码库中添加编译时功能标志,包括配置Cargo.toml、枚举定义、条件编译及运行时检查,支持灰度发布与本地测试。

.agents/skills/add-feature-flag/SKILL.md zerx-lab/zap

Trigger Scenarios

需要添加新功能开关 进行特性门控开发 准备功能上线稳定版

Install

npx skills add zerx-lab/zap --skill add-feature-flag -g -y
More Options

Non-standard path

npx skills add https://github.com/zerx-lab/zap/tree/main/.agents/skills/add-feature-flag -g -y

Use without installing

npx skills use zerx-lab/zap@add-feature-flag

指定 Agent (Claude Code)

npx skills add zerx-lab/zap --skill add-feature-flag -a claude-code -g -y

安装 repo 全部 skill

npx skills add zerx-lab/zap --all -g -y

预览 repo 内 skill

npx skills add zerx-lab/zap --list

SKILL.md

Frontmatter
{
    "name": "add-feature-flag",
    "description": "Add a new feature flag to gate code changes in the Warp codebase."
}

add-feature-flag

Add a new feature flag to gate code changes in the Warp codebase.

Overview

Feature flags in Warp are compile-time flags that allow features to be selectively enabled for different channels (e.g.: Dev, Stable). They use a small runtime plumbing layer that checks if a flag is enabled.

Steps

1. Add to Cargo.toml

Add the feature to app/Cargo.toml under the [features] section, but NOT under the default nested stanza:

[features]
your_feature_name = []

2. Add to FeatureFlag enum

Add a new variant to the FeatureFlag enum in warp_core/src/features.rs:

#[derive(Sequence)]
pub enum FeatureFlag {
    YourFeatureName,
}

3. Add conditional compilation directive

Add the feature to app/src/lib.rs with a corresponding #[cfg(feature = "...")] attribute to ensure it's only included when enabled:

#[cfg(feature = "your_feature_name")]
YourFeatureName,

4. Gate code with runtime checks

In your code, use the runtime check to conditionally execute feature-gated code:

if FeatureFlag::YourFeatureName.is_enabled() {
    // feature-gated behavior
}

5. (Optional) Enable for dogfood builds

To enable the feature by default for Dev/dogfood builds, add it to the DOGFOOD_FLAGS array in features.rs:

pub const DOGFOOD_FLAGS: &[FeatureFlag] = &[
    FeatureFlag::YourFeatureName,
];

6. Running with feature flags

To test locally with the feature enabled:

cargo run --features your_feature_name

# Multiple features:
cargo run --features your_feature_name,another_feature

Keybindings with Feature Flags

If adding an EditableBinding or FixedBinding that's part of a gated feature, include an enabled predicate that checks the feature flag. This prevents the keybinding from appearing in keyboard settings when the feature is disabled.

Example:

EditableBinding::new(
    "action:name",
    "Action description",
    YourAction::Variant
)
.with_enabled(|| FeatureFlag::YourFeatureName.is_enabled())
.with_key_binding("cmdorctrl-key")

Rolling Out to Stable

When ready to enable the feature for all Warp Stable users, add it to the default array in app/Cargo.toml:

[features]
default = [
    "your_feature_name",
    # other default features...
]

Best Practices

  • Prefer runtime checks over cfg directives: Use FeatureFlag::YourFeatureName.is_enabled() instead of #[cfg(...)] when possible, so flags can be toggled without recompilation and are easier to clean up later
  • Use #[cfg(...)] only when code cannot compile without the flag (e.g., platform-specific code or missing dependencies)
  • Keep flags high-level and product-focused rather than per-call-site
  • Remove flags and dead branches after launch has stabilized

Version History

  • 5d87445 Current 2026-07-24 17:34

Same Skill Collection

.agents/skills/add-telemetry/SKILL.md
.agents/skills/dedupe-issue-local/SKILL.md
.agents/skills/diagnose-ci-failures/SKILL.md
.agents/skills/fix-errors/SKILL.md
.agents/skills/implement-specs/SKILL.md
.agents/skills/promote-feature/SKILL.md
.agents/skills/remove-feature-flag/SKILL.md
.agents/skills/resolve-merge-conflicts/SKILL.md
.agents/skills/review-pr-local/SKILL.md
.agents/skills/review-pr/SKILL.md
.agents/skills/rust-unit-tests/SKILL.md
.agents/skills/spec-driven-implementation/SKILL.md
.agents/skills/triage-issue-local/SKILL.md
.agents/skills/update-skill/SKILL.md
.agents/skills/warp-integration-test/SKILL.md
.agents/skills/warp-ui-guidelines/SKILL.md
.agents/skills/write-product-spec/SKILL.md
.agents/skills/write-tech-spec/SKILL.md
resources/bundled/mcp_skills/figma/figma-code-connect-components/SKILL.md
resources/bundled/mcp_skills/figma/figma-create-design-system-rules/SKILL.md
resources/bundled/mcp_skills/figma/figma-create-new-file/SKILL.md
resources/bundled/mcp_skills/figma/figma-generate-library/SKILL.md
resources/bundled/mcp_skills/figma/figma-implement-design/SKILL.md
resources/bundled/skills/add-mcp-server/SKILL.md
resources/bundled/skills/create-skill/SKILL.md
resources/bundled/skills/create-tab-config/SKILL.md
resources/bundled/skills/feedback/SKILL.md
resources/bundled/skills/modify-settings/SKILL.md
resources/bundled/skills/pr-comments/SKILL.md
resources/bundled/skills/tab-configs/SKILL.md
resources/bundled/skills/update-tab-config/SKILL.md
resources/channel-gated-skills/dogfood/triage-vulnerabilities/SKILL.md
resources/bundled/mcp_skills/figma/edit-figma-design/SKILL.md
resources/bundled/mcp_skills/figma/figma-generate-design/SKILL.md
resources/bundled/mcp_skills/figma/figma-use/SKILL.md
resources/bundled/skills/claude-api/SKILL.md

Metadata

Files
0
Version
5d87445
Hash
ef52a019
Indexed
2026-07-24 17:34

inicio - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-16 20:11
浙ICP备14020137号-1 $mapa de visitantes$