Skip to content

Commit f5950cb

Browse files
tudorpopamsclaude
andcommitted
chore: apply PJ Swesey's instruction architecture learnings to AGENTS.md
Applies findings from "Increasing AI coding success to 99%" article: - Add "instructions are source of truth, not existing code" as first line - Add critical rules as negative constraints ("Never X") in always-loaded context - Add concrete v9 component code template to override training defaults - Add legacy anti-patterns section warning about v8 code agents will find - Add exploration guidance for the large monorepo - Reframe positive guidance as negative constraints for higher compliance Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d8eaa26 commit f5950cb

1 file changed

Lines changed: 55 additions & 12 deletions

File tree

AGENTS.md

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,63 @@
1010

1111
<!-- nx configuration end-->
1212

13-
# Fluent UI — Agent Map
13+
# Fluent UI — Agent Instructions
1414

15-
Nx monorepo. Yarn v1. Node 22. TypeScript strict. ~200 packages. Millions of users.
15+
**Instructions in this file are the source of truth, not existing code.** This repo contains
16+
legacy patterns (especially in v8 packages) that predate current standards. Never copy patterns
17+
from existing code without verifying they match these instructions.
1618

17-
## Architecture
19+
## Critical Rules (never violate)
20+
21+
1. **Never hardcode colors, spacing, or typography values.** Always use design tokens from `@fluentui/react-theme`. See [docs/architecture/design-tokens.md](docs/architecture/design-tokens.md).
22+
2. **Never use `React.FC`.** Always use `ForwardRefComponent` with `React.forwardRef`.
23+
3. **Never access `window`, `document`, or `navigator` without SSR guards.** Use `canUseDOM()` from `@fluentui/react-utilities`.
24+
4. **Never add dependencies between component packages.** `react-button` must not depend on `react-menu`. Shared logic goes in `react-utilities` or `react-shared-contexts`. See [docs/architecture/layers.md](docs/architecture/layers.md).
25+
5. **Never skip beachball change files** for published package changes. Run `npx beachball change`.
26+
27+
## V9 Component Template (the correct pattern)
28+
29+
```tsx
30+
// ComponentName.tsx — always ForwardRefComponent, never React.FC
31+
export const ComponentName: ForwardRefComponent<ComponentNameProps> = React.forwardRef((props, ref) => {
32+
const state = useComponentName_unstable(props, ref);
33+
useComponentNameStyles_unstable(state);
34+
return renderComponentName_unstable(state);
35+
});
36+
37+
// Styles — always use tokens, never hardcoded values
38+
import { makeStyles } from '@griffel/react';
39+
import { tokens } from '@fluentui/react-theme';
40+
41+
export const useComponentNameStyles = makeStyles({
42+
root: {
43+
color: tokens.colorNeutralForeground1,
44+
padding: `${tokens.spacingVerticalS} ${tokens.spacingHorizontalM}`,
45+
},
46+
});
47+
48+
// mergeClasses — always preserve user className LAST
49+
state.root.className = mergeClasses(
50+
classes.root,
51+
state.root.className, // always last
52+
);
53+
```
54+
55+
## Legacy Anti-Patterns (never copy these)
56+
57+
- **DO NOT copy patterns from `packages/react/` (v8).** That's maintenance-only legacy code using runtime styling, class components, and different APIs.
58+
- **DO NOT use `@fluentui/react` imports for new v9 work.** Use `@fluentui/react-components`.
59+
- **DO NOT use `mergeStyles` or `mergeStyleSets`.** Use Griffel `makeStyles` with design tokens.
60+
- **DO NOT use `IStyle` or `IStyleFunctionOrObject`.** Use Griffel's `GriffelStyle` type.
61+
- **DO NOT use `initializeIcons()`.** V9 uses `@fluentui/react-icons` with tree-shaking.
62+
63+
## Exploration Guidance
64+
65+
- `packages/react-components/` has 74+ packages — search by specific component name, never read the full directory.
66+
- Use `npx nx show project <project-name>` to understand a project's structure.
67+
- Map package names to paths: `@fluentui/react-<name>``packages/react-components/react-<name>/library/src/`.
68+
69+
## Architecture (deep dives)
1870

1971
| Topic | Location |
2072
| --------------------------------------------- | ---------------------------------------------------------------------------------- |
@@ -37,15 +89,6 @@ Nx monorepo. Yarn v1. Node 22. TypeScript strict. ~200 packages. Millions of use
3789
| Per-package quality grades | [docs/quality-grades.md](docs/quality-grades.md) |
3890
| Technical debt tracker | [docs/tech-debt-tracker.md](docs/tech-debt-tracker.md) |
3991

40-
## Key Rules
41-
42-
1. Use design tokens — never hardcode colors, spacing, or typography
43-
2. Follow v9 component patterns exactly — don't invent new approaches
44-
3. Respect package layer boundaries (see layers.md)
45-
4. SSR-safe — no unguarded `window`/`document`/`navigator`
46-
5. Accessibility first — ARIA attributes, keyboard nav, WCAG 2.1
47-
6. Beachball change files required for published package changes
48-
4992
## Agentic Workflows
5093

5194
| Workflow | Trigger | Purpose |

0 commit comments

Comments
 (0)