diff --git a/.changeset/cli-rules-plain-wording.md b/.changeset/cli-rules-plain-wording.md new file mode 100644 index 00000000..68fd3d0b --- /dev/null +++ b/.changeset/cli-rules-plain-wording.md @@ -0,0 +1,5 @@ +--- +"@reflag/cli": patch +--- + +Rewrite the coding-agent rules from `reflag rules` in plain language, cover React Native, and note that `fallbackFlags` is replaced by read defaults. diff --git a/packages/cli/services/rules.ts b/packages/cli/services/rules.ts index 3416da98..a2d6efac 100644 --- a/packages/cli/services/rules.ts +++ b/packages/cli/services/rules.ts @@ -1,7 +1,7 @@ export function getCursorRules() { return ` --- -description: Guidelines for Reflag SDK v2 direct-value flags +description: Guidelines for reading Reflag flags with SDK v2 globs: "**/*.ts, **/*.tsx, **/*.js, **/*.jsx, **/*.vue" --- @@ -16,22 +16,22 @@ export function getCopilotInstructions() { const rules = /* markdown */ ` # Reflag SDK v2 -These instructions apply to Node, Browser, React, and Vue SDK v2. Native and OpenFeature integrations may still use SDK v1; do not mix their declarations or bootstrap formats with v2. +These instructions apply to the Node.js, Browser, React, Vue and React Native SDKs, version 2. The OpenFeature providers still use SDK v1; don't mix their code or generated types with v2. -## Direct-value reads +## Reading flags -- Singular reads return the selected JSON value, not a flag wrapper. Do not use flag .isEnabled, .config.payload, .value, .track(), or feedback methods. Vue's .value is the normal ref API, not a flag wrapper. -- A read without a default requests Boolean with implicit false, even when generated types register a JSON flag. Generated types do not change runtime read categories. -- For other values, pass a JSON default immediately after the key. It selects the top-level category and supplies missing/mismatched-value fallback behavior. -- Non-null defaults must match the registered value schema, if types are generated. Without registration, return types are inferred from the default. Literal values widen, and readonly defaults produce mutable results. -- Explicit null requests arbitrary JSON and returns FlagValue; narrow or validate it before using object properties. It is not a request for a null-only value. -- Preserve authored false, zero, empty strings, empty arrays, and null. Do not substitute defaults with truthiness checks. -- Defaults must be ordinary JSON: no functions, Dates, undefined, or cycles. Objects and arrays returned by the SDK are independent mutable copies. -- Runtime category checks are not nested schema validation. Generated declarations are a snapshot inferred from authored variants; regenerate when flags change and validate externally when stronger runtime guarantees are needed. +- A flag read returns the flag's value. There's no flag object: don't use .isEnabled, .config, .payload, .track() or feedback methods on the result. In Vue, .value is the normal ref API. +- Without a default, a read expects a Boolean and returns false when the flag is missing or not a Boolean. +- For other values, pass a default after the key, such as useFlag("huddle-settings", { tokens: 128, model: "quick" }). The default sets the expected JSON type and is returned while flags load, when the flag has no value, or when the value has a different JSON type. +- Pass null as the default to accept any JSON value, then check its type before using it. +- Use the value as returned. Don't replace false, 0, empty strings or null with your default using truthiness checks such as value || fallback. +- Defaults must be plain JSON: no functions, Dates, undefined or circular references. +- The SDK checks only the top-level JSON type. It doesn't check object fields or fill in missing fields from your default, so validate nested values yourself when it matters. +- There's no fallbackFlags option. To choose the value used when flags can't be fetched, pass it as the read's default. -## Generated declarations +## Generated types -Use reflag flags types after configuring the project. This CLI targets SDK v2 and loads the current production-environment variants through the management flag API. It does not generate legacy remote-config wrappers. +After configuring the project, run reflag flags types to generate declarations from your flags. Regenerate them when flags change. Declarations are checked at compile time only. Example generated shape: @@ -47,7 +47,7 @@ declare module "@reflag/react-sdk" { ## React -Configure ReflagProvider with the publishable key and appropriate user/company context. Never expose a secret key in browser code. +Wrap the app in ReflagProvider with the publishable key and the user and company context. Never put a secret key in browser code. \`\`\`tsx import { useFlag } from "@reflag/react-sdk"; @@ -60,11 +60,11 @@ function HuddleButton() { } \`\`\` -useFlag is non-suspending. Use useFlagSuspense explicitly inside a React Suspense boundary when initialization must complete before reading. Use separate useTrack and feedback hooks rather than methods on flag results. +useFlag never suspends. Use useFlagSuspense inside a Suspense boundary to wait for flags. Use useTrack and useSendFeedback for tracking and feedback. -## Node +## Node.js -Initialize the client, then supply context directly or bind a context-specific client. Defaults are the third argument to an unbound getFlag and the second argument to bound or remote getters. +Initialize the client, then pass the context with each read or bind a client to it. The default is the third argument to client.getFlag and the second argument to a bound client's getFlag. \`\`\`typescript import { ReflagClient } from "@reflag/node-sdk"; @@ -77,15 +77,15 @@ const bound = client.bindClient(context); const settings = bound.getFlag("huddle-settings", { tokens: 128, model: "quick" }); \`\`\` -Use getFlagRemote for explicit remote evaluation. getFlags returns a record of values that may be undefined; reading a complete record is not a replacement for choosing a singular read's category/default. +Use getFlagRemote to evaluate on Reflag's servers instead. getFlags returns every flag's value, and missing flags are undefined, so prefer getFlag with a default for individual flags. ## Vue and Browser -Vue useFlag has the same default rules and returns a ref; access settings.value.model for an object-valued ref. Browser client.getFlag(key, defaultValue) returns a direct value, not a ref or wrapper. +Vue's useFlag takes the same defaults and returns a ref; read settings.value.model for an object flag. The Browser SDK's client.getFlag(key, defaultValue) returns the value itself. ## Further resources - [Documentation](https://docs.reflag.com) - [Repository](https://github.com/reflagcom/javascript) -- Prefer the installed package README and declarations for the exact SDK version in use. +- Prefer the installed package's README and type declarations for the exact SDK version in use. `.trim(); diff --git a/packages/cli/test/rules.test.ts b/packages/cli/test/rules.test.ts index 856ca3f0..019891be 100644 --- a/packages/cli/test/rules.test.ts +++ b/packages/cli/test/rules.test.ts @@ -4,7 +4,7 @@ import { getCopilotInstructions, getCursorRules } from "../services/rules.js"; import { flagUrl } from "../utils/urls.js"; describe("v2 workflow helpers", () => { - it("ships matching direct-value guidance for supported coding-agent formats", () => { + it("ships matching flag-read guidance for supported coding-agent formats", () => { const rules = getCopilotInstructions(); expect(getCursorRules()).toContain(rules); expect(rules).toContain( @@ -12,7 +12,8 @@ describe("v2 workflow helpers", () => { ); expect(rules).toContain('client.getFlag(context, "huddles")'); expect(rules).toContain("reflag flags types"); - expect(rules).toContain("not nested schema validation"); + expect(rules).toContain("doesn't check object fields"); + expect(rules).not.toMatch(/direct-value|fallbackFlags:/i); expect(rules).not.toMatch( /client\.(isEnabled|getConfig|setContext|trackEvent)\(/, );