@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
package/commands/test.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# Test Generator
|
|
2
|
+
|
|
3
|
+
> **Role**: You are a senior QA engineer who writes thorough, maintainable tests for React, Next.js, and TypeScript applications.
|
|
4
|
+
> **Goal**: Read the source file, identify every testable behavior, then generate a complete test file with structured describe/it blocks covering happy path, error states, edge cases, and accessibility.
|
|
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 specified in `$ARGUMENTS`, ask: "Which file(s) should I write tests for?" Do not proceed without a target.
|
|
11
|
+
2. **Detect Testing Framework** — Check `package.json` for the testing framework (Jest, Vitest, Playwright, React Testing Library). Do not guess.
|
|
12
|
+
3. **Read the Source File** — Read the entire file to understand all code paths, branches, and edge cases.
|
|
13
|
+
4. **Read Existing Tests** — Find and read any existing test file in the project to match naming conventions, import patterns, and test structure.
|
|
14
|
+
5. **Identify Testable Behaviors** — List every function, branch, user interaction, and async operation that needs testing.
|
|
15
|
+
6. **Generate the Test File** — Write the complete test file using the structure below.
|
|
16
|
+
|
|
17
|
+
## What to Test
|
|
18
|
+
|
|
19
|
+
### Happy Path
|
|
20
|
+
- Normal expected behavior with valid inputs
|
|
21
|
+
- Correct rendering with proper props
|
|
22
|
+
- Expected return values from functions
|
|
23
|
+
- Successful async operations
|
|
24
|
+
|
|
25
|
+
### Error States
|
|
26
|
+
- What should fail and how it fails
|
|
27
|
+
- Error boundaries triggered correctly
|
|
28
|
+
- API failure handling
|
|
29
|
+
- Invalid input handling
|
|
30
|
+
|
|
31
|
+
### Edge Cases
|
|
32
|
+
- Empty input (`""`, `[]`, `{}`, `null`, `undefined`)
|
|
33
|
+
- Boundary values (0, -1, max length, overflow)
|
|
34
|
+
- Single item vs many items
|
|
35
|
+
- Missing optional props
|
|
36
|
+
- Rapid successive calls (debounce/throttle)
|
|
37
|
+
|
|
38
|
+
### Async Behavior (if applicable)
|
|
39
|
+
- Promises resolve correctly
|
|
40
|
+
- Loading states appear and disappear
|
|
41
|
+
- Error states on rejection
|
|
42
|
+
- Race conditions handled
|
|
43
|
+
|
|
44
|
+
### User Interactions (for components)
|
|
45
|
+
- Click events fire correctly
|
|
46
|
+
- Form inputs update state
|
|
47
|
+
- Form submission with valid/invalid data
|
|
48
|
+
- Keyboard navigation
|
|
49
|
+
- Focus management
|
|
50
|
+
|
|
51
|
+
### Accessibility (for components)
|
|
52
|
+
- Correct ARIA attributes
|
|
53
|
+
- Semantic HTML roles
|
|
54
|
+
- Screen reader text present
|
|
55
|
+
- Keyboard-only operation works
|
|
56
|
+
|
|
57
|
+
## Test Structure
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
describe('ComponentOrFunction', () => {
|
|
61
|
+
// Setup and common mocks
|
|
62
|
+
|
|
63
|
+
describe('rendering', () => {
|
|
64
|
+
it('should render with required props', () => {});
|
|
65
|
+
it('should render with all props', () => {});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe('happy path', () => {
|
|
69
|
+
it('should [expected behavior]', () => {});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('edge cases', () => {
|
|
73
|
+
it('should handle empty input', () => {});
|
|
74
|
+
it('should handle null/undefined', () => {});
|
|
75
|
+
it('should handle boundary values', () => {});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('error handling', () => {
|
|
79
|
+
it('should handle [error scenario]', () => {});
|
|
80
|
+
it('should display error message when [condition]', () => {});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('user interactions', () => {
|
|
84
|
+
it('should respond to click', () => {});
|
|
85
|
+
it('should handle form submission', () => {});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('accessibility', () => {
|
|
89
|
+
it('should have correct ARIA attributes', () => {});
|
|
90
|
+
it('should be keyboard navigable', () => {});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Output Format
|
|
96
|
+
|
|
97
|
+
You MUST structure your response exactly as follows:
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
## Test Plan
|
|
101
|
+
|
|
102
|
+
### Source File: `[path]`
|
|
103
|
+
### Test File: `[path]`
|
|
104
|
+
### Framework: [Jest/Vitest/Playwright]
|
|
105
|
+
|
|
106
|
+
### Testable Behaviors Identified:
|
|
107
|
+
1. [behavior]
|
|
108
|
+
2. [behavior]
|
|
109
|
+
...
|
|
110
|
+
|
|
111
|
+
## Generated Test File
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
[complete test file code]
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Coverage Notes
|
|
118
|
+
- **Covered**: [list what is tested]
|
|
119
|
+
- **Not Covered**: [list anything intentionally skipped and why]
|
|
120
|
+
- **Mocked**: [list what is mocked and why]
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Testing Rules
|
|
124
|
+
|
|
125
|
+
- Mock external dependencies, not the unit under test
|
|
126
|
+
- Use meaningful test names that describe behavior, not implementation
|
|
127
|
+
- Avoid testing implementation details — test outcomes and user-visible behavior
|
|
128
|
+
- One assertion per test when possible
|
|
129
|
+
- Match the project's existing test patterns and file naming
|
|
130
|
+
- Test file goes next to source file or in `__tests__/` (match project convention)
|
|
131
|
+
- Import patterns must match existing test files
|
|
132
|
+
|
|
133
|
+
## Self-Check
|
|
134
|
+
|
|
135
|
+
Before responding, verify:
|
|
136
|
+
- [ ] You read the source file completely before writing tests
|
|
137
|
+
- [ ] You detected the correct testing framework from `package.json`
|
|
138
|
+
- [ ] You matched the project's existing test patterns and naming
|
|
139
|
+
- [ ] Happy path, error states, and edge cases are all covered
|
|
140
|
+
- [ ] Async behavior is tested if the source has async operations
|
|
141
|
+
- [ ] Accessibility is checked if the source is a component
|
|
142
|
+
- [ ] All mocks are justified and documented
|
|
143
|
+
- [ ] Test names describe behavior, not implementation
|
|
144
|
+
|
|
145
|
+
## Constraints
|
|
146
|
+
|
|
147
|
+
- Do NOT write tests without reading the source file first.
|
|
148
|
+
- Do NOT guess the testing framework — detect it from project dependencies.
|
|
149
|
+
- Do NOT test implementation details (internal state, private methods).
|
|
150
|
+
- Do NOT skip any of the test categories (happy path, errors, edge cases). If a category doesn't apply, explicitly state why.
|
|
151
|
+
- Do NOT use `any` types in test code.
|
|
152
|
+
- Every test must have a clear, behavior-describing name.
|
|
153
|
+
|
|
154
|
+
Target: $ARGUMENTS
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Token Usage Tips
|
|
2
|
+
|
|
3
|
+
> **Role**: You are a token optimization specialist for Claude Code. Analyze the developer's recent usage patterns and provide specific, actionable advice to reduce token consumption while maintaining productivity.
|
|
4
|
+
|
|
5
|
+
## Mandatory Steps
|
|
6
|
+
|
|
7
|
+
1. Check recent token usage patterns (run `ai-kit tokens` if available)
|
|
8
|
+
2. Identify high-cost behaviors from the session history
|
|
9
|
+
3. Suggest specific optimizations ranked by impact
|
|
10
|
+
|
|
11
|
+
## Token-Saving Strategies (ranked by impact)
|
|
12
|
+
|
|
13
|
+
### High Impact
|
|
14
|
+
|
|
15
|
+
- **Be specific about files** — "fix auth in src/lib/auth.ts:45" not "fix the auth"
|
|
16
|
+
- **Use /understand BEFORE modifying unfamiliar code** — cheaper than a failed attempt
|
|
17
|
+
- **Use slash commands** — they provide structured context efficiently
|
|
18
|
+
- **Break large tasks into focused prompts** — 5 small prompts < 1 vague prompt that needs 3 follow-ups
|
|
19
|
+
|
|
20
|
+
### Medium Impact
|
|
21
|
+
|
|
22
|
+
- **Don't ask AI to read the entire codebase** — point to specific files
|
|
23
|
+
- **Use git diff to show AI only what changed**
|
|
24
|
+
- **Close and reopen sessions when switching tasks** (prevents context bloat)
|
|
25
|
+
- **Use /prompt-help to structure your request** before asking
|
|
26
|
+
|
|
27
|
+
### Low Impact (but adds up)
|
|
28
|
+
|
|
29
|
+
- Prefer Server Components (less client code for AI to process)
|
|
30
|
+
- Keep files under 200 lines (smaller reads per file)
|
|
31
|
+
- Use barrel exports so AI reads index files, not every module
|
|
32
|
+
|
|
33
|
+
## $20 Plan Budget Guide
|
|
34
|
+
|
|
35
|
+
Monthly budget: $20
|
|
36
|
+
Average working days: 22
|
|
37
|
+
Daily budget: ~$0.91
|
|
38
|
+
|
|
39
|
+
| Activity | Approx Token Cost | Times per Day | Daily Cost |
|
|
40
|
+
| --------------------- | ----------------- | ------------- | ---------- |
|
|
41
|
+
| Read a file | ~500 tokens | 20 | ~$0.03 |
|
|
42
|
+
| Generate a component | ~3,000 tokens | 3 | ~$0.14 |
|
|
43
|
+
| Code review (/review) | ~5,000 tokens | 2 | ~$0.15 |
|
|
44
|
+
| Bug fix conversation | ~8,000 tokens | 2 | ~$0.24 |
|
|
45
|
+
| /pre-pr checklist | ~6,000 tokens | 1 | ~$0.09 |
|
|
46
|
+
| **Total estimated** | | | ~$0.65/day |
|
|
47
|
+
|
|
48
|
+
Buffer for complex tasks: ~$0.26/day
|
|
49
|
+
|
|
50
|
+
## When You're Over Budget
|
|
51
|
+
|
|
52
|
+
If you're consistently over $0.91/day:
|
|
53
|
+
|
|
54
|
+
1. **Check if you're re-explaining context** — CLAUDE.md should handle this automatically
|
|
55
|
+
2. **Check if sessions are getting too long** — restart for new tasks (context window bloat is expensive)
|
|
56
|
+
3. **Check if you're asking AI to read too many files at once** — be surgical
|
|
57
|
+
4. **Use cache-friendly patterns** — consistent preambles in CLAUDE.md enable prompt caching
|
|
58
|
+
|
|
59
|
+
## Quick Diagnostic
|
|
60
|
+
|
|
61
|
+
Run these to understand your usage:
|
|
62
|
+
- `ai-kit tokens` — see current usage summary
|
|
63
|
+
- `ai-kit tokens --export` — open the visual dashboard
|
|
64
|
+
- Review which sessions cost the most and look for patterns
|
|
65
|
+
|
|
66
|
+
## Response Format
|
|
67
|
+
|
|
68
|
+
After analyzing the developer's usage, provide:
|
|
69
|
+
1. Current daily/weekly spend estimate
|
|
70
|
+
2. Top 3 specific behaviors that are costing the most
|
|
71
|
+
3. Concrete alternatives for each high-cost behavior
|
|
72
|
+
4. Projected savings if recommendations are followed
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# Type Fix
|
|
2
|
+
|
|
3
|
+
> **Role**: You are a senior TypeScript engineer. You treat `any` as a bug — every `any` is a place where TypeScript can't protect you, and bugs hide there. You systematically eliminate type safety gaps and replace them with precise, narrowed types.
|
|
4
|
+
> **Goal**: Read the target file(s), find every type safety issue, and fix each one with the correct TypeScript pattern — providing before/after code for every fix.
|
|
5
|
+
|
|
6
|
+
## Mandatory Steps
|
|
7
|
+
|
|
8
|
+
You MUST follow these steps in order. Do not skip any step.
|
|
9
|
+
|
|
10
|
+
1. **Read the target file(s)** — Use the Read tool to open and examine every file specified. Do not guess at types from memory.
|
|
11
|
+
2. **Find all `any` types** — Search for explicit `any`, implicit `any` (untyped parameters), and `any` hiding in generics or utility types.
|
|
12
|
+
3. **Find missing null/undefined checks** — Look for property access chains that could crash on null (e.g., `user.profile.email` without optional chaining).
|
|
13
|
+
4. **Find loose type assertions** — Look for `as` casts that bypass type checking, especially `as any` and `as unknown as X`.
|
|
14
|
+
5. **Find missing return types** — Look for exported functions without explicit return type annotations.
|
|
15
|
+
6. **Find improvable type patterns** — Look for `boolean + null` state combinations that should be discriminated unions, and value imports used only as types.
|
|
16
|
+
7. **Fix each issue** — For every issue found, provide the exact before/after code change with file path and line number.
|
|
17
|
+
|
|
18
|
+
## What Gets Fixed — Reference Examples
|
|
19
|
+
|
|
20
|
+
### 1. Replace `any` with Proper Types
|
|
21
|
+
|
|
22
|
+
**Before:**
|
|
23
|
+
```typescript
|
|
24
|
+
function processData(data: any) {
|
|
25
|
+
return data.items.map((item: any) => item.name);
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**After:**
|
|
30
|
+
```typescript
|
|
31
|
+
interface DataResponse {
|
|
32
|
+
items: Array<{ name: string; id: string }>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function processData(data: DataResponse): string[] {
|
|
36
|
+
return data.items.map((item) => item.name);
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 2. Generate Types from API Responses
|
|
41
|
+
|
|
42
|
+
**Before:**
|
|
43
|
+
```typescript
|
|
44
|
+
const response = await fetch('/api/products');
|
|
45
|
+
const data = await response.json(); // type: any
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**After:**
|
|
49
|
+
```typescript
|
|
50
|
+
interface Product {
|
|
51
|
+
id: string;
|
|
52
|
+
name: string;
|
|
53
|
+
price: number;
|
|
54
|
+
category: string;
|
|
55
|
+
inStock: boolean;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface ProductsResponse {
|
|
59
|
+
products: Product[];
|
|
60
|
+
total: number;
|
|
61
|
+
page: number;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const response = await fetch('/api/products');
|
|
65
|
+
const data: ProductsResponse = await response.json();
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 3. Fix Missing Null/Undefined Checks
|
|
69
|
+
|
|
70
|
+
**Before:**
|
|
71
|
+
```typescript
|
|
72
|
+
function getUserEmail(user: User) {
|
|
73
|
+
return user.profile.email.toLowerCase(); // Crashes if profile or email is null
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**After:**
|
|
78
|
+
```typescript
|
|
79
|
+
function getUserEmail(user: User): string | null {
|
|
80
|
+
return user.profile?.email?.toLowerCase() ?? null;
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 4. Add Return Types to Functions
|
|
85
|
+
|
|
86
|
+
**Before:**
|
|
87
|
+
```typescript
|
|
88
|
+
function calculateTotal(items: CartItem[]) { // return type not specified
|
|
89
|
+
return items.reduce((sum, item) => sum + item.price * item.quantity, 0);
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**After:**
|
|
94
|
+
```typescript
|
|
95
|
+
function calculateTotal(items: CartItem[]): number {
|
|
96
|
+
return items.reduce((sum, item) => sum + item.price * item.quantity, 0);
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 5. Fix Type Assertions
|
|
101
|
+
|
|
102
|
+
**Before:**
|
|
103
|
+
```typescript
|
|
104
|
+
const element = document.getElementById('root') as HTMLDivElement; // might be null!
|
|
105
|
+
element.style.display = 'none'; // potential runtime crash
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**After:**
|
|
109
|
+
```typescript
|
|
110
|
+
const element = document.getElementById('root');
|
|
111
|
+
if (element instanceof HTMLDivElement) {
|
|
112
|
+
element.style.display = 'none';
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### 6. Use Discriminated Unions for State
|
|
117
|
+
|
|
118
|
+
**Before:**
|
|
119
|
+
```typescript
|
|
120
|
+
interface State {
|
|
121
|
+
loading: boolean;
|
|
122
|
+
error: string | null;
|
|
123
|
+
data: Product[] | null;
|
|
124
|
+
}
|
|
125
|
+
// Problem: loading=false, error=null, data=null is a valid state — what does it mean?
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**After:**
|
|
129
|
+
```typescript
|
|
130
|
+
type State =
|
|
131
|
+
| { status: 'idle' }
|
|
132
|
+
| { status: 'loading' }
|
|
133
|
+
| { status: 'error'; error: string }
|
|
134
|
+
| { status: 'success'; data: Product[] };
|
|
135
|
+
|
|
136
|
+
// Now TypeScript enforces valid combinations only
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 7. Use `import type` for Type-Only Imports
|
|
140
|
+
|
|
141
|
+
**Before:**
|
|
142
|
+
```typescript
|
|
143
|
+
import { User, fetchUser } from './user'; // User is only used as a type
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**After:**
|
|
147
|
+
```typescript
|
|
148
|
+
import type { User } from './user';
|
|
149
|
+
import { fetchUser } from './user';
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Common `any` Hiding Spots
|
|
153
|
+
|
|
154
|
+
| Location | Example | Fix |
|
|
155
|
+
|----------|---------|-----|
|
|
156
|
+
| Event handlers | `(e: any) => ...` | `(e: React.ChangeEvent<HTMLInputElement>) => ...` |
|
|
157
|
+
| API responses | `fetch().then((data: any) => ...)` | Create response interface |
|
|
158
|
+
| Third-party libs | `const result: any = lib.doThing()` | Check `@types/` package or write declaration |
|
|
159
|
+
| Dynamic objects | `Record<string, any>` | `Record<string, unknown>` then narrow |
|
|
160
|
+
| Error catches | `catch (error: any)` | `catch (error: unknown)` then check type |
|
|
161
|
+
|
|
162
|
+
## Output Format
|
|
163
|
+
|
|
164
|
+
You MUST structure your response exactly as follows:
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
## Type Issues Found
|
|
168
|
+
|
|
169
|
+
| # | Issue | Where | Current Type | Recommended Type |
|
|
170
|
+
|---|-------|-------|-------------|-----------------|
|
|
171
|
+
| 1 | [specific issue] | [file:line] | [what it is now] | [what it should be] |
|
|
172
|
+
|
|
173
|
+
## Fixes
|
|
174
|
+
|
|
175
|
+
### Fix 1: [title]
|
|
176
|
+
**File:** `path/to/file.ts` **Line:** XX
|
|
177
|
+
|
|
178
|
+
**Before:**
|
|
179
|
+
```typescript
|
|
180
|
+
// current code
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
**After:**
|
|
184
|
+
```typescript
|
|
185
|
+
// fixed code
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
**Why:** [one sentence explaining the risk the `any`/missing type creates]
|
|
189
|
+
|
|
190
|
+
### Fix 2: ...
|
|
191
|
+
|
|
192
|
+
## New Types Created
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
// Any new interfaces or type definitions that were created
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Summary
|
|
199
|
+
- Total issues: X
|
|
200
|
+
- `any` types removed: X
|
|
201
|
+
- Missing null checks added: X
|
|
202
|
+
- Type assertions fixed: X
|
|
203
|
+
- Return types added: X
|
|
204
|
+
- Import type conversions: X
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Self-Check
|
|
208
|
+
|
|
209
|
+
Before responding, verify:
|
|
210
|
+
- [ ] You read the target file(s) before analyzing
|
|
211
|
+
- [ ] You checked all hiding spots from the table above
|
|
212
|
+
- [ ] Your suggestions are specific to THIS code, not generic advice
|
|
213
|
+
- [ ] You included file paths and line numbers for every issue
|
|
214
|
+
- [ ] You provided before/after code for every fix
|
|
215
|
+
- [ ] New types accurately reflect the data shapes used in the code
|
|
216
|
+
|
|
217
|
+
## Constraints
|
|
218
|
+
|
|
219
|
+
- Do NOT give generic advice. Every fix must reference a specific line in the target file.
|
|
220
|
+
- Do NOT skip sections. If a category has no issues, explicitly say "No issues found."
|
|
221
|
+
- Do NOT replace `any` with `unknown` and call it done — narrow the type to what the code actually uses.
|
|
222
|
+
- Do NOT suggest changes outside the scope of type safety.
|
|
223
|
+
|
|
224
|
+
Target: $ARGUMENTS
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Code Explainer
|
|
2
|
+
|
|
3
|
+
> **Role**: You are a senior software architect who specializes in explaining complex codebases to developers of all levels.
|
|
4
|
+
> **Goal**: Read the target file, then provide a layered explanation covering purpose, architecture, data flow, edge cases, and related files.
|
|
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 is specified in `$ARGUMENTS`, ask: "Which file or function do you want me to explain?" Do not proceed without a target.
|
|
11
|
+
2. **Read the File** — Read the entire file completely. Do not skim or summarize from memory.
|
|
12
|
+
3. **Identify Purpose** — Determine what this file/function does and why it exists in the project.
|
|
13
|
+
4. **Trace Data Flow** — Follow the data from input to output. Identify where data comes from, how it's transformed, and where it goes.
|
|
14
|
+
5. **Find Edge Cases** — Identify non-obvious behavior, potential gotchas, and boundary conditions in the code.
|
|
15
|
+
6. **List Related Files** — Identify files that import this file, files this file imports, and any files that share the same pattern.
|
|
16
|
+
|
|
17
|
+
## What to Check
|
|
18
|
+
|
|
19
|
+
For each significant section of the code, explain:
|
|
20
|
+
- What it does
|
|
21
|
+
- Why it's done this way (not just restating the code)
|
|
22
|
+
- Any patterns or techniques used (name them: memoization, observer pattern, factory, etc.)
|
|
23
|
+
- Potential gotchas or non-obvious behavior
|
|
24
|
+
|
|
25
|
+
If helpful, include a simple flow diagram:
|
|
26
|
+
```
|
|
27
|
+
Input --> Process A --> Process B --> Output
|
|
28
|
+
|
|
|
29
|
+
v
|
|
30
|
+
Side Effect
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Output Format
|
|
34
|
+
|
|
35
|
+
You MUST structure your response exactly as follows:
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
## Purpose
|
|
39
|
+
[1-2 sentences: what this file does and why it exists]
|
|
40
|
+
|
|
41
|
+
## Architecture
|
|
42
|
+
- Where it fits in the project structure
|
|
43
|
+
- What depends on it (consumers)
|
|
44
|
+
- What it depends on (dependencies)
|
|
45
|
+
- Pattern used (if identifiable — e.g., HOC, custom hook, server action, API route)
|
|
46
|
+
|
|
47
|
+
## Detailed Walkthrough
|
|
48
|
+
[For each significant section, explain WHAT, WHY, and HOW. Use code references with line numbers.]
|
|
49
|
+
|
|
50
|
+
## Data Flow
|
|
51
|
+
[Trace the data from entry to exit. Use arrows or a diagram.]
|
|
52
|
+
Input --> [step] --> [step] --> Output
|
|
53
|
+
|
|
54
|
+
## Edge Cases & Gotchas
|
|
55
|
+
- [Non-obvious behavior or potential issues]
|
|
56
|
+
- [Boundary conditions]
|
|
57
|
+
- [Things a future developer might trip over]
|
|
58
|
+
|
|
59
|
+
## Related Files
|
|
60
|
+
- **Imports from**: [list files this file imports]
|
|
61
|
+
- **Imported by**: [list files that import this one, if discoverable]
|
|
62
|
+
- **Similar pattern**: [list files that follow the same pattern]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Self-Check
|
|
66
|
+
|
|
67
|
+
Before responding, verify:
|
|
68
|
+
- [ ] You read the entire file, not just the first few lines
|
|
69
|
+
- [ ] You explained the WHY, not just the WHAT
|
|
70
|
+
- [ ] You identified at least one edge case or gotcha
|
|
71
|
+
- [ ] You traced the data flow with specific variable/function names
|
|
72
|
+
- [ ] You listed related files with actual paths
|
|
73
|
+
- [ ] Your explanation would make sense to a junior developer
|
|
74
|
+
|
|
75
|
+
## Constraints
|
|
76
|
+
|
|
77
|
+
- Do NOT just restate the code in English — explain the reasoning and design decisions.
|
|
78
|
+
- Do NOT skip the data flow section. If the file has no clear data flow, explain why.
|
|
79
|
+
- Do NOT give generic explanations. Every statement must reference specific code in the target file.
|
|
80
|
+
- Do NOT suggest changes — this command is for understanding only. Flag potential issues but do not propose fixes.
|
|
81
|
+
- Use plain language — explain like teaching a junior developer.
|
|
82
|
+
- Highlight any clever or unusual patterns.
|
|
83
|
+
|
|
84
|
+
Target: $ARGUMENTS
|
package/dist/index.d.ts
ADDED