Chuyển đến nội dung
Skillpedia
Triển khai và đám mây (DevOps)7.6k · #13159

feature-flags

Skill này làm gì

Skill này giải thích cách khai báo feature flag trong ứng dụng Agent-Native và bật chúng cho những người dùng, tổ chức hoặc tỷ lệ phần trăm đã chọn. Nó cũng bao gồm việc gỡ bỏ các flag cũ. Skill dành cho lập trình viên triển khai tính năng dần dần.

Khi nào nên dùng

  • ✓Khi bạn muốn ra mắt một tính năng mới cho một ít người dùng trước rồi mở rộng sau.
  • ✓Khi bạn cần bật một tính năng cho các tổ chức cụ thể mà không cần triển khai mới.
  • ✓Khi một công tắc biên dịch nên trở thành flag runtime có thể thay đổi an toàn.

Liên kết skill

https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/feature-flags/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/feature-flags/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Bạn có thể thêm một flag để trình tạo báo cáo mới chỉ bật cho khách hàng thí điểm, và tôi có thể bật rộng hơn sau không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent khai báo flag trong code dùng chung, kiểm tra flag trên máy chủ trước các action được bảo vệ, và quản lý trạng thái triển khai từ mặt phẳng điều khiển Analytics.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Feature Flags

A feature flag is a boolean declared in app code, evaluated locally by Core, and managed from the Analytics fleet control plane. Code owns whether a flag exists. Runtime settings own only its rollout state.

Flags let an app deploy dormant code and turn it on in the real environment without another deployment. They are not experiments: do not add variants, hypotheses, conversion metrics, exposure tracking, or lifecycle states.

When to use one

Use a flag for a reversible rollout of a user-facing capability whose dormant code is safe to deploy. Flags are useful for production dogfooding, exact-user or organization pilots, and deterministic percentage rollouts.

Do not use a flag for authentication, authorization, secrets, audit enablement, SSR cache behavior, or another security boundary. Client hiding is presentation only; every guarded server action must evaluate the same registered flag.

Agent workflow

1. Declare

Keep definitions in a shared TypeScript module so server and client code use the same stable key. Flags are boolean and default-off.

import { defineFeatureFlag } from "@agent-native/core/feature-flags/registry";

export const FULL_APP_BUILDING = defineFeatureFlag({
  key: "full-app-building",
  displayName: "Full app building",
  description: "Create and edit Fusion-backed applications.",
});

Never import defineFeatureFlag from @agent-native/core/feature-flags. That barrel is server evaluation (isFeatureFlagEnabled) plus store code; Vite will follow it into the browser and crash the page. Plugin and A2A auth helpers live on @agent-native/core/server (or @agent-native/core/feature-flags/server).

Keys are immutable, never reused, and contain only letters, numbers, dots, underscores, or hyphens. Prefer a concise app-owned name. Do not create flag definitions or rollout rows from Analytics.

2. Register

Register app definitions from a Nitro plugin before actions are discovered. Do not add app-specific flags to a Core registry.

import { createFeatureFlagsPlugin } from "@agent-native/core/server";

import { FULL_APP_BUILDING } from "../../shared/feature-flags.js";

export default createFeatureFlagsPlugin({ flags: [FULL_APP_BUILDING] });

Definitions live in one process-wide registry (a globalThis symbol in feature-flags/registry.ts, like the labs registry). In local dev the plugin can load core from source while actions load the built package; a module-local map gave each copy its own registry, so get-feature-flags saw no definitions and every flag read as off. Keep the shared registry when touching that module.

3. Guard server and client

The server action is the enforcement boundary:

import { isFeatureFlagEnabled } from "@agent-native/core/feature-flags";

run: async (args, ctx) => {
  if (!(await isFeatureFlagEnabled(FULL_APP_BUILDING, ctx))) {
    throw new Error("Full app building is not enabled for this account.");
  }
  // guarded operation
}

Use the client hook only to hide or reveal hydrated UI:

import { useFeatureFlag } from "@agent-native/core/client/feature-flags";

const enabled = useFeatureFlag(FULL_APP_BUILDING.key);
return enabled ? <FullAppOption /> : null;

The client hook intentionally returns false while loading or for an unknown flag. Never replace that fail-closed behavior with app-local bucketing or a compile-time fallback. When the flag-off UI must not flash before the answer arrives (a whole page swaps on the flag), use useFeatureFlagState(key): it returns { status: "loading" | "ready" | "unavailable", enabled }, so the surface can hold a layout-matching skeleton while status is "loading". Never evaluate personalized flags in the public SSR shell; it is shared and cached for every visitor.

4. Verify and roll out

  1. Verify the off path before changing rollout state.
  2. Confirm the registered flag appears in Analytics → Feature flags for the app and is Off by default.
  3. Use Enable for me for initial production dogfood.
  4. Expand to exact emails, organization IDs, or a percentage only from Analytics.
  5. Confirm the client presentation and authoritative server action agree.

Management contract

Core mounts three actions in registered apps:

Action Purpose
get-feature-flags Return the current caller's evaluated boolean values.
list-feature-flags Return definitions and rollout metadata to an authorized operator.
`set-fea
Câu hỏi thường gặp

Flag có thể bảo vệ các tính năng bảo mật không?

Không. Skill nói flag không được bảo vệ xác thực, phân quyền, bí mật hoặc cài đặt audit.

Flag có giống thử nghiệm không?

Không. Skill nói flag là công tắc bật tắt, không phải thử nghiệm với biến thể hay chỉ số.

Ẩn một nút trên giao diện có tắt tính năng không?

Không. Skill nói việc ẩn ở phía client chỉ là trình bày, và máy chủ phải kiểm tra cùng flag đó.

Chi tiết

Mô tả gốc của tác giả

Declare, evaluate, manage, and remove framework feature flags. Use when shipping a capability gradually, targeting users or organizations, or replacing a compile-time rollout switch with a production-safe runtime flag.

repo: BuilderIO/agent-native

Độ phổ biến

Sao GitHub
7.6k
Vị trí xếp hạng
#13159
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự