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

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 +13 -0
  5. package/dist/rules/wangs-ui/forms-destructuring-lock.md +18 -0
  6. package/dist/rules/wangs-ui/no-raw-html.md +28 -0
  7. package/dist/rules/wangs-ui/no-redundant-wrappers.md +55 -0
  8. package/dist/rules/wangs-ui/react19-checklist-and-reference.md +37 -0
  9. package/dist/rules/wangs-ui/react19-compiler-render-patterns.md +12 -0
  10. package/dist/rules/wangs-ui/react19-naming-conventions.md +15 -0
  11. package/dist/rules/wangs-ui/react19-no-manual-memoization.md +27 -0
  12. package/dist/rules/wangs-ui/react19-primitives-typing.md +84 -0
  13. package/dist/rules/wangs-ui/react19-props-typing.md +24 -0
  14. package/dist/rules/wangs-ui/react19-purity-and-immutability.md +40 -0
  15. package/dist/rules/wangs-ui/react19-tooling-and-opt-out.md +77 -0
  16. package/dist/rules/wangs-ui/theme-variable-override-breaks-engine.md +19 -0
  17. package/dist/rules/wangs-ui/typescript-assertions-last-resort.md +12 -0
  18. package/dist/rules/wangs-ui/typescript-checklist-and-reference.md +33 -0
  19. package/dist/rules/wangs-ui/typescript-discriminated-unions.md +39 -0
  20. package/dist/rules/wangs-ui/typescript-explicit-return-types.md +21 -0
  21. package/dist/rules/wangs-ui/typescript-interface-vs-type.md +39 -0
  22. package/dist/rules/wangs-ui/typescript-literal-unions-vs-enums.md +21 -0
  23. package/dist/rules/wangs-ui/typescript-naming-conventions.md +23 -0
  24. package/dist/rules/wangs-ui/typescript-narrowing-over-casting.md +43 -0
  25. package/dist/rules/wangs-ui/typescript-readonly-by-default.md +23 -0
  26. package/dist/rules/wangs-ui/typescript-tsconfig-strictness.md +30 -0
  27. package/dist/rules/wangs-ui/typescript-zero-any.md +36 -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-BFwMaU8I.js +663 -0
  38. package/package.json +3 -2
  39. package/rules/wangs-ui/default-props-precedence.md +13 -0
  40. package/rules/wangs-ui/forms-destructuring-lock.md +18 -0
  41. package/rules/wangs-ui/no-raw-html.md +28 -0
  42. package/rules/wangs-ui/no-redundant-wrappers.md +55 -0
  43. package/rules/wangs-ui/react19-checklist-and-reference.md +37 -0
  44. package/rules/wangs-ui/react19-compiler-render-patterns.md +12 -0
  45. package/rules/wangs-ui/react19-naming-conventions.md +15 -0
  46. package/rules/wangs-ui/react19-no-manual-memoization.md +27 -0
  47. package/rules/wangs-ui/react19-primitives-typing.md +84 -0
  48. package/rules/wangs-ui/react19-props-typing.md +24 -0
  49. package/rules/wangs-ui/react19-purity-and-immutability.md +40 -0
  50. package/rules/wangs-ui/react19-tooling-and-opt-out.md +77 -0
  51. package/rules/wangs-ui/theme-variable-override-breaks-engine.md +19 -0
  52. package/rules/wangs-ui/typescript-assertions-last-resort.md +12 -0
  53. package/rules/wangs-ui/typescript-checklist-and-reference.md +33 -0
  54. package/rules/wangs-ui/typescript-discriminated-unions.md +39 -0
  55. package/rules/wangs-ui/typescript-explicit-return-types.md +21 -0
  56. package/rules/wangs-ui/typescript-interface-vs-type.md +39 -0
  57. package/rules/wangs-ui/typescript-literal-unions-vs-enums.md +21 -0
  58. package/rules/wangs-ui/typescript-naming-conventions.md +23 -0
  59. package/rules/wangs-ui/typescript-narrowing-over-casting.md +43 -0
  60. package/rules/wangs-ui/typescript-readonly-by-default.md +23 -0
  61. package/rules/wangs-ui/typescript-tsconfig-strictness.md +30 -0
  62. package/rules/wangs-ui/typescript-zero-any.md +36 -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.21",
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,13 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when deciding whether a prop belongs in global defaultProps config or per-instance JSX."
4
+ metadata:
5
+ owner: wangs-ui
6
+ ---
7
+ # Wangs UI Fact: `configOptions.defaultProps` Precedence
8
+
9
+ `WangsUiProvider.configOptions.defaultProps` lets any project set global
10
+ default prop values per component. Per-instance JSX props always win over
11
+ that global default — the merge order is global-default-then-instance, never
12
+ the reverse. This is a `WangsUiProvider` mechanism, true in any project that
13
+ uses it, independent of what values a given project actually configures.
@@ -0,0 +1,18 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when writing a <Field> render-prop callback in a Wangs UI Form/DialogForm."
4
+ metadata:
5
+ owner: wangs-ui
6
+ ---
7
+ # Wangs UI Fact: `<Field>` Render-Prop Must Destructure `{ fieldProps, fieldState }`
8
+
9
+ `<Field>`'s callback render prop must destructure as `{({ fieldProps, fieldState })}`.
10
+ Passing a single parameter instead (`{(field) => ...}`) produces `undefined`
11
+ `value`/`onChange` and permanently locks the input — the field never becomes
12
+ interactive, even on initial render. This is a real `@wangs-ui/form` quirk,
13
+ not a project convention; it reproduces the same way in any consumer.
14
+
15
+ `<Field>` is generic — `fieldProps.onChange` is already typed to the field's
16
+ actual value type. Pass it straight through (`fieldProps.onChange`); don't
17
+ wrap it in a defensive `typeof`/`e?.target?.value` extraction, that's fighting
18
+ a type the field already guarantees.
@@ -0,0 +1,28 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when writing JSX markup — enforce Wangs UI primitives over raw HTML elements."
4
+ metadata:
5
+ owner: wangs-ui
6
+ ---
7
+ # Rule: No Raw HTML Controls
8
+
9
+ Zero raw HTML elements. Use Wangs UI primitives and Foundation theme typography.
10
+
11
+ ## Prohibitions
12
+
13
+ - No `<button>`, `<input>`, `<select>`, `<textarea>`, `<form>`, `<table>`, `<dialog>`.
14
+ - No `<h1>`-`<h6>`, `<p>`, `<span>` for text typography without Wangs UI theme primitives.
15
+
16
+ ## Mandatory Imports
17
+
18
+ - Primitives via subpath:
19
+ - `@wangs-ui/react-core/primitive/button`
20
+ - `@wangs-ui/react-core/primitive/input`
21
+ - `@wangs-ui/react-core/primitive/datatable`
22
+ - `@wangs-ui/react-core/primitive/modal`
23
+ - `@wangs-ui/react-core/primitive/dialogform`
24
+ - `@wangs-ui/react-core/primitive/card`
25
+ - `@wangs-ui/react-core/primitive/badge`
26
+ - Typography via Foundation theme:
27
+ - `@wangs-ui/foundation/theme` (`Text`, `Code`, `Kbd`, `Link`, `Mark`, `Blockquote`, `List`)
28
+ - Use variants: `display*`, `headline*`, `title*`, `body*`, `label*`.
@@ -0,0 +1,55 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when writing or reviewing JSX layout for redundant wrapper containers."
4
+ metadata:
5
+ owner: wangs-ui
6
+ ---
7
+ # Rule: No Redundant Layout & Container Wrappers
8
+
9
+ > **Severity**: **ARCHITECTURAL CODE SMELL / LINT FAILURE**.
10
+
11
+ 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.
12
+
13
+ ---
14
+
15
+ ## 1. Prohibited Anti-Patterns
16
+
17
+ 1. **Single-Child Wrapper `<div>`**:
18
+ Never wrap a single component (e.g. `<DataTable />`, `<Card />`, `<Tabs />`, `<Input />`, `<Button />`) inside an isolated `<div>` that has no layout siblings.
19
+ 2. **Intermediate Tab/Card Wrappers**:
20
+ Do not insert pass-through `<div>` wrappers between `<Card>`/`<Tabs>` and feature content:
21
+ ```tsx
22
+ // ❌ Bad — Redundant intermediate div wrapping a single tab component
23
+ function TabbedPage() {
24
+ return (
25
+ <Card>
26
+ <Tabs ... />
27
+ <div>
28
+ {activeTab === 'general' ? <GeneralTab /> : <AdvancedTab />}
29
+ </div>
30
+ </Card>
31
+ );
32
+ }
33
+
34
+ // ✅ Good — Render active tab directly as Card child
35
+ function TabbedPage() {
36
+ return (
37
+ <Card>
38
+ <Tabs ... />
39
+ {activeTab === 'general' ? <GeneralTab /> : <AdvancedTab />}
40
+ </Card>
41
+ );
42
+ }
43
+ ```
44
+ 3. **Redundant Table Wrappers**:
45
+ 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.
46
+
47
+ ---
48
+
49
+ ## 2. When a Layout Wrapper Is Permitted
50
+
51
+ 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>`:
52
+
53
+ 1. **Alignment bars**: header title + search + action buttons → `<HStack justify="between">`.
54
+ 2. **Multi-column/card grids**: responsive multi-card or multi-field layouts → `<Grid columns={{ compact: 1, medium: 2, expanded: 3 }}>`.
55
+ 3. **Fragment Alternative**: when returning multiple adjacent elements without layout coordination, use React Fragment (`<>...</>`) — not an empty wrapper.
@@ -0,0 +1,37 @@
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
+ metadata:
5
+ owner: wangs-ui
6
+ ---
7
+ # Rule: React 19 — Review Checklist & Quick Reference
8
+
9
+ ## Checking Compiler Optimization
10
+
11
+ - **Build output** — compiled files import `react/compiler-runtime` and contain `Symbol.for("react.memo_cache_sentinel")`; if absent, the compiler never ran.
12
+ - **ESLint / Oxlint** — compiler's recommended rules flag Rules-of-React violations at lint time.
13
+
14
+ ## Review Checklist
15
+
16
+ - [ ] 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
17
+ - [ ] Compiler confirmed active (build output imports `react/compiler-runtime`) before removing any _existing_ manual memoization
18
+ - [ ] No new `useMemo`/`useCallback`/`React.memo` added without documented reason (confirmed bail-out, or external boundary)
19
+ - [ ] No prop/state/context mutation anywhere in render
20
+ - [ ] All hooks called unconditionally at top level, same order every render
21
+ - [ ] Side effects live in `useEffect`/event handlers, never during render
22
+ - [ ] Components are `PascalCase`; hooks are `camelCase` and prefixed `use`
23
+ - [ ] `ref` accepted as normal prop instead of `forwardRef`
24
+ - [ ] Action/optimistic-update state modeled as discriminated union, not optional fields
25
+ - [ ] Mutually exclusive prop combinations modeled as discriminated union `Props` type
26
+ - [ ] Any `"use no memo"` usage has a comment explaining why
27
+
28
+ ## Quick Reference
29
+
30
+ | Situation | Do |
31
+ | ----------------------------------------------------------- | ------------------------------------------------------------- |
32
+ | Tempted to write `useMemo`/`useCallback` | Don't — write plain expression, let compiler decide |
33
+ | Need a ref on a function component | Accept `ref` as a prop, skip `forwardRef` |
34
+ | Form/async state with distinct outcomes | Discriminated union via `useActionState`, not optional fields |
35
+ | Callback needs latest props/state without re-running effect | `useEffectEvent` |
36
+ | A hook/library is known-incompatible with compiler | `"use no memo"` at top of that function, with comment |
37
+ | Checking if optimization is happening | Build output imports `react/compiler-runtime` (has `react.memo_cache_sentinel`) + compiler lint rules |
@@ -0,0 +1,12 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when writing or reviewing render logic in a React 19 component."
4
+ metadata:
5
+ owner: wangs-ui
6
+ ---
7
+ # Rule: React 19 — Compiler-Friendly Render Patterns
8
+
9
+ - 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.
10
+ - Avoid module-level mutable variables read or written during render — that state is invisible to the compiler and breaks idempotence.
11
+ - 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.
12
+ - 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,15 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when naming a React 19 component, hook, or prop."
4
+ metadata:
5
+ owner: wangs-ui
6
+ ---
7
+ # Rule: React 19 — Naming Conventions
8
+
9
+ The compiler identifies what to optimize by naming heuristics, same as the Rules of Hooks linter:
10
+
11
+ | Kind | Convention | Notes |
12
+ | ------------------------------------------------------------------------ | ------------------------------- | ----------------------------------------------------------------------------- |
13
+ | Components | `PascalCase`, returns JSX | Compiler treats it as a component to optimize |
14
+ | Custom hooks | `camelCase`, prefixed `use` | Required for both Rules-of-Hooks lint and compiler analysis |
15
+ | 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,27 @@
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
+ metadata:
5
+ owner: wangs-ui
6
+ ---
7
+ # Rule: React 19 — Stop Hand-Rolling Memoization
8
+
9
+ > **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.
10
+
11
+ 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.
12
+
13
+ ```tsx
14
+ // ❌ Old habit — noisy, and a mismatched dependency array is a whole class of bugs
15
+ const filteredUsers = useMemo(() => users.filter((u) => u.isActive), [users]);
16
+ const handleClick = useCallback(() => onSelect(user.id), [onSelect, user.id]);
17
+
18
+ // ✅ New default — just write the logic; the compiler memoizes what's worth memoizing
19
+ const filteredUsers = users.filter((u) => u.isActive);
20
+ const handleClick = () => onSelect(user.id);
21
+ ```
22
+
23
+ ## When manual memoization is still justified:
24
+
25
+ - 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.
26
+ - 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).
27
+ - 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,84 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when typing React 19 primitives — ref props, useActionState, useOptimistic, use(), useEffectEvent."
4
+ metadata:
5
+ owner: wangs-ui
6
+ ---
7
+ # Rule: React 19 — Typing React 19 Primitives
8
+
9
+ ## `ref` as a Normal Prop
10
+
11
+ `forwardRef` is no longer required for most cases; function components accept `ref` directly.
12
+
13
+ ```tsx
14
+ type InputProps = {
15
+ ref?: React.Ref<HTMLInputElement>;
16
+ placeholder?: string;
17
+ };
18
+
19
+ function TextInput({ ref, placeholder }: InputProps) {
20
+ return <input ref={ref} placeholder={placeholder} />;
21
+ }
22
+ ```
23
+
24
+ ## Actions with `useActionState`
25
+
26
+ Type the state and payload as generics; model the result as a discriminated union rather than optional fields.
27
+
28
+ ```tsx
29
+ type FormState = { status: 'idle' } | { status: 'error'; message: string } | { status: 'success' };
30
+
31
+ const [state, formAction, isPending] = useActionState<FormState, FormData>(
32
+ async (_previous, formData) => {
33
+ const email = formData.get('email');
34
+ if (typeof email !== 'string' || !email.includes('@')) {
35
+ return { status: 'error', message: 'Invalid email' };
36
+ }
37
+ await submit(email);
38
+ return { status: 'success' };
39
+ },
40
+ { status: 'idle' },
41
+ );
42
+ ```
43
+
44
+ ## Optimistic Updates with `useOptimistic`
45
+
46
+ Type both the state and the update shape.
47
+
48
+ ```tsx
49
+ const [optimisticTodos, addOptimisticTodo] = useOptimistic<Todo[], Todo>(
50
+ todos,
51
+ (state, newTodo) => [...state, newTodo],
52
+ );
53
+ ```
54
+
55
+ ## Reading Promises or Context with `use()`
56
+
57
+ Type the resolved value, not the promise wrapper; `use()` is not a hook and may be called conditionally.
58
+
59
+ ```tsx
60
+ function Comments({ commentsPromise }: { commentsPromise: Promise<Comment[]> }) {
61
+ const comments = use(commentsPromise); // suspends until resolved
62
+ return (
63
+ <ul>
64
+ {comments.map((c) => (
65
+ <li key={c.id}>{c.text}</li>
66
+ ))}
67
+ </ul>
68
+ );
69
+ }
70
+ ```
71
+
72
+ ## Stable Event Callbacks with `useEffectEvent` (React 19.2+)
73
+
74
+ Separates "event" logic from "reactive" effect logic so the callback always sees latest props/state without being listed as an effect dependency.
75
+
76
+ ```tsx
77
+ const onVisit = useEffectEvent((url: string) => {
78
+ logVisit(url, theme); // always fresh `theme`, never re-triggers the effect
79
+ });
80
+
81
+ useEffect(() => {
82
+ onVisit(url);
83
+ }, [url]); // `theme` intentionally omitted — onVisit is stable
84
+ ```
@@ -0,0 +1,24 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when defining a component's Props type or interface."
4
+ metadata:
5
+ owner: wangs-ui
6
+ ---
7
+ # Rule: React 19 — Typing Props
8
+
9
+ - `interface` for a component's `Props` — it's an entity shape, often extended.
10
+ - A discriminated union when a component has mutually exclusive prop combinations, instead of a pile of optional props that can contradict each other.
11
+
12
+ ```tsx
13
+ // ❌ Bad — nothing stops passing both `href` and `onClick` incoherently
14
+ interface ButtonProps {
15
+ label: string;
16
+ href?: string;
17
+ onClick?: () => void;
18
+ }
19
+
20
+ // ✅ Good — the two variants can't be mixed
21
+ type ButtonProps =
22
+ | { variant: 'link'; label: string; href: string }
23
+ | { variant: 'action'; label: string; onClick: () => void };
24
+ ```
@@ -0,0 +1,40 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when writing or reviewing a React 19 component or hook body for purity and immutability."
4
+ metadata:
5
+ owner: wangs-ui
6
+ ---
7
+ # Rule: React 19 — Purity and Immutability (Load-Bearing)
8
+
9
+ The compiler assumes your components and hooks are pure. Violating these rules causes the compiler to silently skip optimizing that component:
10
+
11
+ - **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.
12
+ - **Immutability** — never mutate props, state, or context directly. Always create new objects/arrays for changes.
13
+ - **Side effects only in effects or event handlers** — never during render.
14
+ - **Hooks called unconditionally, top-level, same order every render** — no hooks inside conditionals, loops, or nested functions.
15
+
16
+ ```tsx
17
+ // ❌ Mutates a prop — breaks purity and the compiler can't safely memoize this
18
+ function TodoList({ todos }: { todos: Todo[] }) {
19
+ todos.sort((a, b) => a.priority - b.priority); // mutates caller's array
20
+ return (
21
+ <ul>
22
+ {todos.map((t) => (
23
+ <li key={t.id}>{t.title}</li>
24
+ ))}
25
+ </ul>
26
+ );
27
+ }
28
+
29
+ // ✅ Creates a new array — pure, compiler-safe
30
+ function TodoList({ todos }: { todos: Todo[] }) {
31
+ const sorted = [...todos].sort((a, b) => a.priority - b.priority);
32
+ return (
33
+ <ul>
34
+ {sorted.map((t) => (
35
+ <li key={t.id}>{t.title}</li>
36
+ ))}
37
+ </ul>
38
+ );
39
+ }
40
+ ```
@@ -0,0 +1,77 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: 'Apply when configuring React Compiler tooling or opting a component out via "use no memo".'
4
+ metadata:
5
+ owner: wangs-ui
6
+ ---
7
+ # Rule: React 19 — Tooling Setup & Compiler Opt-Out
8
+
9
+ ## Compiler Setup Is Mandatory
10
+
11
+ **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.
12
+
13
+ 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`.
14
+
15
+ ### Verify it's active
16
+
17
+ - 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`).
18
+ - 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.
19
+ - The `react/react-compiler` lint rule is enabled.
20
+
21
+ ### Setup (when missing)
22
+
23
+ ```bash
24
+ # Compiler (build-time transform)
25
+ pnpm add -D --save-exact babel-plugin-react-compiler@latest
26
+ ```
27
+
28
+ ### Lint rules — oxlint
29
+
30
+ Oxlint ships a **native, Rust-based** `react/react-compiler` rule:
31
+
32
+ ```json
33
+ // .oxlintrc.json
34
+ {
35
+ "plugins": ["react"],
36
+ "rules": {
37
+ "react/react-compiler": "error"
38
+ }
39
+ }
40
+ ```
41
+
42
+ This single rule reports:
43
+
44
+ - **Rules-of-React violations** (conditional hooks, reading a ref during render, mutating props) — must-fix bugs.
45
+ - **Compiler bail-outs** — places compiler declined to optimize without rule violation.
46
+
47
+ ### Wiring into Vite 8
48
+
49
+ ```ts
50
+ // vite.config.ts
51
+ import { defineConfig } from 'vite';
52
+ import react, { reactCompilerPreset } from '@vitejs/plugin-react';
53
+ import babel from '@rolldown/plugin-babel';
54
+
55
+ export default defineConfig({
56
+ plugins: [
57
+ babel({ presets: [reactCompilerPreset()] }), // must run before react()
58
+ react(),
59
+ ],
60
+ });
61
+ ```
62
+
63
+ ```bash
64
+ pnpm add -D @rolldown/plugin-babel @babel/core babel-plugin-react-compiler
65
+ ```
66
+
67
+ ## Incompatibility Escape Hatch (`"use no memo"`)
68
+
69
+ 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:
70
+
71
+ ```tsx
72
+ function LegacyForm() {
73
+ 'use no memo';
74
+ const form = useForm(); // incompatible with the compiler today
75
+ // ...
76
+ }
77
+ ```
@@ -0,0 +1,19 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when tempted to override a Wangs UI theme CSS variable directly."
4
+ metadata:
5
+ owner: wangs-ui
6
+ ---
7
+ # Wangs UI Fact: Theme Variables Are Engine-Internal, Never Override Directly
8
+
9
+ Manually defining or overriding `:root`, `[data-mode='dark']`, or `.dark` custom
10
+ properties owned by `@wangs-ui/foundation/theme` (`--color-*`, `--z-index-*`,
11
+ `--spacing-*`, `--size-*`, `--shadow-*`, `--radius-*`) breaks the theme token
12
+ engine: it destroys automatic light/dark mode transitions, corrupts sub-tree
13
+ density overrides made via `<ThemeProvider>`, and causes cross-module visual
14
+ bugs that don't reproduce consistently. This is true for any project consuming
15
+ `@wangs-ui/foundation`, not specific to one app's setup.
16
+
17
+ The supported customization surface is `WangsUiProvider.configOptions.preset`
18
+ — discover it via the `design-system`/`wangs-ui-components` skills' MCP calls,
19
+ never by reading or guessing the CSS variable names.
@@ -0,0 +1,12 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when writing or reviewing a type assertion (`as X`) or non-null assertion (`x!`)."
4
+ metadata:
5
+ owner: wangs-ui
6
+ ---
7
+ # Rule: TypeScript — Type Assertions & Non-Null Assertions are a Last Resort
8
+
9
+ - `as X` and `x!` tell the compiler "trust me" — they produce zero runtime safety and actively hide bugs if wrong.
10
+ - 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.
11
+ - Never use `as any` or `as unknown as X` to force an incompatible cast — that's `any` wearing a disguise.
12
+ - `x!` should almost always be replaceable by an actual null check or optional chaining (`x?.y`) plus a real fallback.
@@ -0,0 +1,33 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when doing a final TypeScript review pass on a file."
4
+ metadata:
5
+ owner: wangs-ui
6
+ ---
7
+ # Rule: TypeScript — Review Checklist & Quick Reference
8
+
9
+ ## Review Checklist
10
+
11
+ Before considering TypeScript code "done," verify:
12
+
13
+ - [ ] No `any` anywhere (including implicit `any` from missing annotations)
14
+ - [ ] External/uncertain data enters as `unknown` and is narrowed before use
15
+ - [ ] Variant state is a discriminated union, not optional fields + booleans
16
+ - [ ] `interface` used for object/entity shapes; `type` used for unions/aliases/intersections
17
+ - [ ] No stray `I` prefixes on interfaces
18
+ - [ ] Naming follows casing conventions consistently
19
+ - [ ] `as` / `!` are rare, justified, and can't be replaced by a guard or null check
20
+ - [ ] Exported functions/methods have explicit return types
21
+ - [ ] Switch statements over unions have an exhaustiveness (`never`) check
22
+ - [ ] `tsconfig.json` includes the strictness baseline
23
+
24
+ ## Quick Reference
25
+
26
+ | Situation | Use |
27
+ | ---------------------------------------------- | ------------------------------------------------------------- |
28
+ | External/uncertain data | `unknown` + narrowing |
29
+ | "This value is definitely one of these shapes" | Discriminated union (`type`) |
30
+ | Object with identity, may be extended | `interface` |
31
+ | Union, intersection, tuple, mapped type | `type` |
32
+ | Need to prove a type through logic | Type guard / narrowing |
33
+ | Tempted to write `any` | Stop — use `unknown`, a generic, or a local interface instead |
@@ -0,0 +1,39 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when modeling a variant or multi-shape state in TypeScript."
4
+ metadata:
5
+ owner: wangs-ui
6
+ ---
7
+ # Rule: TypeScript — Discriminated Unions for Variant State
8
+
9
+ 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.
10
+
11
+ ```ts
12
+ // ❌ Bad — booleans can contradict each other; unclear which fields are valid together
13
+ interface FetchState {
14
+ isLoading: boolean;
15
+ isError: boolean;
16
+ data?: User;
17
+ error?: string;
18
+ }
19
+
20
+ // ✅ Good — only one shape is possible at a time, and the compiler enforces it
21
+ type FetchState =
22
+ | { status: 'idle' }
23
+ | { status: 'loading' }
24
+ | { status: 'success'; data: User }
25
+ | { status: 'error'; error: string };
26
+
27
+ function render(state: FetchState) {
28
+ switch (state.status) {
29
+ case 'success':
30
+ return state.data.name; // `data` is guaranteed to exist here
31
+ case 'error':
32
+ return state.error; // `error` is guaranteed to exist here
33
+ default:
34
+ return null;
35
+ }
36
+ }
37
+ ```
38
+
39
+ 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,21 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when writing or reviewing an exported function, class method, or public API surface in TypeScript."
4
+ metadata:
5
+ owner: wangs-ui
6
+ ---
7
+ # Rule: TypeScript — Explicit Return Types on Exported Functions
8
+
9
+ 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.
10
+
11
+ ```ts
12
+ // ❌ Return type is inferred and can silently drift
13
+ export function getActiveUsers(users: User[]) {
14
+ return users.filter((u) => u.active);
15
+ }
16
+
17
+ // ✅ Explicit, intentional contract
18
+ export function getActiveUsers(users: User[]): User[] {
19
+ return users.filter((u) => u.active);
20
+ }
21
+ ```
@@ -0,0 +1,39 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when deciding between `interface` and `type` for a new TypeScript declaration."
4
+ metadata:
5
+ owner: wangs-ui
6
+ ---
7
+ # Rule: TypeScript — `interface` vs `type`
8
+
9
+ Both can describe object shapes, but they signal different intent. Default rule:
10
+
11
+ | Use `interface` for... | Use `type` for... |
12
+ | -------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
13
+ | Object / entity shapes (a `User`, a `Product`, a component's `Props`) | Unions (`"a" \| "b"`) and discriminated unions |
14
+ | Public API contracts meant to be `implements`-ed by classes | Intersections (`A & B`) |
15
+ | Shapes that consumers may want to **extend/augment** (declaration merging) | Tuples (`[string, number]`) |
16
+ | | Function types / callback signatures |
17
+ | | Mapped, conditional, or utility-derived types (`Partial<T>`, `Pick<T, K>`) |
18
+ | | Aliasing a primitive or another type for readability |
19
+
20
+ ```ts
21
+ // ✅ interface — an entity with identity, extendable
22
+ interface User {
23
+ id: string;
24
+ email: string;
25
+ role: UserRole;
26
+ }
27
+
28
+ interface AdminUser extends User {
29
+ permissions: Permission[];
30
+ }
31
+
32
+ // ✅ type — union, alias, derived shape
33
+ type UserRole = 'admin' | 'editor' | 'viewer';
34
+ type UserId = User['id'];
35
+ type PartialUser = Partial<User>;
36
+ type Callback<T> = (value: T) => void;
37
+ ```
38
+
39
+ 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`.
@@ -0,0 +1,21 @@
1
+ ---
2
+ trigger: model_decision
3
+ description: "Apply when modeling a fixed set of string or numeric variants in TypeScript."
4
+ metadata:
5
+ owner: wangs-ui
6
+ ---
7
+ # Rule: TypeScript — Prefer Literal Unions Over Numeric Enums
8
+
9
+ String literal unions are simpler, tree-shake better, and produce clearer error messages than TypeScript `enum`. Reserve `enum` (or `as const` object maps) for cases that need reverse lookup or genuinely benefit from a namespaced runtime value.
10
+
11
+ ```ts
12
+ // ✅ Preferred
13
+ type OrderStatus = 'pending' | 'shipped' | 'delivered' | 'cancelled';
14
+
15
+ // Acceptable when a namespaced runtime object is actually needed
16
+ const OrderStatus = {
17
+ Pending: 'pending',
18
+ Shipped: 'shipped',
19
+ } as const;
20
+ type OrderStatus = (typeof OrderStatus)[keyof typeof OrderStatus];
21
+ ```