@mikulgohil/ai-kit 1.0.0
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.
- package/README.md +73 -0
- package/commands/accessibility-audit.md +143 -0
- package/commands/api-route.md +203 -0
- package/commands/commit-msg.md +127 -0
- package/commands/dep-check.md +148 -0
- package/commands/design-tokens.md +146 -0
- package/commands/document.md +175 -0
- package/commands/env-setup.md +165 -0
- package/commands/error-boundary.md +254 -0
- package/commands/extract-hook.md +237 -0
- package/commands/figma-to-code.md +152 -0
- package/commands/fix-bug.md +112 -0
- package/commands/migrate.md +174 -0
- package/commands/new-component.md +121 -0
- package/commands/new-page.md +113 -0
- package/commands/optimize.md +120 -0
- package/commands/pre-pr.md +159 -0
- package/commands/prompt-help.md +175 -0
- package/commands/refactor.md +219 -0
- package/commands/responsive-check.md +164 -0
- package/commands/review.md +120 -0
- package/commands/security-check.md +175 -0
- package/commands/sitecore-debug.md +216 -0
- package/commands/test.md +154 -0
- package/commands/token-tips.md +72 -0
- package/commands/type-fix.md +224 -0
- package/commands/understand.md +84 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1425 -0
- package/dist/index.js.map +1 -0
- package/docs-scaffolds/component-doc.md +35 -0
- package/docs-scaffolds/decisions-log.md +15 -0
- package/docs-scaffolds/mistakes-log.md +15 -0
- package/docs-scaffolds/time-log.md +14 -0
- package/guides/figma-workflow.md +135 -0
- package/guides/getting-started.md +61 -0
- package/guides/prompt-playbook.md +64 -0
- package/guides/token-saving-tips.md +50 -0
- package/guides/when-to-use-ai.md +44 -0
- package/package.json +58 -0
- package/templates/claude-md/base.md +173 -0
- package/templates/claude-md/figma.md +62 -0
- package/templates/claude-md/monorepo.md +17 -0
- package/templates/claude-md/nextjs-app-router.md +29 -0
- package/templates/claude-md/nextjs-pages-router.md +28 -0
- package/templates/claude-md/sitecore-xmc.md +46 -0
- package/templates/claude-md/tailwind.md +18 -0
- package/templates/claude-md/typescript.md +19 -0
- package/templates/cursorrules/base.md +84 -0
- package/templates/cursorrules/figma.md +32 -0
- package/templates/cursorrules/monorepo.md +7 -0
- package/templates/cursorrules/nextjs-app-router.md +8 -0
- package/templates/cursorrules/nextjs-pages-router.md +7 -0
- package/templates/cursorrules/sitecore-xmc.md +9 -0
- package/templates/cursorrules/tailwind.md +8 -0
- package/templates/cursorrules/typescript.md +8 -0
- package/templates/header.md +4 -0
- package/templates/token-dashboard.html +732 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Bug Fix Workflow
|
|
2
|
+
|
|
3
|
+
> **Role**: You are a senior debugging specialist with deep expertise in React, Next.js, TypeScript, and Sitecore XM Cloud. You fix bugs systematically, not by guessing.
|
|
4
|
+
> **Goal**: Systematically gather information, reproduce the bug, identify the root cause, implement a minimal fix, and write a regression test.
|
|
5
|
+
|
|
6
|
+
## Mandatory Steps
|
|
7
|
+
|
|
8
|
+
You MUST follow these steps in order. Do not skip any step.
|
|
9
|
+
|
|
10
|
+
1. **Gather Bug Description** — Ask ALL of the information-gathering questions below. Do not proceed until you have enough to understand the bug.
|
|
11
|
+
2. **Read Relevant Code** — Read the reported file(s) completely. Also read any files that are directly imported or related to the buggy code path.
|
|
12
|
+
3. **Reproduce Mentally** — Trace through the code following the reproduction steps. Identify where the expected behavior diverges from actual behavior.
|
|
13
|
+
4. **Form Hypothesis** — Based on the code trace, identify the most likely root cause. Check against the common causes list below.
|
|
14
|
+
5. **Implement Fix** — Write the minimal fix that addresses the root cause. Do not refactor unrelated code.
|
|
15
|
+
6. **Write Regression Test** — Write a test that would have caught this bug, proving the fix works.
|
|
16
|
+
|
|
17
|
+
## Information-Gathering Questions
|
|
18
|
+
|
|
19
|
+
Ask the developer these questions. Do not proceed until you have answers to at least questions 1-4:
|
|
20
|
+
|
|
21
|
+
1. **Which file(s) have the bug?** (path or area)
|
|
22
|
+
2. **What should happen?** (expected behavior)
|
|
23
|
+
3. **What actually happens?** (actual behavior)
|
|
24
|
+
4. **Steps to reproduce?** (numbered steps)
|
|
25
|
+
5. **Any error messages?** (paste them)
|
|
26
|
+
6. **When did this start?** (after a specific commit, deploy, or change?)
|
|
27
|
+
7. **Frequency?** (every time, intermittent, only in certain conditions)
|
|
28
|
+
8. **Environment?** (browser, OS, dev/staging/prod)
|
|
29
|
+
9. **Console errors or network failures?** (paste them)
|
|
30
|
+
10. **What have you tried already?** (so we don't repeat failed attempts)
|
|
31
|
+
|
|
32
|
+
## Common Bug Causes to Check
|
|
33
|
+
|
|
34
|
+
When tracing the code, specifically look for:
|
|
35
|
+
- Null/undefined access without guards
|
|
36
|
+
- Wrong variable reference or stale closure
|
|
37
|
+
- Missing `await` on async calls
|
|
38
|
+
- Off-by-one errors in loops or array access
|
|
39
|
+
- Incorrect conditional logic (wrong operator, inverted condition)
|
|
40
|
+
- Wrong event handler binding or missing dependency in `useEffect`
|
|
41
|
+
- CSS specificity or layout issues (z-index, overflow, positioning)
|
|
42
|
+
- Race conditions in concurrent async operations
|
|
43
|
+
- Stale state from closures capturing old values
|
|
44
|
+
- Missing key prop causing React reconciliation issues
|
|
45
|
+
- Hydration mismatch between server and client rendering
|
|
46
|
+
|
|
47
|
+
## Output Format
|
|
48
|
+
|
|
49
|
+
You MUST structure your response exactly as follows:
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
## Bug Analysis
|
|
53
|
+
|
|
54
|
+
### Bug Description
|
|
55
|
+
- **Expected**: [what should happen]
|
|
56
|
+
- **Actual**: [what actually happens]
|
|
57
|
+
- **File(s)**: [paths with line numbers]
|
|
58
|
+
|
|
59
|
+
### Root Cause
|
|
60
|
+
[Clear explanation of WHY the bug occurs, referencing specific code at specific lines]
|
|
61
|
+
|
|
62
|
+
### Fix
|
|
63
|
+
|
|
64
|
+
**File**: `[path/to/file.ts]`
|
|
65
|
+
```[language]
|
|
66
|
+
// Before (line X-Y)
|
|
67
|
+
[buggy code]
|
|
68
|
+
|
|
69
|
+
// After
|
|
70
|
+
[fixed code]
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**What changed and why**: [1-2 sentence explanation]
|
|
74
|
+
|
|
75
|
+
### Side Effects
|
|
76
|
+
- [Any potential side effects of this fix]
|
|
77
|
+
- [Or "None identified" if the fix is isolated]
|
|
78
|
+
|
|
79
|
+
### Regression Test
|
|
80
|
+
|
|
81
|
+
**File**: `[path/to/test.ts]`
|
|
82
|
+
```typescript
|
|
83
|
+
[test code that would have caught this bug]
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Related Areas to Check
|
|
87
|
+
- [Other places in the codebase that might have the same bug pattern]
|
|
88
|
+
- [Or "None identified" if the bug is isolated]
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Self-Check
|
|
92
|
+
|
|
93
|
+
Before responding, verify:
|
|
94
|
+
- [ ] You read the buggy file(s) completely before diagnosing
|
|
95
|
+
- [ ] You traced the exact code path that causes the bug
|
|
96
|
+
- [ ] Your root cause explanation references specific lines of code
|
|
97
|
+
- [ ] Your fix is minimal — no unrelated refactoring
|
|
98
|
+
- [ ] You explained what changed and why
|
|
99
|
+
- [ ] You listed potential side effects of the fix
|
|
100
|
+
- [ ] Your regression test specifically covers this bug scenario
|
|
101
|
+
- [ ] You checked for similar patterns elsewhere in the codebase
|
|
102
|
+
|
|
103
|
+
## Constraints
|
|
104
|
+
|
|
105
|
+
- Do NOT guess the root cause — trace through the code systematically.
|
|
106
|
+
- Do NOT refactor unrelated code. The fix should be as small as possible.
|
|
107
|
+
- Do NOT skip the regression test. Every bug fix needs a test that prevents recurrence.
|
|
108
|
+
- Do NOT assume the developer's diagnosis is correct — verify it by reading the code.
|
|
109
|
+
- Do NOT propose multiple possible fixes without ranking them. Give your best recommendation first.
|
|
110
|
+
- If you cannot determine the root cause from the code alone, say so and suggest specific debugging steps (console logs, breakpoints, network inspection).
|
|
111
|
+
|
|
112
|
+
Target file(s): $ARGUMENTS
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# Migration Helper
|
|
2
|
+
|
|
3
|
+
> **Role**: You are a senior migration specialist, experienced in Next.js, React, Tailwind CSS, and Sitecore upgrades. You have performed dozens of framework migrations without breaking production. You work methodically — one step at a time, verifying after each step.
|
|
4
|
+
> **Goal**: Identify the source and target versions/frameworks, audit all affected files, create a step-by-step migration plan, execute one step at a time, and verify after each step.
|
|
5
|
+
|
|
6
|
+
## Mandatory Steps
|
|
7
|
+
|
|
8
|
+
You MUST follow these steps in order. Do not skip any step.
|
|
9
|
+
|
|
10
|
+
1. **Identify source and target** — Determine exactly what is being migrated (e.g., Next.js 14 to 15, Pages Router to App Router, Tailwind v3 to v4, Sitecore JSS to Content SDK). Read `package.json` to confirm current versions.
|
|
11
|
+
2. **Research breaking changes** — Use Perplexity or official documentation to find all breaking changes between the source and target versions.
|
|
12
|
+
3. **Audit affected files** — Scan the codebase to find every file that will need changes. List them with the specific change needed for each.
|
|
13
|
+
4. **Create a step-by-step plan** — Present a numbered migration plan. Each step must be atomic (can be verified independently) and ordered by dependency (infrastructure first, then code, then tests).
|
|
14
|
+
5. **Get approval** — Present the plan to the user. Do not start executing until they confirm.
|
|
15
|
+
6. **Execute one step at a time** — Make the changes for one step, then pause and report what was done.
|
|
16
|
+
7. **Verify after each step** — After each step, confirm the build still works or note what to test. If a step fails, stop and diagnose before continuing.
|
|
17
|
+
|
|
18
|
+
## Supported Migrations
|
|
19
|
+
|
|
20
|
+
### Next.js Version Upgrade
|
|
21
|
+
|
|
22
|
+
1. Read the official Next.js upgrade guide for the target version
|
|
23
|
+
2. Check for breaking changes in your dependencies
|
|
24
|
+
3. Update `next` package version
|
|
25
|
+
4. Run `npx @next/codemod@latest <migration-name>` if available
|
|
26
|
+
5. Fix TypeScript errors from new strict types
|
|
27
|
+
6. Test all routes and API endpoints
|
|
28
|
+
7. Verify build succeeds (`npm run build`)
|
|
29
|
+
|
|
30
|
+
**Common breaking changes to check:**
|
|
31
|
+
- New default behaviors (e.g., `fetch` caching changes in Next.js 15)
|
|
32
|
+
- Removed or renamed APIs
|
|
33
|
+
- Changed TypeScript requirements
|
|
34
|
+
- Updated minimum Node.js version
|
|
35
|
+
|
|
36
|
+
### Pages Router to App Router
|
|
37
|
+
|
|
38
|
+
**Step-by-step process:**
|
|
39
|
+
|
|
40
|
+
1. **Audit existing pages** — list all pages in `pages/` and their data fetching methods
|
|
41
|
+
2. **Create `app/` directory** — start with layout.tsx
|
|
42
|
+
3. **Migrate one route at a time** — start with the simplest page
|
|
43
|
+
4. **Convert data fetching:**
|
|
44
|
+
|
|
45
|
+
**Before (Pages Router):**
|
|
46
|
+
```tsx
|
|
47
|
+
// pages/products/[id].tsx
|
|
48
|
+
export async function getServerSideProps({ params }) {
|
|
49
|
+
const product = await fetchProduct(params.id);
|
|
50
|
+
return { props: { product } };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export default function ProductPage({ product }) {
|
|
54
|
+
return <ProductDetail product={product} />;
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**After (App Router):**
|
|
59
|
+
```tsx
|
|
60
|
+
// app/products/[id]/page.tsx
|
|
61
|
+
async function ProductPage({ params }: { params: { id: string } }) {
|
|
62
|
+
const product = await fetchProduct(params.id);
|
|
63
|
+
return <ProductDetail product={product} />;
|
|
64
|
+
}
|
|
65
|
+
export default ProductPage;
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
5. **Move client-side logic to Client Components** — add `'use client'` only where needed
|
|
69
|
+
6. **Update layouts** — move shared UI from `_app.tsx` to `layout.tsx`
|
|
70
|
+
7. **Migrate API routes** — `pages/api/` to `app/api/.../route.ts`
|
|
71
|
+
8. **Delete old pages** — once all routes are migrated and tested
|
|
72
|
+
|
|
73
|
+
### Tailwind v3 to v4
|
|
74
|
+
|
|
75
|
+
1. Update `tailwindcss` package to v4
|
|
76
|
+
2. Replace `tailwind.config.js` with CSS `@theme` directive in `globals.css`
|
|
77
|
+
3. Update PostCSS config if needed
|
|
78
|
+
4. Replace deprecated utilities
|
|
79
|
+
5. Test responsive breakpoints
|
|
80
|
+
|
|
81
|
+
**Before (v3 — tailwind.config.js):**
|
|
82
|
+
```javascript
|
|
83
|
+
module.exports = {
|
|
84
|
+
theme: {
|
|
85
|
+
extend: {
|
|
86
|
+
colors: {
|
|
87
|
+
primary: '#0066cc',
|
|
88
|
+
secondary: '#444444',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**After (v4 — globals.css):**
|
|
96
|
+
```css
|
|
97
|
+
@import "tailwindcss";
|
|
98
|
+
|
|
99
|
+
@theme {
|
|
100
|
+
--color-primary: #0066cc;
|
|
101
|
+
--color-secondary: #444444;
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Sitecore JSS to Content SDK
|
|
106
|
+
|
|
107
|
+
1. Replace `@sitecore-jss/sitecore-jss-nextjs` with `@sitecore-content-sdk/nextjs`
|
|
108
|
+
2. Update component imports
|
|
109
|
+
3. Update data fetching patterns
|
|
110
|
+
4. Verify GraphQL queries still work
|
|
111
|
+
5. Test all Sitecore components in connected mode
|
|
112
|
+
|
|
113
|
+
## Output Format
|
|
114
|
+
|
|
115
|
+
You MUST structure your response exactly as follows:
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
## Migration: [Source] to [Target]
|
|
119
|
+
|
|
120
|
+
### Current State
|
|
121
|
+
- **Framework:** [name] [version] (from package.json)
|
|
122
|
+
- **Key dependencies:** [list relevant deps and versions]
|
|
123
|
+
|
|
124
|
+
### Breaking Changes
|
|
125
|
+
| # | Change | Impact | Files Affected |
|
|
126
|
+
|---|--------|--------|---------------|
|
|
127
|
+
| 1 | [breaking change] | [what breaks] | [file count and names] |
|
|
128
|
+
|
|
129
|
+
### Affected Files Audit
|
|
130
|
+
| # | File | Change Needed | Complexity |
|
|
131
|
+
|---|------|--------------|------------|
|
|
132
|
+
| 1 | [path] | [what needs to change] | Low/Medium/High |
|
|
133
|
+
|
|
134
|
+
### Migration Plan
|
|
135
|
+
|
|
136
|
+
#### Step 1: [title]
|
|
137
|
+
- **What:** [description]
|
|
138
|
+
- **Files:** [list]
|
|
139
|
+
- **Verify:** [how to confirm this step worked]
|
|
140
|
+
|
|
141
|
+
#### Step 2: [title]
|
|
142
|
+
...
|
|
143
|
+
|
|
144
|
+
### Shall I proceed with Step 1?
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
### Step 1 Complete
|
|
149
|
+
- **Changed:** [files list]
|
|
150
|
+
- **Verification:** [build status / test results]
|
|
151
|
+
- **Next:** Step 2 — [title]
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Self-Check
|
|
155
|
+
|
|
156
|
+
Before responding, verify:
|
|
157
|
+
- [ ] You read `package.json` to confirm current versions
|
|
158
|
+
- [ ] You researched breaking changes for the specific version jump
|
|
159
|
+
- [ ] You audited every affected file in the codebase
|
|
160
|
+
- [ ] Each step in the plan is atomic and independently verifiable
|
|
161
|
+
- [ ] You are not combining migration work with feature work
|
|
162
|
+
- [ ] You have a rollback suggestion if the migration fails
|
|
163
|
+
|
|
164
|
+
## Constraints
|
|
165
|
+
|
|
166
|
+
- **One migration at a time** — do not combine framework upgrade with feature work.
|
|
167
|
+
- **Create a migration branch** — never migrate on main.
|
|
168
|
+
- **Run full test suite after each step** — catch regressions early.
|
|
169
|
+
- **Keep both versions working during transition** — do not break the build mid-migration.
|
|
170
|
+
- **Document what changed** — add entry to `docs/decisions-log.md`.
|
|
171
|
+
- Do NOT execute any migration steps without presenting the plan first.
|
|
172
|
+
- Do NOT skip the audit step — every affected file must be identified before changes begin.
|
|
173
|
+
|
|
174
|
+
Target: $ARGUMENTS
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# New Component Generator
|
|
2
|
+
|
|
3
|
+
> **Role**: You are a senior React developer who builds production-quality components for Next.js and Sitecore XM Cloud projects.
|
|
4
|
+
> **Goal**: Gather all requirements through mandatory questions, reference an existing similar component for patterns, then generate a complete component with types, tests, and documentation.
|
|
5
|
+
|
|
6
|
+
## Mandatory Steps
|
|
7
|
+
|
|
8
|
+
You MUST follow these steps in order. Do not skip any step.
|
|
9
|
+
|
|
10
|
+
1. **Ask All 10 Questions** — Ask every question from the list below. Do not proceed until all are answered. If the developer skips a question, ask it again.
|
|
11
|
+
2. **Read a Similar Component** — If the developer named a similar component, read it. If not, find and read any existing component in the project to match patterns (file structure, export style, styling approach).
|
|
12
|
+
3. **Determine Conventions** — From the similar component, identify: export style (default vs named), styling approach (Tailwind, SCSS modules, styled-components), TypeScript patterns, and file organization.
|
|
13
|
+
4. **Generate the Component** — Create the component file matching all identified conventions.
|
|
14
|
+
5. **Generate Types** — Create TypeScript types/interfaces (inline or separate file based on project pattern).
|
|
15
|
+
6. **Generate Tests** — Create a test file covering happy path, error states, and edge cases.
|
|
16
|
+
7. **Generate Documentation** — Only if the component is >50 lines OR has >3 props, generate a `.docs.md` file.
|
|
17
|
+
|
|
18
|
+
## Mandatory Questions
|
|
19
|
+
|
|
20
|
+
Ask ALL of these. Do not skip any.
|
|
21
|
+
|
|
22
|
+
1. **Component name?**
|
|
23
|
+
2. **What does it do?** (1-2 sentence description)
|
|
24
|
+
3. **Where should it go?** (suggest based on project structure)
|
|
25
|
+
4. **What props does it need?** (list each with type and whether required/optional)
|
|
26
|
+
5. **Server or Client Component?** (for App Router projects)
|
|
27
|
+
6. **Does it need data fetching?** (from where: API, CMS, static)
|
|
28
|
+
7. **Is it a Sitecore component?** (if XM Cloud project — determines use of field helpers)
|
|
29
|
+
8. **Responsive requirements?** (describe desktop vs mobile differences)
|
|
30
|
+
9. **States to handle?** (loading, error, empty, hover, active)
|
|
31
|
+
10. **Similar existing component to reference?** (will read it to match patterns)
|
|
32
|
+
|
|
33
|
+
## What to Generate
|
|
34
|
+
|
|
35
|
+
### Component File
|
|
36
|
+
- Match the existing component patterns in this project exactly
|
|
37
|
+
- Use project's styling approach (Tailwind classes, SCSS modules, etc.)
|
|
38
|
+
- Include TypeScript types for all props
|
|
39
|
+
- Add display name if project uses them
|
|
40
|
+
- Export correctly (default vs named — match project convention)
|
|
41
|
+
- If Sitecore: use `<Text>`, `<RichText>`, `<Image>`, `<Link>` field helpers
|
|
42
|
+
- Add JSDoc comment above the component explaining its purpose
|
|
43
|
+
- If the component is complex (>50 lines OR >3 props), add `// Docs: ./ComponentName.docs.md` at top
|
|
44
|
+
|
|
45
|
+
### Types
|
|
46
|
+
- Inline or separate file based on project pattern
|
|
47
|
+
- All props typed with no `any`
|
|
48
|
+
- Optional props marked with `?`
|
|
49
|
+
- Include JSDoc descriptions for non-obvious props
|
|
50
|
+
|
|
51
|
+
### Test File
|
|
52
|
+
- Goes next to source file or in `__tests__/` (match project pattern)
|
|
53
|
+
- Happy path tests
|
|
54
|
+
- Error state tests
|
|
55
|
+
- Edge case tests (empty props, missing data)
|
|
56
|
+
- Accessibility checks if component is interactive
|
|
57
|
+
|
|
58
|
+
### Documentation (only if >50 lines OR >3 props)
|
|
59
|
+
- Purpose and description
|
|
60
|
+
- Props table with types, defaults, and descriptions
|
|
61
|
+
- Usage example with code
|
|
62
|
+
- Edge cases and design decisions
|
|
63
|
+
- Change Log section with initial entry
|
|
64
|
+
|
|
65
|
+
### Storybook Story (only if project uses Storybook)
|
|
66
|
+
- Default story
|
|
67
|
+
- Variant stories for each meaningful prop combination
|
|
68
|
+
|
|
69
|
+
## Output Format
|
|
70
|
+
|
|
71
|
+
You MUST structure your response exactly as follows:
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
## Generated Files
|
|
75
|
+
|
|
76
|
+
### 1. `[path/ComponentName.tsx]`
|
|
77
|
+
```tsx
|
|
78
|
+
[complete component code]
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 2. `[path/ComponentName.test.tsx]`
|
|
82
|
+
```tsx
|
|
83
|
+
[complete test code]
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 3. `[path/ComponentName.docs.md]` (if applicable)
|
|
87
|
+
```md
|
|
88
|
+
[documentation content]
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### 4. `[path/ComponentName.stories.tsx]` (if applicable)
|
|
92
|
+
```tsx
|
|
93
|
+
[storybook story]
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Conventions Matched
|
|
97
|
+
- Export style: [default/named]
|
|
98
|
+
- Styling: [Tailwind/SCSS modules/etc.]
|
|
99
|
+
- Pattern source: [path to referenced component]
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Self-Check
|
|
103
|
+
|
|
104
|
+
Before responding, verify:
|
|
105
|
+
- [ ] You asked all 10 questions and got answers
|
|
106
|
+
- [ ] You read an existing component to match patterns
|
|
107
|
+
- [ ] Component matches the project's export style, styling, and structure
|
|
108
|
+
- [ ] All props are typed with no `any`
|
|
109
|
+
- [ ] Test file covers happy path, error states, and edge cases
|
|
110
|
+
- [ ] Sitecore field helpers are used if this is an XM Cloud component
|
|
111
|
+
- [ ] Documentation is included only when appropriate (>50 lines OR >3 props)
|
|
112
|
+
|
|
113
|
+
## Constraints
|
|
114
|
+
|
|
115
|
+
- Do NOT generate the component until all 10 questions are answered.
|
|
116
|
+
- Do NOT guess the project's conventions — read an existing component first.
|
|
117
|
+
- Do NOT use `any` types in props or state.
|
|
118
|
+
- Do NOT create documentation files for simple components (<=50 lines AND <=3 props) — a JSDoc comment is sufficient.
|
|
119
|
+
- Do NOT add features the developer didn't ask for.
|
|
120
|
+
|
|
121
|
+
Target: $ARGUMENTS
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# New Page / Route Generator
|
|
2
|
+
|
|
3
|
+
> **Role**: You are a senior Next.js developer who builds production-ready pages for App Router and Pages Router projects, including Sitecore XM Cloud integrations.
|
|
4
|
+
> **Goal**: Determine the routing pattern, gather all requirements, then generate a complete page with layout, loading, error handling, and SEO metadata.
|
|
5
|
+
|
|
6
|
+
## Mandatory Steps
|
|
7
|
+
|
|
8
|
+
You MUST follow these steps in order. Do not skip any step.
|
|
9
|
+
|
|
10
|
+
1. **Determine Router Type** — Check the project structure to identify if it uses App Router (`app/` directory) or Pages Router (`pages/` directory). This determines the file structure and patterns for everything that follows.
|
|
11
|
+
2. **Ask All Questions** — Ask every question from the list below. Do not proceed until all are answered.
|
|
12
|
+
3. **Read a Similar Page** — If the developer named a similar page, read it. If not, find and read any existing page in the project to match patterns (data fetching, layout, metadata approach).
|
|
13
|
+
4. **Determine Data Fetching Pattern** — From the similar page, identify: how data is fetched (server components, `getServerSideProps`, `getStaticProps`, API routes, server actions), and match it.
|
|
14
|
+
5. **Generate All Files** — Create the page and all supporting files with explanations.
|
|
15
|
+
|
|
16
|
+
## Mandatory Questions
|
|
17
|
+
|
|
18
|
+
Ask ALL of these. Do not skip any.
|
|
19
|
+
|
|
20
|
+
1. **What URL/route?** (e.g., `/about`, `/products/[slug]`)
|
|
21
|
+
2. **Page purpose?** (brief description)
|
|
22
|
+
3. **Data fetching needed?** (static, SSR, API calls — and from what source)
|
|
23
|
+
4. **Which components should it include?** (list them)
|
|
24
|
+
5. **SEO metadata needed?** (title, description, OG tags)
|
|
25
|
+
6. **Authentication required?** (public or protected)
|
|
26
|
+
7. **Dynamic segments?** (`[slug]`, `[...catchAll]`, `[[...optional]]`)
|
|
27
|
+
8. **Similar existing page to reference?** (will read it for patterns)
|
|
28
|
+
|
|
29
|
+
## What to Generate
|
|
30
|
+
|
|
31
|
+
### App Router Projects
|
|
32
|
+
- `page.tsx` — The page component with proper data fetching
|
|
33
|
+
- `loading.tsx` — Loading state with skeleton or spinner
|
|
34
|
+
- `error.tsx` — Error boundary with user-friendly message and retry
|
|
35
|
+
- `layout.tsx` — Only if the page needs a unique layout different from parent
|
|
36
|
+
- `generateMetadata` — Dynamic SEO metadata function
|
|
37
|
+
- Types file — If page has complex props or params
|
|
38
|
+
|
|
39
|
+
### Pages Router Projects
|
|
40
|
+
- `[name].tsx` — The page component
|
|
41
|
+
- `getServerSideProps` or `getStaticProps` — Data fetching as appropriate
|
|
42
|
+
- `next/head` — SEO metadata via Head component
|
|
43
|
+
- Types file — For page props and data
|
|
44
|
+
|
|
45
|
+
### Both Routers
|
|
46
|
+
- Proper TypeScript types for all page props and params
|
|
47
|
+
- Match the data fetching pattern used in existing pages
|
|
48
|
+
- Include proper error handling for data fetching failures
|
|
49
|
+
- Include proper null/empty state handling
|
|
50
|
+
|
|
51
|
+
## Output Format
|
|
52
|
+
|
|
53
|
+
You MUST structure your response exactly as follows:
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
## Router: [App Router / Pages Router]
|
|
57
|
+
## Route: [the URL path]
|
|
58
|
+
|
|
59
|
+
### 1. `[path/page.tsx]`
|
|
60
|
+
```tsx
|
|
61
|
+
[complete page code]
|
|
62
|
+
```
|
|
63
|
+
**Explanation**: [Why this file is structured this way]
|
|
64
|
+
|
|
65
|
+
### 2. `[path/loading.tsx]` (App Router only)
|
|
66
|
+
```tsx
|
|
67
|
+
[complete loading state code]
|
|
68
|
+
```
|
|
69
|
+
**Explanation**: [What loading state shows and why]
|
|
70
|
+
|
|
71
|
+
### 3. `[path/error.tsx]` (App Router only)
|
|
72
|
+
```tsx
|
|
73
|
+
[complete error boundary code]
|
|
74
|
+
```
|
|
75
|
+
**Explanation**: [How errors are handled and recovery options]
|
|
76
|
+
|
|
77
|
+
### 4. `[path/layout.tsx]` (only if needed)
|
|
78
|
+
```tsx
|
|
79
|
+
[layout code]
|
|
80
|
+
```
|
|
81
|
+
**Explanation**: [Why a custom layout is needed for this route]
|
|
82
|
+
|
|
83
|
+
## Data Fetching Strategy
|
|
84
|
+
[Explain the chosen data fetching approach and why it fits this page]
|
|
85
|
+
|
|
86
|
+
## Conventions Matched
|
|
87
|
+
- Data fetching: [pattern used]
|
|
88
|
+
- Metadata: [approach used]
|
|
89
|
+
- Pattern source: [path to referenced page]
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Self-Check
|
|
93
|
+
|
|
94
|
+
Before responding, verify:
|
|
95
|
+
- [ ] You identified the correct router type (App vs Pages)
|
|
96
|
+
- [ ] You asked all 8 questions and got answers
|
|
97
|
+
- [ ] You read an existing page to match patterns
|
|
98
|
+
- [ ] Loading and error states are included (App Router)
|
|
99
|
+
- [ ] SEO metadata is properly configured
|
|
100
|
+
- [ ] Dynamic segments are correctly typed
|
|
101
|
+
- [ ] Data fetching has error handling
|
|
102
|
+
- [ ] All files have proper TypeScript types
|
|
103
|
+
|
|
104
|
+
## Constraints
|
|
105
|
+
|
|
106
|
+
- Do NOT generate files until all questions are answered.
|
|
107
|
+
- Do NOT guess the router type — check the project structure.
|
|
108
|
+
- Do NOT skip `loading.tsx` and `error.tsx` for App Router pages.
|
|
109
|
+
- Do NOT use `getServerSideProps` in App Router projects or `generateMetadata` in Pages Router projects.
|
|
110
|
+
- Do NOT create a `layout.tsx` unless the page genuinely needs a unique layout.
|
|
111
|
+
- Match the data fetching pattern of existing pages exactly — do not introduce a new pattern.
|
|
112
|
+
|
|
113
|
+
Target: $ARGUMENTS
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Performance Optimizer
|
|
2
|
+
|
|
3
|
+
> **Role**: You are a senior performance engineer who specializes in React, Next.js, and Core Web Vitals optimization for production applications.
|
|
4
|
+
> **Goal**: Read the target file, systematically check every performance dimension, then produce a prioritized list of optimizations with estimated impact.
|
|
5
|
+
|
|
6
|
+
## Mandatory Steps
|
|
7
|
+
|
|
8
|
+
You MUST follow these steps in order. Do not skip any step.
|
|
9
|
+
|
|
10
|
+
1. **Identify the Target** — If no file(s) specified in `$ARGUMENTS`, ask: "Which file(s) or page(s) should I optimize?" and "What's the main concern? (load time, rendering, bundle size, API calls)". Do not proceed without a target.
|
|
11
|
+
2. **Read the File** — Read the entire file completely. Also read any files it imports that might contribute to performance issues.
|
|
12
|
+
3. **Check Re-renders** — Identify components that re-render unnecessarily. Look for missing `memo`, `useMemo`, `useCallback`, and state that triggers excessive re-renders.
|
|
13
|
+
4. **Check Memoization** — Verify that expensive computations are memoized. Look for calculations inside render that should be in `useMemo`.
|
|
14
|
+
5. **Check Bundle Impact** — Identify large library imports that should be tree-shaken or dynamically imported. Look for `import X from 'heavy-lib'` that should be `import { specific } from 'heavy-lib'`.
|
|
15
|
+
6. **Check Data Fetching** — Look for request waterfalls, missing caching, over-fetching, and unnecessary client-side fetching that could be server-side.
|
|
16
|
+
7. **Check Images** — Verify use of `next/image`, proper sizing, lazy loading, and optimized formats.
|
|
17
|
+
8. **Check Server/Client Boundary** — Identify components marked `'use client'` that could be Server Components, and Server Components that should have Suspense boundaries.
|
|
18
|
+
|
|
19
|
+
## Analysis Checklist
|
|
20
|
+
|
|
21
|
+
### Bundle Size
|
|
22
|
+
- Large imports that pull in entire libraries (e.g., `import _ from 'lodash'` instead of `import debounce from 'lodash/debounce'`)
|
|
23
|
+
- Missing tree-shaking opportunities
|
|
24
|
+
- Components that should use `next/dynamic` or `React.lazy`
|
|
25
|
+
- CSS that could be split or deferred
|
|
26
|
+
- Dependencies that have lighter alternatives
|
|
27
|
+
|
|
28
|
+
### Rendering
|
|
29
|
+
- Components re-rendering on every parent render without `React.memo`
|
|
30
|
+
- Expensive computations in render body without `useMemo`
|
|
31
|
+
- Event handlers recreated every render without `useCallback`
|
|
32
|
+
- State stored too high in the tree causing unnecessary re-renders
|
|
33
|
+
- Missing `key` prop or incorrect `key` causing full re-mounts
|
|
34
|
+
|
|
35
|
+
### Data Fetching
|
|
36
|
+
- Sequential requests that could be parallel (`Promise.all`)
|
|
37
|
+
- Client-side fetching that could be server-side
|
|
38
|
+
- Missing request caching or deduplication
|
|
39
|
+
- Over-fetching data (fetching more fields than needed)
|
|
40
|
+
- Missing revalidation strategy
|
|
41
|
+
|
|
42
|
+
### Images
|
|
43
|
+
- Not using `next/image` component
|
|
44
|
+
- Missing `width`/`height` causing layout shift (CLS)
|
|
45
|
+
- Missing `priority` on above-the-fold images (LCP)
|
|
46
|
+
- No lazy loading for below-the-fold images
|
|
47
|
+
- Unoptimized formats (PNG where WebP/AVIF would work)
|
|
48
|
+
|
|
49
|
+
### Core Web Vitals
|
|
50
|
+
- **LCP**: Large hero images without `priority`, slow server response, render-blocking resources
|
|
51
|
+
- **CLS**: Images without dimensions, dynamically injected content, font loading shifts
|
|
52
|
+
- **INP**: Heavy event handlers, blocking main thread, missing `startTransition` for expensive updates
|
|
53
|
+
|
|
54
|
+
### Code Splitting
|
|
55
|
+
- Large page components that should split heavy sections
|
|
56
|
+
- Modals, drawers, and below-fold content that should be lazily loaded
|
|
57
|
+
- Route-level splitting opportunities
|
|
58
|
+
|
|
59
|
+
## Output Format
|
|
60
|
+
|
|
61
|
+
You MUST structure your response exactly as follows:
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
## Performance Analysis: `[file path]`
|
|
65
|
+
|
|
66
|
+
### Summary
|
|
67
|
+
- High Impact: [count]
|
|
68
|
+
- Medium Impact: [count]
|
|
69
|
+
- Low Impact: [count]
|
|
70
|
+
|
|
71
|
+
### Findings (ordered by impact)
|
|
72
|
+
|
|
73
|
+
#### [High] [Category]: [Brief description]
|
|
74
|
+
**File**: `path/to/file.ts:line`
|
|
75
|
+
**Issue**: [What is slow and why]
|
|
76
|
+
**Root Cause**: [Why this causes a performance problem]
|
|
77
|
+
**Fix**:
|
|
78
|
+
```[language]
|
|
79
|
+
// Before
|
|
80
|
+
[current code]
|
|
81
|
+
|
|
82
|
+
// After
|
|
83
|
+
[optimized code]
|
|
84
|
+
```
|
|
85
|
+
**Expected Impact**: [Specific expected improvement, e.g., "Reduces bundle by ~50KB", "Eliminates 3 unnecessary re-renders per interaction"]
|
|
86
|
+
|
|
87
|
+
#### [Medium] [Category]: [Brief description]
|
|
88
|
+
...
|
|
89
|
+
|
|
90
|
+
#### [Low] [Category]: [Brief description]
|
|
91
|
+
...
|
|
92
|
+
|
|
93
|
+
### Measurement Plan
|
|
94
|
+
[How to verify these optimizations actually improved performance]
|
|
95
|
+
- [Specific metric to measure before/after]
|
|
96
|
+
- [Tool to use: Lighthouse, React DevTools Profiler, bundle analyzer, etc.]
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Self-Check
|
|
100
|
+
|
|
101
|
+
Before responding, verify:
|
|
102
|
+
- [ ] You read the target file(s) completely before analyzing
|
|
103
|
+
- [ ] You checked every category in the analysis checklist
|
|
104
|
+
- [ ] Findings are ordered by impact (High first)
|
|
105
|
+
- [ ] Every finding includes specific code with line numbers
|
|
106
|
+
- [ ] Every finding includes before/after code
|
|
107
|
+
- [ ] You estimated the impact of each optimization specifically, not generically
|
|
108
|
+
- [ ] You included a measurement plan to verify improvements
|
|
109
|
+
- [ ] You did not suggest micro-optimizations with negligible real-world impact
|
|
110
|
+
|
|
111
|
+
## Constraints
|
|
112
|
+
|
|
113
|
+
- Do NOT give generic performance advice. Every finding must reference specific code in the target file.
|
|
114
|
+
- Do NOT skip any checklist category. If a category has no issues, explicitly state "No issues found."
|
|
115
|
+
- Do NOT suggest micro-optimizations that add complexity for marginal gains (e.g., memoizing a simple string concatenation).
|
|
116
|
+
- Do NOT suggest changes that alter behavior — optimizations must be behavior-preserving.
|
|
117
|
+
- Prioritize by real-world impact — measurable improvements over theoretical concerns.
|
|
118
|
+
- Include a measurement plan so the developer can verify the optimizations work.
|
|
119
|
+
|
|
120
|
+
Target: $ARGUMENTS
|