anchi-kit 1.2.0 → 1.2.1
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/.antigravity/skills/article-extractor/SKILL.md +52 -0
- package/.antigravity/skills/artifacts-builder/SKILL.md +63 -0
- package/.antigravity/skills/aws-deployment/SKILL.md +85 -0
- package/.antigravity/skills/brainstorming/SKILL.md +73 -0
- package/.antigravity/skills/canvas-design/SKILL.md +62 -0
- package/.antigravity/skills/changelog-generator/SKILL.md +149 -0
- package/.antigravity/skills/changelog-generator/assets/changelog-template.md +60 -0
- package/.antigravity/skills/changelog-generator/scripts/generate-changelog.js +181 -0
- package/.antigravity/skills/claude-code/references/advanced-features.md +399 -0
- package/.antigravity/skills/claude-code/references/agent-skills.md +399 -0
- package/.antigravity/skills/claude-code/references/api-reference.md +498 -0
- package/.antigravity/skills/claude-code/references/best-practices.md +447 -0
- package/.antigravity/skills/claude-code/references/cicd-integration.md +428 -0
- package/.antigravity/skills/claude-code/references/common-workflows.md +119 -0
- package/.antigravity/skills/claude-code/references/configuration.md +480 -0
- package/.antigravity/skills/claude-code/references/enterprise-features.md +472 -0
- package/.antigravity/skills/claude-code/references/getting-started.md +252 -0
- package/.antigravity/skills/claude-code/references/hooks-and-plugins.md +444 -0
- package/.antigravity/skills/claude-code/references/hooks-comprehensive.md +622 -0
- package/.antigravity/skills/claude-code/references/ide-integration.md +316 -0
- package/.antigravity/skills/claude-code/references/mcp-integration.md +386 -0
- package/.antigravity/skills/claude-code/references/slash-commands.md +489 -0
- package/.antigravity/skills/claude-code/references/troubleshooting.md +456 -0
- package/.antigravity/skills/claude-code/skill.md +60 -0
- package/.antigravity/skills/code-quality/SKILL.md +273 -0
- package/.antigravity/skills/comprehensive-review/complexity.md +11 -0
- package/.antigravity/skills/comprehensive-review/index.yaml +19 -0
- package/.antigravity/skills/comprehensive-review/maintainability.md +12 -0
- package/.antigravity/skills/comprehensive-review/readability.md +12 -0
- package/.antigravity/skills/content-research-writer/SKILL.md +65 -0
- package/.antigravity/skills/csv-data-analyzer/SKILL.md +91 -0
- package/.antigravity/skills/d3-visualization/SKILL.md +65 -0
- package/.antigravity/skills/debugging/references/root-cause-analysis-methods.md +140 -0
- package/.antigravity/skills/engineering-discipline/incremental-change.md +15 -0
- package/.antigravity/skills/engineering-discipline/index.yaml +30 -0
- package/.antigravity/skills/engineering-discipline/planning-first.md +18 -0
- package/.antigravity/skills/engineering-discipline/reasoning-clarity.md +19 -0
- package/.antigravity/skills/engineering-discipline/verify-before-commit.md +17 -0
- package/.antigravity/skills/file-organizer/SKILL.md +64 -0
- package/.antigravity/skills/git-automation/SKILL.md +68 -0
- package/.antigravity/skills/git-automation/references/branch-finishing.md +64 -0
- package/.antigravity/skills/impact-scoring/SKILL.md +219 -0
- package/.antigravity/skills/kaizen/SKILL.md +94 -0
- package/.antigravity/skills/performance-patterns/SKILL.md +209 -0
- package/.antigravity/skills/playwright-testing/SKILL.md +115 -0
- package/.antigravity/skills/playwright-testing/references/playwright-patterns.md +122 -0
- package/.antigravity/skills/prompt-engineering/SKILL.md +126 -0
- package/.antigravity/skills/prompt-engineering/references/anthropic-best-practices.md +160 -0
- package/.antigravity/skills/pypict-testing/SKILL.md +79 -0
- package/.antigravity/skills/review-implementing/SKILL.md +287 -0
- package/.antigravity/skills/security-audit/SKILL.md +263 -0
- package/.antigravity/skills/software-architecture/SKILL.md +91 -0
- package/.antigravity/skills/software-architecture/references/solid-principles.md +293 -0
- package/.antigravity/skills/subagent-driven-development/SKILL.md +237 -0
- package/.antigravity/skills/test-driven-development/SKILL.md +130 -0
- package/.antigravity/skills/test-driven-development/references/tdd-patterns.md +124 -0
- package/.antigravity/skills/test-driven-development/references/testing-strategies.md +131 -0
- package/.antigravity/skills/test-fixing/SKILL.md +256 -0
- package/.antigravity/skills/theme-factory/SKILL.md +63 -0
- package/.antigravity/workflows/clean.md +333 -0
- package/.antigravity/workflows/health.md +228 -0
- package/.cursor/skills/_packs/common/pack-architecture.md +40 -0
- package/.cursor/skills/_packs/common/pack-devops.md +43 -0
- package/.cursor/skills/_packs/common/pack-productivity.md +37 -0
- package/.cursor/skills/_packs/common/pack-quality.md +41 -0
- package/.cursor/skills/_packs/data/pack-ai.md +41 -0
- package/.cursor/skills/_packs/data/pack-data-science.md +36 -0
- package/.cursor/skills/_packs/mobile/pack-mobile.md +40 -0
- package/.cursor/skills/_packs/web/pack-backend.md +61 -0
- package/.cursor/skills/_packs/web/pack-frontend.md +66 -0
- package/.cursor/skills/_packs/web3/pack-blockchain.md +37 -0
- package/.cursor/skills/advanced-coding/references/getting-started.md +93 -0
- package/.cursor/skills/advanced-coding/skill.md +34 -0
- package/.cursor/skills/template-skill/SKILL.md +6 -0
- package/README.md +1 -1
- package/docs/reference/SECURITY.md +1 -1
- package/package.json +2 -2
- package/src/cli.js +5 -5
- package/src/commands/dashboard.js +3 -3
- package/src/commands/init.js +15 -3
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# Performance Patterns Skill
|
|
2
|
+
|
|
3
|
+
> Domain knowledge for writing performant code across all layers.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 📋 Database Performance Patterns
|
|
8
|
+
|
|
9
|
+
### N+1 Query Problem
|
|
10
|
+
|
|
11
|
+
**❌ Bad:**
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
const users = await prisma.user.findMany();
|
|
15
|
+
for (const user of users) {
|
|
16
|
+
const posts = await prisma.post.findMany({ where: { userId: user.id } });
|
|
17
|
+
}
|
|
18
|
+
// 1 query for users + N queries for posts = N+1
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**✅ Good:**
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
const users = await prisma.user.findMany({
|
|
25
|
+
include: { posts: true }, // Single query with JOIN
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
### Pagination
|
|
32
|
+
|
|
33
|
+
**Always paginate large datasets:**
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
// Cursor-based (recommended for large datasets)
|
|
37
|
+
const users = await prisma.user.findMany({
|
|
38
|
+
take: 20,
|
|
39
|
+
skip: 1,
|
|
40
|
+
cursor: { id: lastUserId },
|
|
41
|
+
orderBy: { id: "asc" },
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Offset-based (simpler but slower for large offsets)
|
|
45
|
+
const users = await prisma.user.findMany({
|
|
46
|
+
take: 20,
|
|
47
|
+
skip: page * 20,
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
### Indexing Strategy
|
|
54
|
+
|
|
55
|
+
```sql
|
|
56
|
+
-- Always index:
|
|
57
|
+
-- 1. Foreign keys
|
|
58
|
+
CREATE INDEX idx_posts_user_id ON posts(user_id);
|
|
59
|
+
|
|
60
|
+
-- 2. Frequently filtered columns
|
|
61
|
+
CREATE INDEX idx_users_email ON users(email);
|
|
62
|
+
|
|
63
|
+
-- 3. Frequently sorted columns
|
|
64
|
+
CREATE INDEX idx_posts_created_at ON posts(created_at DESC);
|
|
65
|
+
|
|
66
|
+
-- 4. Composite for multi-column queries
|
|
67
|
+
CREATE INDEX idx_posts_user_status ON posts(user_id, status);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
### Caching Patterns
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
// 1. Request-level cache (React Query / SWR)
|
|
76
|
+
const { data } = useQuery(["user", id], fetchUser, {
|
|
77
|
+
staleTime: 5 * 60 * 1000, // 5 minutes
|
|
78
|
+
cacheTime: 30 * 60 * 1000, // 30 minutes
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// 2. Server-side cache (Redis)
|
|
82
|
+
const cached = await redis.get(`user:${id}`);
|
|
83
|
+
if (cached) return JSON.parse(cached);
|
|
84
|
+
|
|
85
|
+
const user = await prisma.user.findUnique({ where: { id } });
|
|
86
|
+
await redis.setex(`user:${id}`, 300, JSON.stringify(user)); // 5 min TTL
|
|
87
|
+
|
|
88
|
+
// 3. CDN cache (API response headers)
|
|
89
|
+
res.setHeader("Cache-Control", "public, max-age=60, stale-while-revalidate=30");
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
### Lazy Loading vs Eager Loading
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
// Eager: Load everything upfront
|
|
98
|
+
const user = await prisma.user.findUnique({
|
|
99
|
+
where: { id },
|
|
100
|
+
include: { posts: true, comments: true, profile: true }, // Heavy
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Lazy: Load on demand
|
|
104
|
+
const user = await prisma.user.findUnique({ where: { id } });
|
|
105
|
+
// Later when needed:
|
|
106
|
+
const posts = await prisma.post.findMany({ where: { userId: user.id } });
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**When to use which:**
|
|
110
|
+
| Scenario | Strategy |
|
|
111
|
+
|----------|----------|
|
|
112
|
+
| List view | Eager (one query) |
|
|
113
|
+
| Detail view | Lazy (load sections) |
|
|
114
|
+
| Dashboard | Parallel lazy |
|
|
115
|
+
| Export | Eager with batching |
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
### Connection Pooling
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
// Prisma (prisma/schema.prisma)
|
|
123
|
+
datasource db {
|
|
124
|
+
provider = "postgresql"
|
|
125
|
+
url = env("DATABASE_URL")
|
|
126
|
+
connection_limit = 10 // Adjust based on traffic
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Serverless (Prisma Accelerate or PgBouncer)
|
|
130
|
+
// Use connection pooler URL for serverless environments
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## 📋 API Performance Patterns
|
|
136
|
+
|
|
137
|
+
### Parallel Requests
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
// ❌ Sequential (slow)
|
|
141
|
+
const user = await getUser(id);
|
|
142
|
+
const posts = await getPosts(id);
|
|
143
|
+
const comments = await getComments(id);
|
|
144
|
+
|
|
145
|
+
// ✅ Parallel (fast)
|
|
146
|
+
const [user, posts, comments] = await Promise.all([
|
|
147
|
+
getUser(id),
|
|
148
|
+
getPosts(id),
|
|
149
|
+
getComments(id),
|
|
150
|
+
]);
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
### Debounce & Throttle
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
// Debounce: Wait for user to stop typing
|
|
159
|
+
const debouncedSearch = debounce((query) => {
|
|
160
|
+
fetch(`/api/search?q=${query}`);
|
|
161
|
+
}, 300);
|
|
162
|
+
|
|
163
|
+
// Throttle: Max 1 request per 500ms
|
|
164
|
+
const throttledScroll = throttle(() => {
|
|
165
|
+
loadMoreItems();
|
|
166
|
+
}, 500);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## 📋 Frontend Performance Patterns
|
|
172
|
+
|
|
173
|
+
### React Optimization
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
// 1. Memoize expensive computations
|
|
177
|
+
const sortedUsers = useMemo(
|
|
178
|
+
() => users.sort((a, b) => a.name.localeCompare(b.name)),
|
|
179
|
+
[users]
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
// 2. Memoize callbacks
|
|
183
|
+
const handleClick = useCallback(() => {
|
|
184
|
+
doSomething(id);
|
|
185
|
+
}, [id]);
|
|
186
|
+
|
|
187
|
+
// 3. Virtualize long lists
|
|
188
|
+
import { FixedSizeList } from "react-window";
|
|
189
|
+
<FixedSizeList height={600} itemCount={10000} itemSize={50}>
|
|
190
|
+
{({ index, style }) => <Row style={style} data={items[index]} />}
|
|
191
|
+
</FixedSizeList>;
|
|
192
|
+
|
|
193
|
+
// 4. Code splitting
|
|
194
|
+
const HeavyComponent = lazy(() => import("./HeavyComponent"));
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## 📋 Quick Checklist
|
|
200
|
+
|
|
201
|
+
Before any implementation, verify:
|
|
202
|
+
|
|
203
|
+
- [ ] No N+1 queries
|
|
204
|
+
- [ ] Large lists paginated
|
|
205
|
+
- [ ] Indexes on filtered/sorted columns
|
|
206
|
+
- [ ] Caching for repeated reads
|
|
207
|
+
- [ ] Parallel requests where possible
|
|
208
|
+
- [ ] Connection pool configured
|
|
209
|
+
- [ ] React components optimized
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: playwright-testing
|
|
3
|
+
description: Automated end-to-end testing using Playwright test framework. Use for writing automated test suites, CI/CD integration, regression testing, and cross-browser validation. For manual debugging and performance profiling, use chrome-devtools skill instead.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Playwright Testing
|
|
7
|
+
|
|
8
|
+
Browser automation and end-to-end testing for web applications using Playwright.
|
|
9
|
+
|
|
10
|
+
## When to Use
|
|
11
|
+
|
|
12
|
+
- Testing web application UIs
|
|
13
|
+
- End-to-end (E2E) testing
|
|
14
|
+
- Browser automation tasks
|
|
15
|
+
- Visual regression testing
|
|
16
|
+
- Cross-browser testing
|
|
17
|
+
- Integration testing for frontend
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
### Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install -D @playwright/test
|
|
25
|
+
npx playwright install
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Basic Test
|
|
29
|
+
|
|
30
|
+
```javascript
|
|
31
|
+
// tests/example.spec.js
|
|
32
|
+
import { test, expect } from "@playwright/test";
|
|
33
|
+
|
|
34
|
+
test("homepage has title", async ({ page }) => {
|
|
35
|
+
await page.goto("http://localhost:3000");
|
|
36
|
+
await expect(page).toHaveTitle(/My App/);
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Run Tests
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npx playwright test # Run all tests
|
|
44
|
+
npx playwright test --ui # Run with UI mode
|
|
45
|
+
npx playwright test --debug # Debug mode
|
|
46
|
+
npx playwright test --headed # Show browser
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Common Patterns
|
|
50
|
+
|
|
51
|
+
See [references/playwright-patterns.md](references/playwright-patterns.md) for:
|
|
52
|
+
|
|
53
|
+
- Page Object Model
|
|
54
|
+
- Test data setup
|
|
55
|
+
- Authentication flows
|
|
56
|
+
- API mocking
|
|
57
|
+
- File upload/download
|
|
58
|
+
- Network interception
|
|
59
|
+
|
|
60
|
+
## Test Structure
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
test.describe("Login Flow", () => {
|
|
64
|
+
test("successful login", async ({ page }) => {
|
|
65
|
+
// Navigate
|
|
66
|
+
await page.goto("/login");
|
|
67
|
+
|
|
68
|
+
// Interact
|
|
69
|
+
await page.fill('input[name="email"]', "user@example.com");
|
|
70
|
+
await page.fill('input[name="password"]', "password");
|
|
71
|
+
await page.click('button[type="submit"]');
|
|
72
|
+
|
|
73
|
+
// Assert
|
|
74
|
+
await expect(page).toHaveURL("/dashboard");
|
|
75
|
+
await expect(page.locator("h1")).toContainText("Welcome");
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Best Practices
|
|
81
|
+
|
|
82
|
+
1. **Use Locators** - Prefer data-testid or semantic selectors
|
|
83
|
+
2. **Wait for Navigation** - Use auto-waiting, avoid timeouts
|
|
84
|
+
3. **Isolate Tests** - Each test should be independent
|
|
85
|
+
4. **Test Real Scenarios** - Simulate actual user behavior
|
|
86
|
+
5. **Handle State** - Reset state between tests
|
|
87
|
+
6. **Use Fixtures** - Share setup across tests
|
|
88
|
+
|
|
89
|
+
## Configuration
|
|
90
|
+
|
|
91
|
+
### playwright.config.js
|
|
92
|
+
|
|
93
|
+
```javascript
|
|
94
|
+
import { defineConfig } from "@playwright/test";
|
|
95
|
+
|
|
96
|
+
export default defineConfig({
|
|
97
|
+
testDir: "./tests",
|
|
98
|
+
timeout: 30000,
|
|
99
|
+
retries: 2,
|
|
100
|
+
use: {
|
|
101
|
+
baseURL: "http://localhost:3000",
|
|
102
|
+
screenshot: "only-on-failure",
|
|
103
|
+
trace: "retain-on-failure",
|
|
104
|
+
},
|
|
105
|
+
projects: [
|
|
106
|
+
{ name: "chromium", use: { ...devices["Desktop Chrome"] } },
|
|
107
|
+
{ name: "firefox", use: { ...devices["Desktop Firefox"] } },
|
|
108
|
+
],
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## References
|
|
113
|
+
|
|
114
|
+
- [Playwright Patterns](references/playwright-patterns.md) - Common test patterns
|
|
115
|
+
- [Playwright Docs](https://playwright.dev/) - Official documentation
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# Playwright Patterns
|
|
2
|
+
|
|
3
|
+
## Page Object Model (POM)
|
|
4
|
+
|
|
5
|
+
```javascript
|
|
6
|
+
// pages/LoginPage.js
|
|
7
|
+
export class LoginPage {
|
|
8
|
+
constructor(page) {
|
|
9
|
+
this.page = page;
|
|
10
|
+
this.emailInput = page.locator('input[name="email"]');
|
|
11
|
+
this.passwordInput = page.locator('input[name="password"]');
|
|
12
|
+
this.submitButton = page.locator('button[type="submit"]');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async goto() {
|
|
16
|
+
await this.page.goto("/login");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async login(email, password) {
|
|
20
|
+
await this.emailInput.fill(email);
|
|
21
|
+
await this.passwordInput.fill(password);
|
|
22
|
+
await this.submitButton.click();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// tests/login.spec.js
|
|
27
|
+
import { LoginPage } from "../pages/LoginPage";
|
|
28
|
+
|
|
29
|
+
test("user can login", async ({ page }) => {
|
|
30
|
+
const loginPage = new LoginPage(page);
|
|
31
|
+
await loginPage.goto();
|
|
32
|
+
await loginPage.login("user@example.com", "password");
|
|
33
|
+
await expect(page).toHaveURL("/dashboard");
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Authentication Flow
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
// auth.setup.js - Run once to save auth state
|
|
41
|
+
import { test as setup } from "@playwright/test";
|
|
42
|
+
|
|
43
|
+
setup("authenticate", async ({ page }) => {
|
|
44
|
+
await page.goto("/login");
|
|
45
|
+
await page.fill('input[name="email"]', "user@example.com");
|
|
46
|
+
await page.fill('input[name="password"]', "password");
|
|
47
|
+
await page.click('button[type="submit"]');
|
|
48
|
+
|
|
49
|
+
await page.context().storageState({ path: "auth.json" });
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// playwright.config.js - Use saved auth state
|
|
53
|
+
export default defineConfig({
|
|
54
|
+
projects: [
|
|
55
|
+
{ name: "setup", testMatch: /auth\.setup\.js/ },
|
|
56
|
+
{
|
|
57
|
+
name: "authenticated",
|
|
58
|
+
use: { storageState: "auth.json" },
|
|
59
|
+
dependencies: ["setup"],
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## API Mocking
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
test("mock API response", async ({ page }) => {
|
|
69
|
+
await page.route("**/api/users", (route) => {
|
|
70
|
+
route.fulfill({
|
|
71
|
+
status: 200,
|
|
72
|
+
contentType: "application/json",
|
|
73
|
+
body: JSON.stringify([
|
|
74
|
+
{ id: 1, name: "John" },
|
|
75
|
+
{ id: 2, name: "Jane" },
|
|
76
|
+
]),
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
await page.goto("/users");
|
|
81
|
+
await expect(page.locator(".user-list")).toContainText("John");
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## File Upload
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
test("upload file", async ({ page }) => {
|
|
89
|
+
await page.goto("/upload");
|
|
90
|
+
|
|
91
|
+
const fileInput = page.locator('input[type="file"]');
|
|
92
|
+
await fileInput.setInputFiles("path/to/file.pdf");
|
|
93
|
+
|
|
94
|
+
await page.click('button:text("Upload")');
|
|
95
|
+
await expect(page.locator(".success")).toBeVisible();
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Network Interception
|
|
100
|
+
|
|
101
|
+
```javascript
|
|
102
|
+
test("wait for API call", async ({ page }) => {
|
|
103
|
+
const responsePromise = page.waitForResponse(
|
|
104
|
+
(response) =>
|
|
105
|
+
response.url().includes("/api/data") && response.status() === 200
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
await page.click('button:text("Load Data")');
|
|
109
|
+
const response = await responsePromise;
|
|
110
|
+
|
|
111
|
+
expect(response.ok()).toBeTruthy();
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Visual Testing
|
|
116
|
+
|
|
117
|
+
```javascript
|
|
118
|
+
test("visual regression", async ({ page }) => {
|
|
119
|
+
await page.goto("/dashboard");
|
|
120
|
+
await expect(page).toHaveScreenshot("dashboard.png");
|
|
121
|
+
});
|
|
122
|
+
```
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: prompt-engineering
|
|
3
|
+
description: Advanced prompt engineering techniques and Anthropic best practices for creating effective AI prompts, agents, and AI interactions. Use when creating AI agents, writing prompts, optimizing AI interactions, or building AI-powered features.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Prompt Engineering
|
|
7
|
+
|
|
8
|
+
Advanced techniques for crafting effective prompts and optimizing AI interactions.
|
|
9
|
+
|
|
10
|
+
## When to Use
|
|
11
|
+
|
|
12
|
+
- Creating AI agents or assistants
|
|
13
|
+
- Writing prompts for Claude or other LLMs
|
|
14
|
+
- Optimizing AI-powered features
|
|
15
|
+
- Debugging AI responses
|
|
16
|
+
- Building conversational interfaces
|
|
17
|
+
- Implementing RAG systems
|
|
18
|
+
|
|
19
|
+
## Core Principles
|
|
20
|
+
|
|
21
|
+
### 1. Be Clear and Specific
|
|
22
|
+
|
|
23
|
+
```markdown
|
|
24
|
+
❌ Bad: "Write code for a login system"
|
|
25
|
+
|
|
26
|
+
✅ Good: "Create a secure login system in Node.js with:
|
|
27
|
+
|
|
28
|
+
- Email/password authentication
|
|
29
|
+
- JWT tokens for sessions
|
|
30
|
+
- Password hashing with bcrypt
|
|
31
|
+
- Input validation
|
|
32
|
+
- Rate limiting (5 attempts/minute)"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 2. Provide Context
|
|
36
|
+
|
|
37
|
+
```markdown
|
|
38
|
+
Context: I'm building an e-commerce site with Next.js 14, PostgreSQL, and Stripe.
|
|
39
|
+
Task: Create a checkout flow that handles...
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 3. Use Examples (Few-Shot Learning)
|
|
43
|
+
|
|
44
|
+
```markdown
|
|
45
|
+
Convert these user messages to structured data:
|
|
46
|
+
|
|
47
|
+
Input: "Book a flight to NYC on Friday"
|
|
48
|
+
Output: {"action": "book_flight", "destination": "NYC", "date": "friday"}
|
|
49
|
+
|
|
50
|
+
Input: "Cancel my hotel reservation"
|
|
51
|
+
Output: {"action": "cancel", "type": "hotel"}
|
|
52
|
+
|
|
53
|
+
Now convert: "Find me a restaurant in Paris"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Anthropic Best Practices
|
|
57
|
+
|
|
58
|
+
See [references/anthropic-best-practices.md](references/anthropic-best-practices.md) for:
|
|
59
|
+
|
|
60
|
+
- Claude-specific techniques
|
|
61
|
+
- System prompts vs user prompts
|
|
62
|
+
- Tool use patterns
|
|
63
|
+
- Multi-turn conversations
|
|
64
|
+
- Handling refusals
|
|
65
|
+
|
|
66
|
+
## Prompt Patterns
|
|
67
|
+
|
|
68
|
+
See [references/prompt-patterns.md](references/prompt-patterns.md) for:
|
|
69
|
+
|
|
70
|
+
- Chain of Thought
|
|
71
|
+
- ReAct (Reasoning + Acting)
|
|
72
|
+
- Self-Consistency
|
|
73
|
+
- Tree of Thoughts
|
|
74
|
+
- Structured Output
|
|
75
|
+
|
|
76
|
+
## Effective Techniques
|
|
77
|
+
|
|
78
|
+
### Chain of Thought
|
|
79
|
+
|
|
80
|
+
```markdown
|
|
81
|
+
Solve this step-by-step:
|
|
82
|
+
|
|
83
|
+
Problem: A store has 15% off all items. An item costs $80. What's the final price?
|
|
84
|
+
|
|
85
|
+
Think through this:
|
|
86
|
+
|
|
87
|
+
1. Calculate discount amount
|
|
88
|
+
2. Subtract from original price
|
|
89
|
+
3. Show your work
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Role Assignment
|
|
93
|
+
|
|
94
|
+
```markdown
|
|
95
|
+
You are a senior software architect specializing in microservices.
|
|
96
|
+
Review this system design and provide:
|
|
97
|
+
|
|
98
|
+
1. Potential bottlenecks
|
|
99
|
+
2. Scalability concerns
|
|
100
|
+
3. Recommended improvements
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Structured Output
|
|
104
|
+
|
|
105
|
+
```markdown
|
|
106
|
+
Analyze this code and respond in JSON format:
|
|
107
|
+
{
|
|
108
|
+
"issues": [...],
|
|
109
|
+
"suggestions": [...],
|
|
110
|
+
"complexity_score": 1-10
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Debugging Prompts
|
|
115
|
+
|
|
116
|
+
1. **Too vague** → Add specific requirements
|
|
117
|
+
2. **Wrong format** → Provide output examples
|
|
118
|
+
3. **Inconsistent** → Add constraints and validation
|
|
119
|
+
4. **Verbose** → Request concise responses
|
|
120
|
+
5. **Off-topic** → Clarify scope and boundaries
|
|
121
|
+
|
|
122
|
+
## References
|
|
123
|
+
|
|
124
|
+
- [Anthropic Best Practices](references/anthropic-best-practices.md)
|
|
125
|
+
- [Prompt Patterns](references/prompt-patterns.md)
|
|
126
|
+
- [Claude Documentation](https://docs.anthropic.com/en/docs/)
|