@wangs-ui/skills 1.3.0-alpha.2 → 1.3.0-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +15 -11
  2. package/dist/bin.js +20 -15
  3. package/dist/index.js +2 -2
  4. package/dist/rules/wangs-ui/default-props-precedence.md +14 -0
  5. package/dist/rules/wangs-ui/forms-destructuring-lock.md +19 -0
  6. package/dist/rules/wangs-ui/no-raw-html.md +29 -0
  7. package/dist/rules/wangs-ui/no-redundant-wrappers.md +56 -0
  8. package/dist/rules/wangs-ui/react19-checklist-and-reference.md +38 -0
  9. package/dist/rules/wangs-ui/react19-compiler-render-patterns.md +13 -0
  10. package/dist/rules/wangs-ui/react19-naming-conventions.md +16 -0
  11. package/dist/rules/wangs-ui/react19-no-manual-memoization.md +28 -0
  12. package/dist/rules/wangs-ui/react19-primitives-typing.md +85 -0
  13. package/dist/rules/wangs-ui/react19-props-typing.md +25 -0
  14. package/dist/rules/wangs-ui/react19-purity-and-immutability.md +41 -0
  15. package/dist/rules/wangs-ui/react19-tooling-and-opt-out.md +78 -0
  16. package/dist/rules/wangs-ui/theme-variable-override-breaks-engine.md +20 -0
  17. package/dist/rules/wangs-ui/typescript-assertions-last-resort.md +13 -0
  18. package/dist/rules/wangs-ui/typescript-checklist-and-reference.md +34 -0
  19. package/dist/rules/wangs-ui/typescript-discriminated-unions.md +40 -0
  20. package/dist/rules/wangs-ui/typescript-explicit-return-types.md +22 -0
  21. package/dist/rules/wangs-ui/typescript-interface-vs-type.md +40 -0
  22. package/dist/rules/wangs-ui/typescript-literal-unions-vs-enums.md +22 -0
  23. package/dist/rules/wangs-ui/typescript-naming-conventions.md +24 -0
  24. package/dist/rules/wangs-ui/typescript-narrowing-over-casting.md +44 -0
  25. package/dist/rules/wangs-ui/typescript-readonly-by-default.md +24 -0
  26. package/dist/rules/wangs-ui/typescript-tsconfig-strictness.md +31 -0
  27. package/dist/rules/wangs-ui/typescript-zero-any.md +37 -0
  28. package/dist/skills/wangs-ui/craft-theme/SKILL.md +63 -0
  29. package/dist/skills/{create-form → wangs-ui/create-form}/SKILL.md +27 -16
  30. package/{skills → dist/skills/wangs-ui}/data-table/SKILL.md +24 -15
  31. package/{skills → dist/skills/wangs-ui}/dialog-modal/SKILL.md +18 -9
  32. package/{skills → dist/skills/wangs-ui}/i18n-usage/SKILL.md +19 -11
  33. package/dist/skills/wangs-ui/layout-navigation/SKILL.md +156 -0
  34. package/dist/skills/wangs-ui/responsive-design/SKILL.md +107 -0
  35. package/dist/skills/wangs-ui/universal-layout/SKILL.md +80 -0
  36. package/dist/skills/wangs-ui/wangs-ui-components/SKILL.md +104 -0
  37. package/dist/src-C0l8elLu.js +663 -0
  38. package/package.json +3 -2
  39. package/rules/wangs-ui/default-props-precedence.md +14 -0
  40. package/rules/wangs-ui/forms-destructuring-lock.md +19 -0
  41. package/rules/wangs-ui/no-raw-html.md +29 -0
  42. package/rules/wangs-ui/no-redundant-wrappers.md +56 -0
  43. package/rules/wangs-ui/react19-checklist-and-reference.md +38 -0
  44. package/rules/wangs-ui/react19-compiler-render-patterns.md +13 -0
  45. package/rules/wangs-ui/react19-naming-conventions.md +16 -0
  46. package/rules/wangs-ui/react19-no-manual-memoization.md +28 -0
  47. package/rules/wangs-ui/react19-primitives-typing.md +85 -0
  48. package/rules/wangs-ui/react19-props-typing.md +25 -0
  49. package/rules/wangs-ui/react19-purity-and-immutability.md +41 -0
  50. package/rules/wangs-ui/react19-tooling-and-opt-out.md +78 -0
  51. package/rules/wangs-ui/theme-variable-override-breaks-engine.md +20 -0
  52. package/rules/wangs-ui/typescript-assertions-last-resort.md +13 -0
  53. package/rules/wangs-ui/typescript-checklist-and-reference.md +34 -0
  54. package/rules/wangs-ui/typescript-discriminated-unions.md +40 -0
  55. package/rules/wangs-ui/typescript-explicit-return-types.md +22 -0
  56. package/rules/wangs-ui/typescript-interface-vs-type.md +40 -0
  57. package/rules/wangs-ui/typescript-literal-unions-vs-enums.md +22 -0
  58. package/rules/wangs-ui/typescript-naming-conventions.md +24 -0
  59. package/rules/wangs-ui/typescript-narrowing-over-casting.md +44 -0
  60. package/rules/wangs-ui/typescript-readonly-by-default.md +24 -0
  61. package/rules/wangs-ui/typescript-tsconfig-strictness.md +31 -0
  62. package/rules/wangs-ui/typescript-zero-any.md +37 -0
  63. package/skills/wangs-ui/craft-theme/SKILL.md +63 -0
  64. package/skills/{create-form → wangs-ui/create-form}/SKILL.md +27 -16
  65. package/{dist/skills → skills/wangs-ui}/data-table/SKILL.md +24 -15
  66. package/{dist/skills → skills/wangs-ui}/dialog-modal/SKILL.md +18 -9
  67. package/{dist/skills → skills/wangs-ui}/i18n-usage/SKILL.md +19 -11
  68. package/skills/wangs-ui/layout-navigation/SKILL.md +156 -0
  69. package/skills/wangs-ui/responsive-design/SKILL.md +107 -0
  70. package/skills/wangs-ui/universal-layout/SKILL.md +80 -0
  71. package/skills/wangs-ui/wangs-ui-components/SKILL.md +104 -0
  72. package/dist/skills/layout-navigation/SKILL.md +0 -62
  73. package/dist/skills/react19-compiler-typescript/SKILL.md +0 -388
  74. package/dist/skills/typescript-strict-typing/SKILL.md +0 -317
  75. package/dist/skills/wangs-ui-components/SKILL.md +0 -108
  76. package/dist/src-DDi-O7tk.js +0 -246
  77. package/skills/layout-navigation/SKILL.md +0 -62
  78. package/skills/react19-compiler-typescript/SKILL.md +0 -388
  79. package/skills/typescript-strict-typing/SKILL.md +0 -317
  80. package/skills/wangs-ui-components/SKILL.md +0 -108
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wangs-ui/skills",
3
- "version": "1.3.0-alpha.2",
3
+ "version": "1.3.0-alpha.20",
4
4
  "description": "CLI to install, update, and manage modular AI agent skills for Wangs UI React applications",
5
5
  "keywords": [
6
6
  "agents",
@@ -29,7 +29,8 @@
29
29
  },
30
30
  "files": [
31
31
  "dist",
32
- "skills"
32
+ "skills",
33
+ "rules"
33
34
  ],
34
35
  "type": "module",
35
36
  "sideEffects": false,
@@ -0,0 +1,14 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when deciding whether a prop belongs in global defaultProps config or per-instance JSX."
4
+ owner: wangs-ui
5
+ metadata:
6
+ owner: wangs-ui
7
+ ---
8
+ # Wangs UI Fact: `configOptions.defaultProps` Precedence
9
+
10
+ `WangsUiProvider.configOptions.defaultProps` lets any project set global
11
+ default prop values per component. Per-instance JSX props always win over
12
+ that global default — the merge order is global-default-then-instance, never
13
+ the reverse. This is a `WangsUiProvider` mechanism, true in any project that
14
+ uses it, independent of what values a given project actually configures.
@@ -0,0 +1,19 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when writing a <Field> render-prop callback in a Wangs UI Form/DialogForm."
4
+ owner: wangs-ui
5
+ metadata:
6
+ owner: wangs-ui
7
+ ---
8
+ # Wangs UI Fact: `<Field>` Render-Prop Must Destructure `{ fieldProps, fieldState }`
9
+
10
+ `<Field>`'s callback render prop must destructure as `{({ fieldProps, fieldState })}`.
11
+ Passing a single parameter instead (`{(field) => ...}`) produces `undefined`
12
+ `value`/`onChange` and permanently locks the input — the field never becomes
13
+ interactive, even on initial render. This is a real `@wangs-ui/form` quirk,
14
+ not a project convention; it reproduces the same way in any consumer.
15
+
16
+ `<Field>` is generic — `fieldProps.onChange` is already typed to the field's
17
+ actual value type. Pass it straight through (`fieldProps.onChange`); don't
18
+ wrap it in a defensive `typeof`/`e?.target?.value` extraction, that's fighting
19
+ a type the field already guarantees.
@@ -0,0 +1,29 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when writing JSX markup — enforce Wangs UI primitives over raw HTML elements."
4
+ owner: wangs-ui
5
+ metadata:
6
+ owner: wangs-ui
7
+ ---
8
+ # Rule: No Raw HTML Controls
9
+
10
+ Zero raw HTML elements. Use Wangs UI primitives and Foundation theme typography.
11
+
12
+ ## Prohibitions
13
+
14
+ - No `<button>`, `<input>`, `<select>`, `<textarea>`, `<form>`, `<table>`, `<dialog>`.
15
+ - No `<h1>`-`<h6>`, `<p>`, `<span>` for text typography without Wangs UI theme primitives.
16
+
17
+ ## Mandatory Imports
18
+
19
+ - Primitives via subpath:
20
+ - `@wangs-ui/react-core/primitive/button`
21
+ - `@wangs-ui/react-core/primitive/input`
22
+ - `@wangs-ui/react-core/primitive/datatable`
23
+ - `@wangs-ui/react-core/primitive/modal`
24
+ - `@wangs-ui/react-core/primitive/dialogform`
25
+ - `@wangs-ui/react-core/primitive/card`
26
+ - `@wangs-ui/react-core/primitive/badge`
27
+ - Typography via Foundation theme:
28
+ - `@wangs-ui/foundation/theme` (`Text`, `Code`, `Kbd`, `Link`, `Mark`, `Blockquote`, `List`)
29
+ - Use variants: `display*`, `headline*`, `title*`, `body*`, `label*`.
@@ -0,0 +1,56 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when writing or reviewing JSX layout for redundant wrapper containers."
4
+ owner: wangs-ui
5
+ metadata:
6
+ owner: wangs-ui
7
+ ---
8
+ # Rule: No Redundant Layout & Container Wrappers
9
+
10
+ > **Severity**: **ARCHITECTURAL CODE SMELL / LINT FAILURE**.
11
+
12
+ Components must not be wrapped in an unnecessary layout element. A `<div>` (or `Box`/`Stack`) wrapping a single component without active layout coordination is strictly prohibited — see `.agents/skills/universal-layout` and `.agents/rules/no-inline-component-styling.md` §2 for which primitive replaces a raw `<div>` when layout coordination is genuinely needed.
13
+
14
+ ---
15
+
16
+ ## 1. Prohibited Anti-Patterns
17
+
18
+ 1. **Single-Child Wrapper `<div>`**:
19
+ Never wrap a single component (e.g. `<DataTable />`, `<Card />`, `<Tabs />`, `<Input />`, `<Button />`) inside an isolated `<div>` that has no layout siblings.
20
+ 2. **Intermediate Tab/Card Wrappers**:
21
+ Do not insert pass-through `<div>` wrappers between `<Card>`/`<Tabs>` and feature content:
22
+ ```tsx
23
+ // ❌ Bad — Redundant intermediate div wrapping a single tab component
24
+ function TabbedPage() {
25
+ return (
26
+ <Card>
27
+ <Tabs ... />
28
+ <div>
29
+ {activeTab === 'general' ? <GeneralTab /> : <AdvancedTab />}
30
+ </div>
31
+ </Card>
32
+ );
33
+ }
34
+
35
+ // ✅ Good — Render active tab directly as Card child
36
+ function TabbedPage() {
37
+ return (
38
+ <Card>
39
+ <Tabs ... />
40
+ {activeTab === 'general' ? <GeneralTab /> : <AdvancedTab />}
41
+ </Card>
42
+ );
43
+ }
44
+ ```
45
+ 3. **Redundant Table Wrappers**:
46
+ Never wrap `<DataTable />` in a `Box`/`div` solely to set width or margin. Wangs UI DataTable manages its own container scroll and dimensions out of the box.
47
+
48
+ ---
49
+
50
+ ## 2. When a Layout Wrapper Is Permitted
51
+
52
+ A layout wrapper is **ONLY** warranted when coordinating **2 or more siblings** in a structural layout — and even then it's a `universal-layout` primitive, not a raw `<div>`:
53
+
54
+ 1. **Alignment bars**: header title + search + action buttons → `<HStack justify="between">`.
55
+ 2. **Multi-column/card grids**: responsive multi-card or multi-field layouts → `<Grid columns={{ compact: 1, medium: 2, expanded: 3 }}>`.
56
+ 3. **Fragment Alternative**: when returning multiple adjacent elements without layout coordination, use React Fragment (`<>...</>`) — not an empty wrapper.
@@ -0,0 +1,38 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when doing a final review pass on React 19 component or hook code for compiler-optimization compliance."
4
+ owner: wangs-ui
5
+ metadata:
6
+ owner: wangs-ui
7
+ ---
8
+ # Rule: React 19 — Review Checklist & Quick Reference
9
+
10
+ ## Checking Compiler Optimization
11
+
12
+ - **Build output** — compiled files import `react/compiler-runtime` and contain `Symbol.for("react.memo_cache_sentinel")`; if absent, the compiler never ran.
13
+ - **ESLint / Oxlint** — compiler's recommended rules flag Rules-of-React violations at lint time.
14
+
15
+ ## Review Checklist
16
+
17
+ - [ ] Compiler is wired up and confirmed active — set it up if missing (see `react19-tooling-and-opt-out.md`); never treat a missing compiler as licence to hand-roll memoization
18
+ - [ ] Compiler confirmed active (build output imports `react/compiler-runtime`) before removing any _existing_ manual memoization
19
+ - [ ] No new `useMemo`/`useCallback`/`React.memo` added without documented reason (confirmed bail-out, or external boundary)
20
+ - [ ] No prop/state/context mutation anywhere in render
21
+ - [ ] All hooks called unconditionally at top level, same order every render
22
+ - [ ] Side effects live in `useEffect`/event handlers, never during render
23
+ - [ ] Components are `PascalCase`; hooks are `camelCase` and prefixed `use`
24
+ - [ ] `ref` accepted as normal prop instead of `forwardRef`
25
+ - [ ] Action/optimistic-update state modeled as discriminated union, not optional fields
26
+ - [ ] Mutually exclusive prop combinations modeled as discriminated union `Props` type
27
+ - [ ] Any `"use no memo"` usage has a comment explaining why
28
+
29
+ ## Quick Reference
30
+
31
+ | Situation | Do |
32
+ | ----------------------------------------------------------- | ------------------------------------------------------------- |
33
+ | Tempted to write `useMemo`/`useCallback` | Don't — write plain expression, let compiler decide |
34
+ | Need a ref on a function component | Accept `ref` as a prop, skip `forwardRef` |
35
+ | Form/async state with distinct outcomes | Discriminated union via `useActionState`, not optional fields |
36
+ | Callback needs latest props/state without re-running effect | `useEffectEvent` |
37
+ | A hook/library is known-incompatible with compiler | `"use no memo"` at top of that function, with comment |
38
+ | Checking if optimization is happening | Build output imports `react/compiler-runtime` (has `react.memo_cache_sentinel`) + compiler lint rules |
@@ -0,0 +1,13 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when writing or reviewing render logic in a React 19 component."
4
+ owner: wangs-ui
5
+ metadata:
6
+ owner: wangs-ui
7
+ ---
8
+ # Rule: React 19 — Compiler-Friendly Render Patterns
9
+
10
+ - Creating new object/array/function literals inline in render (`style={{ color }}`, `onClick={() => ...}`) is fine — stop manually hoisting or `useMemo`-wrapping these preemptively; the compiler memoizes them if it determines it's worthwhile.
11
+ - Avoid module-level mutable variables read or written during render — that state is invisible to the compiler and breaks idempotence.
12
+ - Don't use `useRef` to store a value that should trigger a re-render when it changes — refs are an imperative escape hatch, not state, and the compiler treats them as such.
13
+ - Keep components small and composable. The compiler optimizes per component/hook boundary, so a single 300-line component gives it far less to work with than several focused ones.
@@ -0,0 +1,16 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when naming a React 19 component, hook, or prop."
4
+ owner: wangs-ui
5
+ metadata:
6
+ owner: wangs-ui
7
+ ---
8
+ # Rule: React 19 — Naming Conventions
9
+
10
+ The compiler identifies what to optimize by naming heuristics, same as the Rules of Hooks linter:
11
+
12
+ | Kind | Convention | Notes |
13
+ | ------------------------------------------------------------------------ | ------------------------------- | ----------------------------------------------------------------------------- |
14
+ | Components | `PascalCase`, returns JSX | Compiler treats it as a component to optimize |
15
+ | Custom hooks | `camelCase`, prefixed `use` | Required for both Rules-of-Hooks lint and compiler analysis |
16
+ | Plain helper functions that return JSX-like values but aren't components | Avoid `PascalCase`/`use` naming | Prevents the compiler (and other devs) from mistaking it for a component/hook |
@@ -0,0 +1,28 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when writing or reviewing a React 19 component or hook that uses or is tempted to use useMemo/useCallback/React.memo."
4
+ owner: wangs-ui
5
+ metadata:
6
+ owner: wangs-ui
7
+ ---
8
+ # Rule: React 19 — Stop Hand-Rolling Memoization
9
+
10
+ > **Prerequisite:** this rule holds only once the React Compiler is enabled. If the project isn't wired up yet, set it up first (see `react19-tooling-and-opt-out.md`) — the absence of the compiler is never a reason to hand-roll memoization.
11
+
12
+ Don't reach for `useMemo`, `useCallback`, or `React.memo` — the compiler adds this automatically wherever it determines it helps. This is a requirement, not a stylistic preference: manual memoization is the exception and must be justified.
13
+
14
+ ```tsx
15
+ // ❌ Old habit — noisy, and a mismatched dependency array is a whole class of bugs
16
+ const filteredUsers = useMemo(() => users.filter((u) => u.isActive), [users]);
17
+ const handleClick = useCallback(() => onSelect(user.id), [onSelect, user.id]);
18
+
19
+ // ✅ New default — just write the logic; the compiler memoizes what's worth memoizing
20
+ const filteredUsers = users.filter((u) => u.isActive);
21
+ const handleClick = () => onSelect(user.id);
22
+ ```
23
+
24
+ ## When manual memoization is still justified:
25
+
26
+ - You've **confirmed a compiler bail-out** on a genuine hot path via profiling, and fixing the underlying Rules-of-React violation isn't possible right now.
27
+ - A value must have **stable referential identity across a boundary the compiler can't see** — e.g. passed into a non-React library, a WebSocket subscription, or a third-party hook incompatible with the compiler (`react-hook-form`'s `useForm`, `@tanstack/react-table`'s `useReactTable` are known cases).
28
+ - Keep any manual memoization it produces isolated and commented with _why_, so it doesn't silently rot into a bail-out later when the code around it changes.
@@ -0,0 +1,85 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when typing React 19 primitives — ref props, useActionState, useOptimistic, use(), useEffectEvent."
4
+ owner: wangs-ui
5
+ metadata:
6
+ owner: wangs-ui
7
+ ---
8
+ # Rule: React 19 — Typing React 19 Primitives
9
+
10
+ ## `ref` as a Normal Prop
11
+
12
+ `forwardRef` is no longer required for most cases; function components accept `ref` directly.
13
+
14
+ ```tsx
15
+ type InputProps = {
16
+ ref?: React.Ref<HTMLInputElement>;
17
+ placeholder?: string;
18
+ };
19
+
20
+ function TextInput({ ref, placeholder }: InputProps) {
21
+ return <input ref={ref} placeholder={placeholder} />;
22
+ }
23
+ ```
24
+
25
+ ## Actions with `useActionState`
26
+
27
+ Type the state and payload as generics; model the result as a discriminated union rather than optional fields.
28
+
29
+ ```tsx
30
+ type FormState = { status: 'idle' } | { status: 'error'; message: string } | { status: 'success' };
31
+
32
+ const [state, formAction, isPending] = useActionState<FormState, FormData>(
33
+ async (_previous, formData) => {
34
+ const email = formData.get('email');
35
+ if (typeof email !== 'string' || !email.includes('@')) {
36
+ return { status: 'error', message: 'Invalid email' };
37
+ }
38
+ await submit(email);
39
+ return { status: 'success' };
40
+ },
41
+ { status: 'idle' },
42
+ );
43
+ ```
44
+
45
+ ## Optimistic Updates with `useOptimistic`
46
+
47
+ Type both the state and the update shape.
48
+
49
+ ```tsx
50
+ const [optimisticTodos, addOptimisticTodo] = useOptimistic<Todo[], Todo>(
51
+ todos,
52
+ (state, newTodo) => [...state, newTodo],
53
+ );
54
+ ```
55
+
56
+ ## Reading Promises or Context with `use()`
57
+
58
+ Type the resolved value, not the promise wrapper; `use()` is not a hook and may be called conditionally.
59
+
60
+ ```tsx
61
+ function Comments({ commentsPromise }: { commentsPromise: Promise<Comment[]> }) {
62
+ const comments = use(commentsPromise); // suspends until resolved
63
+ return (
64
+ <ul>
65
+ {comments.map((c) => (
66
+ <li key={c.id}>{c.text}</li>
67
+ ))}
68
+ </ul>
69
+ );
70
+ }
71
+ ```
72
+
73
+ ## Stable Event Callbacks with `useEffectEvent` (React 19.2+)
74
+
75
+ Separates "event" logic from "reactive" effect logic so the callback always sees latest props/state without being listed as an effect dependency.
76
+
77
+ ```tsx
78
+ const onVisit = useEffectEvent((url: string) => {
79
+ logVisit(url, theme); // always fresh `theme`, never re-triggers the effect
80
+ });
81
+
82
+ useEffect(() => {
83
+ onVisit(url);
84
+ }, [url]); // `theme` intentionally omitted — onVisit is stable
85
+ ```
@@ -0,0 +1,25 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when defining a component's Props type or interface."
4
+ owner: wangs-ui
5
+ metadata:
6
+ owner: wangs-ui
7
+ ---
8
+ # Rule: React 19 — Typing Props
9
+
10
+ - `interface` for a component's `Props` — it's an entity shape, often extended.
11
+ - A discriminated union when a component has mutually exclusive prop combinations, instead of a pile of optional props that can contradict each other.
12
+
13
+ ```tsx
14
+ // ❌ Bad — nothing stops passing both `href` and `onClick` incoherently
15
+ interface ButtonProps {
16
+ label: string;
17
+ href?: string;
18
+ onClick?: () => void;
19
+ }
20
+
21
+ // ✅ Good — the two variants can't be mixed
22
+ type ButtonProps =
23
+ | { variant: 'link'; label: string; href: string }
24
+ | { variant: 'action'; label: string; onClick: () => void };
25
+ ```
@@ -0,0 +1,41 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when writing or reviewing a React 19 component or hook body for purity and immutability."
4
+ owner: wangs-ui
5
+ metadata:
6
+ owner: wangs-ui
7
+ ---
8
+ # Rule: React 19 — Purity and Immutability (Load-Bearing)
9
+
10
+ The compiler assumes your components and hooks are pure. Violating these rules causes the compiler to silently skip optimizing that component:
11
+
12
+ - **Idempotent renders** — given the same props/state/context, a component must return the same output. No random values, no `Date.now()`, no side effects during render.
13
+ - **Immutability** — never mutate props, state, or context directly. Always create new objects/arrays for changes.
14
+ - **Side effects only in effects or event handlers** — never during render.
15
+ - **Hooks called unconditionally, top-level, same order every render** — no hooks inside conditionals, loops, or nested functions.
16
+
17
+ ```tsx
18
+ // ❌ Mutates a prop — breaks purity and the compiler can't safely memoize this
19
+ function TodoList({ todos }: { todos: Todo[] }) {
20
+ todos.sort((a, b) => a.priority - b.priority); // mutates caller's array
21
+ return (
22
+ <ul>
23
+ {todos.map((t) => (
24
+ <li key={t.id}>{t.title}</li>
25
+ ))}
26
+ </ul>
27
+ );
28
+ }
29
+
30
+ // ✅ Creates a new array — pure, compiler-safe
31
+ function TodoList({ todos }: { todos: Todo[] }) {
32
+ const sorted = [...todos].sort((a, b) => a.priority - b.priority);
33
+ return (
34
+ <ul>
35
+ {sorted.map((t) => (
36
+ <li key={t.id}>{t.title}</li>
37
+ ))}
38
+ </ul>
39
+ );
40
+ }
41
+ ```
@@ -0,0 +1,78 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: 'Apply when configuring React Compiler tooling or opting a component out via "use no memo".'
4
+ owner: wangs-ui
5
+ metadata:
6
+ owner: wangs-ui
7
+ ---
8
+ # Rule: React 19 — Tooling Setup & Compiler Opt-Out
9
+
10
+ ## Compiler Setup Is Mandatory
11
+
12
+ **The compiler is required, not opt-in.** Every Wangs UI project must run it. The entire "write plain code, no manual memoization" rule set only holds once the compiler is actually active, so wiring it up is a prerequisite — not an optional enhancement.
13
+
14
+ Plain `@vitejs/plugin-react` (`react()`), plain Next.js, plain Babel/webpack config, etc. do **not** run the compiler on their own. **Verify it is active before assuming manual memoization can be dropped — and if it isn't wired up, set it up first** instead of falling back to hand-rolled `useMemo`/`useCallback`/`React.memo`.
15
+
16
+ ### Verify it's active
17
+
18
+ - The build passes the compiler preset through Babel, and `babel-plugin-react-compiler` is installed (e.g. `@vitejs/plugin-react`'s `reactCompilerPreset()` via `@rolldown/plugin-babel`).
19
+ - The build output actually contains compiler artifacts — `import { c as _c } from "react/compiler-runtime"` and `Symbol.for("react.memo_cache_sentinel")` in `dist`. Config being present is **not** proof it ran; the emitted output is.
20
+ - The `react/react-compiler` lint rule is enabled.
21
+
22
+ ### Setup (when missing)
23
+
24
+ ```bash
25
+ # Compiler (build-time transform)
26
+ pnpm add -D --save-exact babel-plugin-react-compiler@latest
27
+ ```
28
+
29
+ ### Lint rules — oxlint
30
+
31
+ Oxlint ships a **native, Rust-based** `react/react-compiler` rule:
32
+
33
+ ```json
34
+ // .oxlintrc.json
35
+ {
36
+ "plugins": ["react"],
37
+ "rules": {
38
+ "react/react-compiler": "error"
39
+ }
40
+ }
41
+ ```
42
+
43
+ This single rule reports:
44
+
45
+ - **Rules-of-React violations** (conditional hooks, reading a ref during render, mutating props) — must-fix bugs.
46
+ - **Compiler bail-outs** — places compiler declined to optimize without rule violation.
47
+
48
+ ### Wiring into Vite 8
49
+
50
+ ```ts
51
+ // vite.config.ts
52
+ import { defineConfig } from 'vite';
53
+ import react, { reactCompilerPreset } from '@vitejs/plugin-react';
54
+ import babel from '@rolldown/plugin-babel';
55
+
56
+ export default defineConfig({
57
+ plugins: [
58
+ babel({ presets: [reactCompilerPreset()] }), // must run before react()
59
+ react(),
60
+ ],
61
+ });
62
+ ```
63
+
64
+ ```bash
65
+ pnpm add -D @rolldown/plugin-babel @babel/core babel-plugin-react-compiler
66
+ ```
67
+
68
+ ## Incompatibility Escape Hatch (`"use no memo"`)
69
+
70
+ If a specific function is genuinely incompatible with compiler (e.g. calls `useForm` from `react-hook-form`), opt out with `"use no memo"` directive as **first line of function body** — leave a comment explaining why:
71
+
72
+ ```tsx
73
+ function LegacyForm() {
74
+ 'use no memo';
75
+ const form = useForm(); // incompatible with the compiler today
76
+ // ...
77
+ }
78
+ ```
@@ -0,0 +1,20 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when tempted to override a Wangs UI theme CSS variable directly."
4
+ owner: wangs-ui
5
+ metadata:
6
+ owner: wangs-ui
7
+ ---
8
+ # Wangs UI Fact: Theme Variables Are Engine-Internal, Never Override Directly
9
+
10
+ Manually defining or overriding `:root`, `[data-mode='dark']`, or `.dark` custom
11
+ properties owned by `@wangs-ui/foundation/theme` (`--color-*`, `--z-index-*`,
12
+ `--spacing-*`, `--size-*`, `--shadow-*`, `--radius-*`) breaks the theme token
13
+ engine: it destroys automatic light/dark mode transitions, corrupts sub-tree
14
+ density overrides made via `<ThemeProvider>`, and causes cross-module visual
15
+ bugs that don't reproduce consistently. This is true for any project consuming
16
+ `@wangs-ui/foundation`, not specific to one app's setup.
17
+
18
+ The supported customization surface is `WangsUiProvider.configOptions.preset`
19
+ — discover it via the `design-system`/`wangs-ui-components` skills' MCP calls,
20
+ never by reading or guessing the CSS variable names.
@@ -0,0 +1,13 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when writing or reviewing a type assertion (`as X`) or non-null assertion (`x!`)."
4
+ owner: wangs-ui
5
+ metadata:
6
+ owner: wangs-ui
7
+ ---
8
+ # Rule: TypeScript — Type Assertions & Non-Null Assertions are a Last Resort
9
+
10
+ - `as X` and `x!` tell the compiler "trust me" — they produce zero runtime safety and actively hide bugs if wrong.
11
+ - Acceptable only when the compiler genuinely cannot know something you do (e.g. a DOM query you've already null-checked, or narrowing a third-party type at a well-tested boundary) — and even then, prefer a type guard or a runtime check over a bare assertion.
12
+ - Never use `as any` or `as unknown as X` to force an incompatible cast — that's `any` wearing a disguise.
13
+ - `x!` should almost always be replaceable by an actual null check or optional chaining (`x?.y`) plus a real fallback.
@@ -0,0 +1,34 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when doing a final TypeScript review pass on a file."
4
+ owner: wangs-ui
5
+ metadata:
6
+ owner: wangs-ui
7
+ ---
8
+ # Rule: TypeScript — Review Checklist & Quick Reference
9
+
10
+ ## Review Checklist
11
+
12
+ Before considering TypeScript code "done," verify:
13
+
14
+ - [ ] No `any` anywhere (including implicit `any` from missing annotations)
15
+ - [ ] External/uncertain data enters as `unknown` and is narrowed before use
16
+ - [ ] Variant state is a discriminated union, not optional fields + booleans
17
+ - [ ] `interface` used for object/entity shapes; `type` used for unions/aliases/intersections
18
+ - [ ] No stray `I` prefixes on interfaces
19
+ - [ ] Naming follows casing conventions consistently
20
+ - [ ] `as` / `!` are rare, justified, and can't be replaced by a guard or null check
21
+ - [ ] Exported functions/methods have explicit return types
22
+ - [ ] Switch statements over unions have an exhaustiveness (`never`) check
23
+ - [ ] `tsconfig.json` includes the strictness baseline
24
+
25
+ ## Quick Reference
26
+
27
+ | Situation | Use |
28
+ | ---------------------------------------------- | ------------------------------------------------------------- |
29
+ | External/uncertain data | `unknown` + narrowing |
30
+ | "This value is definitely one of these shapes" | Discriminated union (`type`) |
31
+ | Object with identity, may be extended | `interface` |
32
+ | Union, intersection, tuple, mapped type | `type` |
33
+ | Need to prove a type through logic | Type guard / narrowing |
34
+ | Tempted to write `any` | Stop — use `unknown`, a generic, or a local interface instead |
@@ -0,0 +1,40 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when modeling a variant or multi-shape state in TypeScript."
4
+ owner: wangs-ui
5
+ metadata:
6
+ owner: wangs-ui
7
+ ---
8
+ # Rule: TypeScript — Discriminated Unions for Variant State
9
+
10
+ Whenever a value can be one of several distinct "shapes" (loading/success/error states, event types, API response variants), model it as a **discriminated union** with a literal tag field — never as a loose object with optional fields or boolean flags.
11
+
12
+ ```ts
13
+ // ❌ Bad — booleans can contradict each other; unclear which fields are valid together
14
+ interface FetchState {
15
+ isLoading: boolean;
16
+ isError: boolean;
17
+ data?: User;
18
+ error?: string;
19
+ }
20
+
21
+ // ✅ Good — only one shape is possible at a time, and the compiler enforces it
22
+ type FetchState =
23
+ | { status: 'idle' }
24
+ | { status: 'loading' }
25
+ | { status: 'success'; data: User }
26
+ | { status: 'error'; error: string };
27
+
28
+ function render(state: FetchState) {
29
+ switch (state.status) {
30
+ case 'success':
31
+ return state.data.name; // `data` is guaranteed to exist here
32
+ case 'error':
33
+ return state.error; // `error` is guaranteed to exist here
34
+ default:
35
+ return null;
36
+ }
37
+ }
38
+ ```
39
+
40
+ Use a consistent tag field name across a codebase (`kind`, `type`, or `status` — pick one and stick with it) so narrowing patterns stay predictable.
@@ -0,0 +1,22 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when writing or reviewing an exported function, class method, or public API surface in TypeScript."
4
+ owner: wangs-ui
5
+ metadata:
6
+ owner: wangs-ui
7
+ ---
8
+ # Rule: TypeScript — Explicit Return Types on Exported Functions
9
+
10
+ Inference is fine for local, private helpers, but exported functions, class methods, and anything forming a public API should declare an explicit return type. This prevents an internal implementation change from silently widening/narrowing the public contract.
11
+
12
+ ```ts
13
+ // ❌ Return type is inferred and can silently drift
14
+ export function getActiveUsers(users: User[]) {
15
+ return users.filter((u) => u.active);
16
+ }
17
+
18
+ // ✅ Explicit, intentional contract
19
+ export function getActiveUsers(users: User[]): User[] {
20
+ return users.filter((u) => u.active);
21
+ }
22
+ ```
@@ -0,0 +1,40 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when deciding between `interface` and `type` for a new TypeScript declaration."
4
+ owner: wangs-ui
5
+ metadata:
6
+ owner: wangs-ui
7
+ ---
8
+ # Rule: TypeScript — `interface` vs `type`
9
+
10
+ Both can describe object shapes, but they signal different intent. Default rule:
11
+
12
+ | Use `interface` for... | Use `type` for... |
13
+ | -------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
14
+ | Object / entity shapes (a `User`, a `Product`, a component's `Props`) | Unions (`"a" \| "b"`) and discriminated unions |
15
+ | Public API contracts meant to be `implements`-ed by classes | Intersections (`A & B`) |
16
+ | Shapes that consumers may want to **extend/augment** (declaration merging) | Tuples (`[string, number]`) |
17
+ | | Function types / callback signatures |
18
+ | | Mapped, conditional, or utility-derived types (`Partial<T>`, `Pick<T, K>`) |
19
+ | | Aliasing a primitive or another type for readability |
20
+
21
+ ```ts
22
+ // ✅ interface — an entity with identity, extendable
23
+ interface User {
24
+ id: string;
25
+ email: string;
26
+ role: UserRole;
27
+ }
28
+
29
+ interface AdminUser extends User {
30
+ permissions: Permission[];
31
+ }
32
+
33
+ // ✅ type — union, alias, derived shape
34
+ type UserRole = 'admin' | 'editor' | 'viewer';
35
+ type UserId = User['id'];
36
+ type PartialUser = Partial<User>;
37
+ type Callback<T> = (value: T) => void;
38
+ ```
39
+
40
+ Don't mix conventions arbitrarily within one file — if a shape is a plain data object that will never need a union/intersection, `interface` is the default; the moment it needs to express "one of several shapes," reach for `type`.