contextos-agents 1.7.0 → 2.0.0-beta.2
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/.agents/AGENTS.md +1 -1
- package/.agents/adapters/aider/export.js +117 -99
- package/.agents/adapters/claude/export.js +68 -26
- package/.agents/adapters/copilot/export.js +90 -53
- package/.agents/adapters/cursor/export.js +80 -101
- package/.agents/adapters/drift-detector.js +196 -0
- package/.agents/adapters/gemini/export.js +76 -45
- package/.agents/adapters/pure-compiler.js +443 -0
- package/.agents/adapters/zed/export.js +104 -96
- package/.agents/compiled/registry.v2.json +504 -0
- package/.agents/compiled/registry.v2.sha256 +1 -0
- package/.agents/compiler/manifest-compiler.js +963 -0
- package/.agents/compiler/vendor/yaml.LICENSE.txt +13 -0
- package/.agents/compiler/vendor/yaml.SBOM.json +6 -0
- package/.agents/compiler/vendor/yaml.js +139 -0
- package/.agents/core/profiles/init.yaml +25 -0
- package/.agents/core/skills/context-manager/skill.yaml +3 -5
- package/.agents/core/skills/context-os/SKILL.md +3 -6
- package/.agents/core/skills/context-os/skill.yaml +3 -8
- package/.agents/core/skills/engineering-workflow/skill.yaml +1 -7
- package/.agents/core/skills/gemini-precision/skill.yaml +1 -6
- package/.agents/core/skills/gstack-roles/skill.yaml +3 -6
- package/.agents/core/skills/ponytail-mindset/skill.yaml +1 -7
- package/.agents/core/skills/security/skill.yaml +15 -3
- package/.agents/ctx.js +574 -111
- package/.agents/customization-dx.js +282 -0
- package/.agents/doctor.js +719 -64
- package/.agents/filesystem/index.js +71 -0
- package/.agents/filesystem/journaled-transaction.js +451 -0
- package/.agents/filesystem/lockfile-v2.js +275 -0
- package/.agents/filesystem/platform-hardening.js +222 -0
- package/.agents/filesystem/project-lock.js +218 -0
- package/.agents/filesystem/safe-path.js +256 -0
- package/.agents/generated/claude/skills/context-os/SKILL.md +1 -1
- package/.agents/generated/gemini/skills/context-os/SKILL.md +2 -2
- package/.agents/plugins/contextos/plugin.json +1 -1
- package/.agents/plugins.js +259 -60
- package/.agents/profiles.js +486 -51
- package/.agents/resolver.js +50 -534
- package/.agents/schemas/attestation.review.v1.json +111 -0
- package/.agents/schemas/attestation.verification.v1.json +85 -0
- package/.agents/schemas/lockfile.v2.schema.json +134 -0
- package/.agents/schemas/profile.v2.schema.json +114 -0
- package/.agents/schemas/runtime.thread.v1.json +192 -0
- package/.agents/schemas/skill.manifest.v2.json +177 -0
- package/.agents/schemas/verification.spec.v1.json +39 -0
- package/.agents/schemas/workspace.graph.schema.json +106 -0
- package/.agents/transaction-core/event-store.js +288 -0
- package/.agents/transaction-core/idempotency.js +129 -0
- package/.agents/transaction-core/ipc-lock.js +311 -0
- package/.agents/transaction-core/plugin-supply-chain-bundle.js +436 -0
- package/.agents/validate.js +44 -1
- package/.agents/watch.js +354 -102
- package/.agents/workspace/workspace-graph.js +778 -0
- package/README.md +59 -387
- package/benchmarks/v2/analysis/statistics.js +140 -0
- package/benchmarks/v2/analysis/stats.js +69 -0
- package/benchmarks/v2/arms/arm-definitions.js +79 -0
- package/benchmarks/v2/dataset.schema.json +34 -0
- package/benchmarks/v2/evaluators/index.js +25 -0
- package/benchmarks/v2/evaluators/verified-success.js +116 -0
- package/benchmarks/v2/harness/runner.js +88 -0
- package/benchmarks/v2/pilot-tasks.json +392 -0
- package/bin/commands/recover.js +88 -0
- package/bin/commands/update.js +80 -17
- package/bin/commands.js +62 -25
- package/bin/index.js +138 -81
- package/bin/lib/lockfile.js +5 -3
- package/bin/lib/safe-writer.js +34 -3
- package/package.json +85 -72
- package/registry.json +2 -2
- package/registry.v2.schema.json +86 -0
- package/.agents/core/profiles/backend.yaml +0 -47
- package/.agents/core/profiles/enterprise.yaml +0 -46
- package/.agents/core/profiles/frontend.yaml +0 -46
- package/.agents/core/profiles/hackathon.yaml +0 -45
- package/.agents/core/profiles/mvp.yaml +0 -44
- package/.agents/core/profiles/startup.yaml +0 -48
- package/.agents/core/skills/adapters/EXAMPLES.md +0 -19
- package/.agents/core/skills/adapters/SKILL.md +0 -105
- package/.agents/core/skills/adapters/TROUBLESHOOTING.md +0 -7
- package/.agents/core/skills/adapters/VALIDATION.json +0 -12
- package/.agents/core/skills/adapters/skill.yaml +0 -16
- package/.agents/core/skills/architecture-diagrams/SKILL.md +0 -108
- package/.agents/core/skills/architecture-diagrams/VALIDATION.json +0 -12
- package/.agents/core/skills/architecture-diagrams/skill.yaml +0 -12
- package/.agents/core/skills/brutalist-design/SKILL.md +0 -150
- package/.agents/core/skills/brutalist-design/VALIDATION.json +0 -12
- package/.agents/core/skills/brutalist-design/skill.yaml +0 -12
- package/.agents/core/skills/database/EXAMPLES.md +0 -74
- package/.agents/core/skills/database/SKILL.md +0 -101
- package/.agents/core/skills/database/TROUBLESHOOTING.md +0 -18
- package/.agents/core/skills/database/VALIDATION.json +0 -11
- package/.agents/core/skills/database/skill.yaml +0 -31
- package/.agents/core/skills/ddd/EXAMPLES.md +0 -42
- package/.agents/core/skills/ddd/SKILL.md +0 -247
- package/.agents/core/skills/ddd/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/ddd/VALIDATION.json +0 -12
- package/.agents/core/skills/ddd/ddd.md +0 -178
- package/.agents/core/skills/ddd/skill.yaml +0 -17
- package/.agents/core/skills/decisions/EXAMPLES.md +0 -35
- package/.agents/core/skills/decisions/SKILL.md +0 -90
- package/.agents/core/skills/decisions/TROUBLESHOOTING.md +0 -13
- package/.agents/core/skills/decisions/VALIDATION.json +0 -12
- package/.agents/core/skills/decisions/skill.yaml +0 -16
- package/.agents/core/skills/docker/EXAMPLES.md +0 -56
- package/.agents/core/skills/docker/SKILL.md +0 -63
- package/.agents/core/skills/docker/TROUBLESHOOTING.md +0 -18
- package/.agents/core/skills/docker/VALIDATION.json +0 -11
- package/.agents/core/skills/docker/skill.yaml +0 -29
- package/.agents/core/skills/fastapi/EXAMPLES.md +0 -36
- package/.agents/core/skills/fastapi/SKILL.md +0 -148
- package/.agents/core/skills/fastapi/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/fastapi/VALIDATION.json +0 -12
- package/.agents/core/skills/fastapi/fastapi.md +0 -112
- package/.agents/core/skills/fastapi/skill.yaml +0 -17
- package/.agents/core/skills/generators/EXAMPLES.md +0 -19
- package/.agents/core/skills/generators/SKILL.md +0 -112
- package/.agents/core/skills/generators/TROUBLESHOOTING.md +0 -7
- package/.agents/core/skills/generators/VALIDATION.json +0 -12
- package/.agents/core/skills/generators/skill.yaml +0 -25
- package/.agents/core/skills/generators/templates/API.md +0 -77
- package/.agents/core/skills/generators/templates/ARCHITECTURE.md +0 -70
- package/.agents/core/skills/generators/templates/DATABASE.md +0 -42
- package/.agents/core/skills/generators/templates/DECISION.md +0 -46
- package/.agents/core/skills/generators/templates/PRD.md +0 -67
- package/.agents/core/skills/generators/templates/PROJECT_GRAPH.md +0 -56
- package/.agents/core/skills/generators/templates/ROADMAP.md +0 -51
- package/.agents/core/skills/generators/templates/TASKS.md +0 -43
- package/.agents/core/skills/generators/templates/UI.md +0 -73
- package/.agents/core/skills/graphify/EXAMPLES.md +0 -73
- package/.agents/core/skills/graphify/SKILL.md +0 -130
- package/.agents/core/skills/graphify/VALIDATION.json +0 -12
- package/.agents/core/skills/graphify/skill.yaml +0 -18
- package/.agents/core/skills/impeccable-design/EXAMPLES.md +0 -26
- package/.agents/core/skills/impeccable-design/SKILL.md +0 -201
- package/.agents/core/skills/impeccable-design/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/impeccable-design/VALIDATION.json +0 -12
- package/.agents/core/skills/impeccable-design/skill.yaml +0 -20
- package/.agents/core/skills/interview-me/SKILL.md +0 -97
- package/.agents/core/skills/interview-me/VALIDATION.json +0 -12
- package/.agents/core/skills/interview-me/skill.yaml +0 -12
- package/.agents/core/skills/microservices/EXAMPLES.md +0 -38
- package/.agents/core/skills/microservices/SKILL.md +0 -164
- package/.agents/core/skills/microservices/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/microservices/VALIDATION.json +0 -12
- package/.agents/core/skills/microservices/microservices.md +0 -119
- package/.agents/core/skills/microservices/skill.yaml +0 -17
- package/.agents/core/skills/minimalist-design/SKILL.md +0 -113
- package/.agents/core/skills/minimalist-design/VALIDATION.json +0 -12
- package/.agents/core/skills/minimalist-design/skill.yaml +0 -12
- package/.agents/core/skills/nestjs/EXAMPLES.md +0 -40
- package/.agents/core/skills/nestjs/SKILL.md +0 -139
- package/.agents/core/skills/nestjs/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/nestjs/VALIDATION.json +0 -12
- package/.agents/core/skills/nestjs/nestjs.md +0 -103
- package/.agents/core/skills/nestjs/skill.yaml +0 -17
- package/.agents/core/skills/nextjs/EXAMPLES.md +0 -40
- package/.agents/core/skills/nextjs/SKILL.md +0 -163
- package/.agents/core/skills/nextjs/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/nextjs/VALIDATION.json +0 -12
- package/.agents/core/skills/nextjs/nextjs.md +0 -67
- package/.agents/core/skills/nextjs/skill.yaml +0 -17
- package/.agents/core/skills/node/EXAMPLES.md +0 -80
- package/.agents/core/skills/node/SKILL.md +0 -128
- package/.agents/core/skills/node/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/node/VALIDATION.json +0 -12
- package/.agents/core/skills/node/node.md +0 -87
- package/.agents/core/skills/node/skill.yaml +0 -17
- package/.agents/core/skills/performance/EXAMPLES.md +0 -30
- package/.agents/core/skills/performance/SKILL.md +0 -75
- package/.agents/core/skills/performance/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/performance/VALIDATION.json +0 -12
- package/.agents/core/skills/performance/performance.md +0 -52
- package/.agents/core/skills/performance/skill.yaml +0 -17
- package/.agents/core/skills/react/EXAMPLES.md +0 -79
- package/.agents/core/skills/react/SKILL.md +0 -132
- package/.agents/core/skills/react/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/react/VALIDATION.json +0 -12
- package/.agents/core/skills/react/react.md +0 -93
- package/.agents/core/skills/react/skill.yaml +0 -17
- package/.agents/core/skills/react-best-practices/SKILL.md +0 -155
- package/.agents/core/skills/react-best-practices/VALIDATION.json +0 -12
- package/.agents/core/skills/react-best-practices/skill.yaml +0 -14
- package/.agents/core/skills/redesign-audit/SKILL.md +0 -117
- package/.agents/core/skills/redesign-audit/VALIDATION.json +0 -12
- package/.agents/core/skills/redesign-audit/skill.yaml +0 -12
- package/.agents/core/skills/soft-design/SKILL.md +0 -108
- package/.agents/core/skills/soft-design/VALIDATION.json +0 -12
- package/.agents/core/skills/soft-design/skill.yaml +0 -12
- package/.agents/core/skills/state-management/EXAMPLES.md +0 -56
- package/.agents/core/skills/state-management/SKILL.md +0 -48
- package/.agents/core/skills/state-management/TROUBLESHOOTING.md +0 -18
- package/.agents/core/skills/state-management/VALIDATION.json +0 -11
- package/.agents/core/skills/state-management/skill.yaml +0 -28
- package/.agents/core/skills/subagent-orchestrator/SKILL.md +0 -117
- package/.agents/core/skills/subagent-orchestrator/VALIDATION.json +0 -12
- package/.agents/core/skills/subagent-orchestrator/skill.yaml +0 -12
- package/.agents/core/skills/system-design/EXAMPLES.md +0 -75
- package/.agents/core/skills/system-design/SKILL.md +0 -419
- package/.agents/core/skills/system-design/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/system-design/VALIDATION.json +0 -12
- package/.agents/core/skills/system-design/skill.yaml +0 -20
- package/.agents/core/skills/system-design/system-design.md +0 -112
- package/.agents/core/skills/testing/EXAMPLES.md +0 -71
- package/.agents/core/skills/testing/SKILL.md +0 -70
- package/.agents/core/skills/testing/TROUBLESHOOTING.md +0 -18
- package/.agents/core/skills/testing/VALIDATION.json +0 -11
- package/.agents/core/skills/testing/skill.yaml +0 -32
- package/.agents/core/skills/typescript/EXAMPLES.md +0 -64
- package/.agents/core/skills/typescript/SKILL.md +0 -112
- package/.agents/core/skills/typescript/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/typescript/VALIDATION.json +0 -12
- package/.agents/core/skills/typescript/skill.yaml +0 -17
- package/.agents/core/skills/typescript/typescript.md +0 -71
- package/.agents/core/skills/ui-design/EXAMPLES.md +0 -21
- package/.agents/core/skills/ui-design/SKILL.md +0 -124
- package/.agents/core/skills/ui-design/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/ui-design/VALIDATION.json +0 -12
- package/.agents/core/skills/ui-design/skill.yaml +0 -17
- package/.agents/core/skills/ui-design/ui.md +0 -88
- package/.agents/core/skills/ui-ux-pro/EXAMPLES.md +0 -62
- package/.agents/core/skills/ui-ux-pro/SKILL.md +0 -375
- package/.agents/core/skills/ui-ux-pro/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/ui-ux-pro/VALIDATION.json +0 -12
- package/.agents/core/skills/ui-ux-pro/skill.yaml +0 -19
- package/.agents/core/skills/ux-design/EXAMPLES.md +0 -36
- package/.agents/core/skills/ux-design/SKILL.md +0 -116
- package/.agents/core/skills/ux-design/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/ux-design/VALIDATION.json +0 -12
- package/.agents/core/skills/ux-design/skill.yaml +0 -17
- package/.agents/core/skills/ux-design/ux.md +0 -80
- package/.agents/core/skills/vercel-optimize/SKILL.md +0 -83
- package/.agents/core/skills/vercel-optimize/VALIDATION.json +0 -12
- package/.agents/core/skills/vercel-optimize/scripts/collect-signals.mjs +0 -131
- package/.agents/core/skills/vercel-optimize/scripts/gate-investigations.mjs +0 -142
- package/.agents/core/skills/vercel-optimize/scripts/merge-signals.mjs +0 -143
- package/.agents/core/skills/vercel-optimize/scripts/scan-codebase.mjs +0 -174
- package/.agents/core/skills/vercel-optimize/skill.yaml +0 -18
- package/.agents/core/skills/web-accessibility/EXAMPLES.md +0 -39
- package/.agents/core/skills/web-accessibility/SKILL.md +0 -170
- package/.agents/core/skills/web-accessibility/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/web-accessibility/VALIDATION.json +0 -12
- package/.agents/core/skills/web-accessibility/accessibility.md +0 -63
- package/.agents/core/skills/web-accessibility/skill.yaml +0 -17
- package/.agents/generated/claude/skills/adapters/SKILL.md +0 -126
- package/.agents/generated/claude/skills/architecture-diagrams/SKILL.md +0 -101
- package/.agents/generated/claude/skills/brutalist-design/SKILL.md +0 -145
- package/.agents/generated/claude/skills/database/SKILL.md +0 -191
- package/.agents/generated/claude/skills/ddd/SKILL.md +0 -305
- package/.agents/generated/claude/skills/decisions/SKILL.md +0 -134
- package/.agents/generated/claude/skills/docker/SKILL.md +0 -135
- package/.agents/generated/claude/skills/fastapi/SKILL.md +0 -200
- package/.agents/generated/claude/skills/generators/SKILL.md +0 -133
- package/.agents/generated/claude/skills/graphify/SKILL.md +0 -198
- package/.agents/generated/claude/skills/impeccable-design/SKILL.md +0 -241
- package/.agents/generated/claude/skills/interview-me/SKILL.md +0 -90
- package/.agents/generated/claude/skills/microservices/SKILL.md +0 -218
- package/.agents/generated/claude/skills/minimalist-design/SKILL.md +0 -108
- package/.agents/generated/claude/skills/nestjs/SKILL.md +0 -195
- package/.agents/generated/claude/skills/nextjs/SKILL.md +0 -219
- package/.agents/generated/claude/skills/node/SKILL.md +0 -224
- package/.agents/generated/claude/skills/performance/SKILL.md +0 -121
- package/.agents/generated/claude/skills/react/SKILL.md +0 -227
- package/.agents/generated/claude/skills/react-best-practices/SKILL.md +0 -146
- package/.agents/generated/claude/skills/redesign-audit/SKILL.md +0 -112
- package/.agents/generated/claude/skills/soft-design/SKILL.md +0 -103
- package/.agents/generated/claude/skills/state-management/SKILL.md +0 -120
- package/.agents/generated/claude/skills/subagent-orchestrator/SKILL.md +0 -110
- package/.agents/generated/claude/skills/system-design/SKILL.md +0 -507
- package/.agents/generated/claude/skills/testing/SKILL.md +0 -157
- package/.agents/generated/claude/skills/typescript/SKILL.md +0 -192
- package/.agents/generated/claude/skills/ui-design/SKILL.md +0 -161
- package/.agents/generated/claude/skills/ui-ux-pro/SKILL.md +0 -451
- package/.agents/generated/claude/skills/ux-design/SKILL.md +0 -168
- package/.agents/generated/claude/skills/vercel-optimize/SKILL.md +0 -76
- package/.agents/generated/claude/skills/web-accessibility/SKILL.md +0 -225
- package/.agents/generated/gemini/skills/adapters/SKILL.md +0 -135
- package/.agents/generated/gemini/skills/architecture-diagrams/SKILL.md +0 -107
- package/.agents/generated/gemini/skills/brutalist-design/SKILL.md +0 -151
- package/.agents/generated/gemini/skills/database/SKILL.md +0 -200
- package/.agents/generated/gemini/skills/ddd/SKILL.md +0 -314
- package/.agents/generated/gemini/skills/decisions/SKILL.md +0 -143
- package/.agents/generated/gemini/skills/docker/SKILL.md +0 -144
- package/.agents/generated/gemini/skills/fastapi/SKILL.md +0 -209
- package/.agents/generated/gemini/skills/generators/SKILL.md +0 -142
- package/.agents/generated/gemini/skills/graphify/SKILL.md +0 -205
- package/.agents/generated/gemini/skills/impeccable-design/SKILL.md +0 -250
- package/.agents/generated/gemini/skills/interview-me/SKILL.md +0 -96
- package/.agents/generated/gemini/skills/microservices/SKILL.md +0 -227
- package/.agents/generated/gemini/skills/minimalist-design/SKILL.md +0 -114
- package/.agents/generated/gemini/skills/nestjs/SKILL.md +0 -204
- package/.agents/generated/gemini/skills/nextjs/SKILL.md +0 -298
- package/.agents/generated/gemini/skills/node/SKILL.md +0 -323
- package/.agents/generated/gemini/skills/performance/SKILL.md +0 -185
- package/.agents/generated/gemini/skills/react/SKILL.md +0 -332
- package/.agents/generated/gemini/skills/react-best-practices/SKILL.md +0 -152
- package/.agents/generated/gemini/skills/redesign-audit/SKILL.md +0 -118
- package/.agents/generated/gemini/skills/soft-design/SKILL.md +0 -109
- package/.agents/generated/gemini/skills/state-management/SKILL.md +0 -129
- package/.agents/generated/gemini/skills/subagent-orchestrator/SKILL.md +0 -116
- package/.agents/generated/gemini/skills/system-design/SKILL.md +0 -631
- package/.agents/generated/gemini/skills/testing/SKILL.md +0 -166
- package/.agents/generated/gemini/skills/typescript/SKILL.md +0 -275
- package/.agents/generated/gemini/skills/ui-design/SKILL.md +0 -170
- package/.agents/generated/gemini/skills/ui-ux-pro/SKILL.md +0 -460
- package/.agents/generated/gemini/skills/ux-design/SKILL.md +0 -177
- package/.agents/generated/gemini/skills/vercel-optimize/SKILL.md +0 -82
- package/.agents/generated/gemini/skills/web-accessibility/SKILL.md +0 -300
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
# Node.js — Best Practices
|
|
2
|
-
|
|
3
|
-
## Architecture
|
|
4
|
-
|
|
5
|
-
- **Layered architecture**: Routes → Controllers → Services → Repositories
|
|
6
|
-
- **Dependency injection** — don't import dependencies directly in services
|
|
7
|
-
- **Config from environment** — never hardcode secrets, use env variables
|
|
8
|
-
- **Graceful shutdown** — handle SIGTERM, close connections, drain requests
|
|
9
|
-
|
|
10
|
-
## Error Handling
|
|
11
|
-
|
|
12
|
-
- **Never swallow errors** — always handle or re-throw
|
|
13
|
-
- **Custom error classes** — extend Error with HTTP status codes
|
|
14
|
-
- **Global error handler** — catch unhandled rejections and uncaught exceptions
|
|
15
|
-
- **Structured logging** — JSON logs with request ID, timestamp, level
|
|
16
|
-
|
|
17
|
-
```typescript
|
|
18
|
-
class AppError extends Error {
|
|
19
|
-
constructor(
|
|
20
|
-
public message: string,
|
|
21
|
-
public statusCode: number = 500,
|
|
22
|
-
public code: string = 'INTERNAL_ERROR'
|
|
23
|
-
) {
|
|
24
|
-
super(message);
|
|
25
|
-
this.name = 'AppError';
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## API Design
|
|
31
|
-
|
|
32
|
-
- **RESTful conventions** — GET (read), POST (create), PUT (full update), PATCH (partial), DELETE
|
|
33
|
-
- **Consistent response format** — `{ data, error, pagination }`
|
|
34
|
-
- **Validation at the edge** — validate request body/params with Zod or Joi
|
|
35
|
-
- **Rate limiting** — protect against abuse
|
|
36
|
-
- **CORS** — configure explicitly, never use `*` in production
|
|
37
|
-
|
|
38
|
-
## Security
|
|
39
|
-
|
|
40
|
-
- **Helmet.js** — security headers
|
|
41
|
-
- **Input validation** — never trust client input
|
|
42
|
-
- **SQL injection** — always use parameterized queries
|
|
43
|
-
- **XSS** — sanitize output, use Content-Security-Policy
|
|
44
|
-
- **Authentication** — JWT with short expiry + refresh tokens
|
|
45
|
-
- **Secrets** — environment variables, never in code
|
|
46
|
-
|
|
47
|
-
## Database
|
|
48
|
-
|
|
49
|
-
- **Connection pooling** — don't create connections per request
|
|
50
|
-
- **Migrations** — version-controlled schema changes
|
|
51
|
-
- **Transactions** — for multi-step operations
|
|
52
|
-
- **Indexes** — add indexes for frequently queried columns
|
|
53
|
-
|
|
54
|
-
## Performance
|
|
55
|
-
|
|
56
|
-
- **Async/await** — never block the event loop
|
|
57
|
-
- **Streaming** — for large files and data sets
|
|
58
|
-
- **Caching** — Redis for frequently accessed data
|
|
59
|
-
- **Clustering** — use PM2 or cluster module for multi-core
|
|
60
|
-
|
|
61
|
-
## Testing
|
|
62
|
-
|
|
63
|
-
- **Unit tests** — services and utilities
|
|
64
|
-
- **Integration tests** — API endpoints with test database
|
|
65
|
-
- **Test isolation** — each test should be independent
|
|
66
|
-
- **Fixtures** — use factories, not shared state
|
|
67
|
-
|
|
68
|
-
## File Structure
|
|
69
|
-
|
|
70
|
-
```
|
|
71
|
-
src/
|
|
72
|
-
├── config/ # Configuration
|
|
73
|
-
├── modules/ # Feature modules
|
|
74
|
-
│ └── users/
|
|
75
|
-
│ ├── users.controller.ts
|
|
76
|
-
│ ├── users.service.ts
|
|
77
|
-
│ ├── users.repository.ts
|
|
78
|
-
│ ├── users.routes.ts
|
|
79
|
-
│ ├── users.types.ts
|
|
80
|
-
│ └── users.test.ts
|
|
81
|
-
├── shared/ # Shared utilities
|
|
82
|
-
│ ├── middleware/
|
|
83
|
-
│ ├── errors/
|
|
84
|
-
│ └── utils/
|
|
85
|
-
├── types/ # Global types
|
|
86
|
-
└── app.ts # App entry point
|
|
87
|
-
```
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
id: node
|
|
2
|
-
name: Node.js
|
|
3
|
-
category: backend
|
|
4
|
-
type: instruction-only
|
|
5
|
-
tags: [backend, javascript, runtime, server, express, fastify]
|
|
6
|
-
requires: [typescript]
|
|
7
|
-
optional: [postgres, redis, docker]
|
|
8
|
-
conflicts: []
|
|
9
|
-
weight: 7
|
|
10
|
-
documents:
|
|
11
|
-
- node.md
|
|
12
|
-
resources:
|
|
13
|
-
- EXAMPLES.md
|
|
14
|
-
- SKILL.md
|
|
15
|
-
- TROUBLESHOOTING.md
|
|
16
|
-
- VALIDATION.json
|
|
17
|
-
- node.md
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# performance Examples — Anti-patterns vs ContextOS Standard
|
|
2
|
-
|
|
3
|
-
## Example 1: Dynamic Imports for Heavy Libraries
|
|
4
|
-
|
|
5
|
-
### Anti-pattern: Static Import of Heavy Visualizers in Initial Bundle
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
// BAD: Adds 800KB (Monaco editor or Three.js) to the critical first-paint bundle!
|
|
9
|
-
import { CodeEditor } from '@/components/CodeEditor';
|
|
10
|
-
|
|
11
|
-
export default function Page() {
|
|
12
|
-
return <div><CodeEditor /></div>;
|
|
13
|
-
}
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
### Best practice: ContextOS Standard (Lazy Load on Demand)
|
|
17
|
-
|
|
18
|
-
```typescript
|
|
19
|
-
// GOOD: Dynamic import splits chunk, only downloads when component renders
|
|
20
|
-
import dynamic from 'next/dynamic';
|
|
21
|
-
|
|
22
|
-
const CodeEditor = dynamic(
|
|
23
|
-
() => import('@/components/CodeEditor'),
|
|
24
|
-
{ loading: () => <EditorSkeleton />, ssr: false }
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
export default function Page() {
|
|
28
|
-
return <div><CodeEditor /></div>;
|
|
29
|
-
}
|
|
30
|
-
```
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Web Performance
|
|
3
|
-
description: >
|
|
4
|
-
ContextOS skill for Web Performance, Core Web Vitals, waterfall elimination, bundle size optimization, and caching strategies.
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Web Performance & Core Web Vitals
|
|
8
|
-
|
|
9
|
-
## Overview
|
|
10
|
-
|
|
11
|
-
Enforces high-efficiency frontend and full-stack performance standards to achieve exceptional Core Web Vitals: Largest Contentful Paint (LCP < 2.5s), Interaction to Next Paint (INP < 200ms), and Cumulative Layout Shift (CLS < 0.1).
|
|
12
|
-
|
|
13
|
-
## When to Use
|
|
14
|
-
|
|
15
|
-
Activate whenever analyzing, profiling, writing, or optimizing page loading speeds, network waterfalls, script bundling, animation frame rates, or data caching.
|
|
16
|
-
|
|
17
|
-
## Negative Constraints (What NOT to Do)
|
|
18
|
-
|
|
19
|
-
1. **NEVER introduce async waterfalls**: Do not chain sequential `await` calls when requests can be executed concurrently via `Promise.all()`.
|
|
20
|
-
2. **NEVER import large full libraries when only a utility is needed**: Never `import _ from 'lodash'`; use `import debounce from 'lodash/debounce'` or native alternatives.
|
|
21
|
-
3. **NEVER render images or videos without explicit aspect ratios**: Always provide `width` and `height` or `aspect-ratio` to avoid Cumulative Layout Shift (CLS).
|
|
22
|
-
4. **NEVER trigger synchronous layout thrashing**: Do not alternate between reading layout properties (`offsetHeight`, `getBoundingClientRect`) and writing styles in loops.
|
|
23
|
-
5. **NEVER animate non-composited properties**: Animate only GPU-composited CSS properties (`transform`, `opacity`). Never animate `width`, `height`, `top`, `left`, or `margin`.
|
|
24
|
-
|
|
25
|
-
## Rules & Patterns
|
|
26
|
-
|
|
27
|
-
### 1. Vercel Optimization Hierarchy by Impact
|
|
28
|
-
|
|
29
|
-
| Priority | Category | Key Optimization Target | Expected Impact |
|
|
30
|
-
|:---|:---|:---|:---|
|
|
31
|
-
| **1. CRITICAL** | **Eliminating Waterfalls** | Parallel data fetching (`Promise.all`), Suspense streaming | **30–60% faster LCP** |
|
|
32
|
-
| **2. CRITICAL** | **Bundle Size Optimization** | Direct submodule imports, `next/dynamic`, deferring 3rd party scripts | **40–70% smaller initial JS** |
|
|
33
|
-
| **3. HIGH** | **Server-Side & RSC Caching** | `React.cache()` request deduplication, edge SSR caching | **Lower TTFB & DB load** |
|
|
34
|
-
| **4. MEDIUM-HIGH** | **Client Query Optimization** | SWR / TanStack Query stale-while-revalidate, deduplication | **Zero redundant network calls** |
|
|
35
|
-
| **5. MEDIUM** | **Render & DOM Optimization** | Virtualization for large lists, state colocation, `:focus-visible` | **Smooth 60 FPS / INP < 100ms** |
|
|
36
|
-
|
|
37
|
-
### 2. Eliminating Network Waterfalls
|
|
38
|
-
|
|
39
|
-
```ts
|
|
40
|
-
// [GOOD] Parallel execution
|
|
41
|
-
const [user, notifications] = await Promise.all([
|
|
42
|
-
fetchUser(),
|
|
43
|
-
fetchNotifications(),
|
|
44
|
-
]);
|
|
45
|
-
const posts = await fetchPosts(user.id);
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### 3. Layout Shift & Visual Stability (CLS < 0.1)
|
|
49
|
-
|
|
50
|
-
- **Images & Video**: Always supply `width`, `height`, and `sizes` or CSS `aspect-ratio: 16 / 9`.
|
|
51
|
-
- **Dynamic Content**: Reserve layout space for dynamically loaded widgets with min-height placeholders or skeletons.
|
|
52
|
-
- **Tabular Numbers**: Use `font-feature-settings: "tnum"` / `font-variant-numeric: tabular-nums` for counters, clocks, and tables to prevent number width jitter.
|
|
53
|
-
|
|
54
|
-
## Code Examples
|
|
55
|
-
|
|
56
|
-
See `EXAMPLES.md` for detailed performance patterns and benchmark snippets.
|
|
57
|
-
|
|
58
|
-
## Validation Checklist
|
|
59
|
-
|
|
60
|
-
- [ ] LCP target is < 2.5s with preloaded critical fonts and LCP image `priority`.
|
|
61
|
-
- [ ] No sequential `await` waterfalls in API routes or Server Components.
|
|
62
|
-
- [ ] All animated elements use only `transform` and `opacity`.
|
|
63
|
-
- [ ] `prefers-reduced-motion` media queries are respected.
|
|
64
|
-
- [ ] Large tables / lists (> 100 items) utilize virtualization.
|
|
65
|
-
|
|
66
|
-
## Common Mistakes
|
|
67
|
-
|
|
68
|
-
- Chaining independent async requests instead of using `Promise.all`.
|
|
69
|
-
- Animating layout-triggering properties (`height`, `width`, `top`) causing jank.
|
|
70
|
-
- Missing image dimensions causing layout shift when images finish loading.
|
|
71
|
-
|
|
72
|
-
## Integration Notes
|
|
73
|
-
|
|
74
|
-
- Pairs with `nextjs` and `react` for App Router caching and component lifecycle tuning.
|
|
75
|
-
- Pairs with `ui-ux-pro` for smooth animations and responsive design tokens.
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# performance Troubleshooting & Common Mistakes
|
|
2
|
-
|
|
3
|
-
## 1. Cumulative Layout Shift (CLS) from Images & Fonts
|
|
4
|
-
|
|
5
|
-
- **Symptom**: Page content jumps around as images and custom fonts load.
|
|
6
|
-
- **Root Cause**: Missing width and height attributes on image tags and FOUT (Flash of Unstyled Text).
|
|
7
|
-
- **Fix**: Always specify aspect-ratio or width/height on images, and use next/font to preload web fonts with fallback sizing.
|
|
8
|
-
|
|
9
|
-
## 2. High Interaction to Next Paint (INP)
|
|
10
|
-
|
|
11
|
-
- **Symptom**: User clicks a button and the UI freezes for 200ms+ before responding.
|
|
12
|
-
- **Root Cause**: Long task blocking the main thread during event dispatch.
|
|
13
|
-
- **Fix**: Defer non-critical state updates using startTransition() or split heavy computation with Web Workers.
|
|
14
|
-
|
|
15
|
-
## 3. Unoptimized SVG / Icon Overload
|
|
16
|
-
|
|
17
|
-
- **Symptom**: Huge DOM node count and slow initial render times.
|
|
18
|
-
- **Root Cause**: Rendering 500 inline SVG icons with complex paths.
|
|
19
|
-
- **Fix**: Use SVG sprite sheets, dynamic icon loaders, or lightweight canvas rendering for dense data visualizations.
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# Web Performance — Best Practices
|
|
2
|
-
|
|
3
|
-
## Core Web Vitals
|
|
4
|
-
|
|
5
|
-
| Metric | Target | What it measures |
|
|
6
|
-
| --- | --- | --- |
|
|
7
|
-
| LCP (Largest Contentful Paint) | < 2.5s | Loading performance |
|
|
8
|
-
| INP (Interaction to Next Paint) | < 200ms | Responsiveness |
|
|
9
|
-
| CLS (Cumulative Layout Shift) | < 0.1 | Visual stability |
|
|
10
|
-
|
|
11
|
-
## Loading Performance
|
|
12
|
-
|
|
13
|
-
- **Code splitting** — split by route, lazy load non-critical components
|
|
14
|
-
- **Tree shaking** — use ES modules, avoid side-effect imports
|
|
15
|
-
- **Image optimization** — WebP/AVIF, responsive srcset, lazy loading
|
|
16
|
-
- **Font loading** — `font-display: swap`, preload critical fonts
|
|
17
|
-
- **Critical CSS** — inline above-the-fold styles
|
|
18
|
-
- **Preconnect** — `<link rel="preconnect">` for third-party origins
|
|
19
|
-
|
|
20
|
-
## Runtime Performance
|
|
21
|
-
|
|
22
|
-
- **Avoid layout thrashing** — batch DOM reads and writes
|
|
23
|
-
- **Debounce/throttle** — expensive event handlers (scroll, resize, input)
|
|
24
|
-
- **Web Workers** — offload heavy computation
|
|
25
|
-
- **Virtualize long lists** — render only visible items
|
|
26
|
-
- **Avoid synchronous operations** — use async/await, requestIdleCallback
|
|
27
|
-
|
|
28
|
-
## Bundle Optimization
|
|
29
|
-
|
|
30
|
-
- **Analyze bundle** — use webpack-bundle-analyzer or similar
|
|
31
|
-
- **Dynamic imports** — `import()` for heavy libraries
|
|
32
|
-
- **Avoid barrel exports** — they prevent tree shaking
|
|
33
|
-
- **Vendor splitting** — separate vendor chunks for caching
|
|
34
|
-
- **Compression** — Brotli > gzip
|
|
35
|
-
|
|
36
|
-
## Caching Strategy
|
|
37
|
-
|
|
38
|
-
| Asset | Cache | Strategy |
|
|
39
|
-
| --- | --- | --- |
|
|
40
|
-
| HTML | Short (5min) | Revalidate |
|
|
41
|
-
| JS/CSS (hashed) | Long (1 year) | Immutable |
|
|
42
|
-
| Images | Long (1 year) | Immutable |
|
|
43
|
-
| API responses | Depends | stale-while-revalidate |
|
|
44
|
-
| Fonts | Long (1 year) | Immutable |
|
|
45
|
-
|
|
46
|
-
## Anti-Patterns
|
|
47
|
-
|
|
48
|
-
- [FAIL] Importing entire libraries (`import _ from 'lodash'`)
|
|
49
|
-
- [FAIL] Unoptimized images (PNG > 500KB)
|
|
50
|
-
- [FAIL] Blocking scripts in `<head>` without `defer`
|
|
51
|
-
- [FAIL] Layout shifts from dynamic content (no dimensions on images)
|
|
52
|
-
- [FAIL] Premature optimization — measure first, optimize second
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
id: performance
|
|
2
|
-
name: Web Performance
|
|
3
|
-
category: frontend
|
|
4
|
-
type: instruction-only
|
|
5
|
-
tags: [frontend, performance, core-web-vitals, optimization]
|
|
6
|
-
requires: []
|
|
7
|
-
optional: [react, nextjs]
|
|
8
|
-
conflicts: []
|
|
9
|
-
weight: 6
|
|
10
|
-
documents:
|
|
11
|
-
- performance.md
|
|
12
|
-
resources:
|
|
13
|
-
- EXAMPLES.md
|
|
14
|
-
- SKILL.md
|
|
15
|
-
- TROUBLESHOOTING.md
|
|
16
|
-
- VALIDATION.json
|
|
17
|
-
- performance.md
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
# React Examples — Anti-patterns vs ContextOS Standard
|
|
2
|
-
|
|
3
|
-
## Example 1: Derived State vs. useEffect
|
|
4
|
-
|
|
5
|
-
### Anti-pattern: Anti-pattern (Redundant state + extra render with useEffect)
|
|
6
|
-
|
|
7
|
-
```tsx
|
|
8
|
-
// BAD: causes an unnecessary extra render cycle and potential state desync
|
|
9
|
-
function OrderSummary({ items }: { items: CartItem[] }) {
|
|
10
|
-
const [total, setTotal] = useState(0);
|
|
11
|
-
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
const calculated = items.reduce((sum, item) => sum + item.price * item.quantity, 0);
|
|
14
|
-
setTotal(calculated);
|
|
15
|
-
}, [items]);
|
|
16
|
-
|
|
17
|
-
return <div>Total: ${total}</div>;
|
|
18
|
-
}
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
### Best practice: ContextOS Standard (Inline derived calculation / useMemo)
|
|
22
|
-
|
|
23
|
-
```tsx
|
|
24
|
-
// GOOD: calculated instantly during render with zero extra render pass
|
|
25
|
-
function OrderSummary({ items }: { items: CartItem[] }) {
|
|
26
|
-
const total = useMemo(
|
|
27
|
-
() => items.reduce((sum, item) => sum + item.price * item.quantity, 0),
|
|
28
|
-
[items]
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
return <div>Total: ${total.toFixed(2)}</div>;
|
|
32
|
-
}
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
## Example 2: Custom Hook Encapsulation
|
|
38
|
-
|
|
39
|
-
### Anti-pattern: Anti-pattern (Scattered listener logic inside component)
|
|
40
|
-
|
|
41
|
-
```tsx
|
|
42
|
-
// BAD: window listener logic cluttering UI component
|
|
43
|
-
function NavHeader() {
|
|
44
|
-
const [isScrolled, setIsScrolled] = useState(false);
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
const handleScroll = () => setIsScrolled(window.scrollY > 50);
|
|
47
|
-
window.addEventListener('scroll', handleScroll);
|
|
48
|
-
return () => window.removeEventListener('scroll', handleScroll);
|
|
49
|
-
}, []);
|
|
50
|
-
return <header className={isScrolled ? 'scrolled' : ''}>Header</header>;
|
|
51
|
-
}
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### Best practice: ContextOS Standard (Reusable Custom Hook)
|
|
55
|
-
|
|
56
|
-
```tsx
|
|
57
|
-
// GOOD: extracted into a reusable, testable custom hook
|
|
58
|
-
export function useScrollThreshold(threshold = 50): boolean {
|
|
59
|
-
const [isPassed, setIsPassed] = useState(() => typeof window !== 'undefined' && window.scrollY > threshold);
|
|
60
|
-
|
|
61
|
-
useEffect(() => {
|
|
62
|
-
let ticking = false;
|
|
63
|
-
const handleScroll = () => {
|
|
64
|
-
if (!ticking) {
|
|
65
|
-
window.requestAnimationFrame(() => {
|
|
66
|
-
setIsPassed(window.scrollY > threshold);
|
|
67
|
-
ticking = false;
|
|
68
|
-
});
|
|
69
|
-
ticking = true;
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
window.addEventListener('scroll', handleScroll, { passive: true });
|
|
74
|
-
return () => window.removeEventListener('scroll', handleScroll);
|
|
75
|
-
}, [threshold]);
|
|
76
|
-
|
|
77
|
-
return isPassed;
|
|
78
|
-
}
|
|
79
|
-
```
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: React
|
|
3
|
-
description: >
|
|
4
|
-
ContextOS skill for modern React (v18/v19), component architecture, state colocation, render optimization, and Vercel performance rules.
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# React Engineering & Performance Best Practices
|
|
8
|
-
|
|
9
|
-
## Overview
|
|
10
|
-
|
|
11
|
-
Enforces declarative, component-driven UI architecture with optimal re-render cycles, state colocation, responsive optimistic updates, and robust accessibility standards.
|
|
12
|
-
|
|
13
|
-
## When to Use
|
|
14
|
-
|
|
15
|
-
Activate whenever creating, refactoring, or optimizing React functional components, custom hooks, context providers, or UI interaction states.
|
|
16
|
-
|
|
17
|
-
## Negative Constraints (What NOT to Do)
|
|
18
|
-
|
|
19
|
-
1. **NEVER use `useEffect` to synchronize or compute derived state**: Calculate derived state inline during render. Use `useMemo` only for computationally intensive derivations.
|
|
20
|
-
2. **NEVER use array indices as `key` props on dynamic or reorderable lists**: Always use stable, unique entity identifiers (`item.id`).
|
|
21
|
-
3. **NEVER mutate React state directly**: Always return new immutable references (`[...prev, newItem]` or `{ ...prev, key: value }`).
|
|
22
|
-
4. **NEVER declare subcomponents inside the render body of parent components**: Declare components at module scope or in dedicated files to prevent DOM node remounting and lost focus state.
|
|
23
|
-
5. **NEVER create memory leaks in `useEffect`**: Always provide clean-up functions for event listeners, `AbortController`, timers, and websocket subscriptions.
|
|
24
|
-
6. **NEVER lift state higher than necessary**: Colocate state to the nearest common ancestor or leaf component to prevent wasteful re-renders of unrelated subtrees.
|
|
25
|
-
|
|
26
|
-
## Rules & Patterns
|
|
27
|
-
|
|
28
|
-
### 1. State Colocation & Re-render Optimization
|
|
29
|
-
|
|
30
|
-
- **State Colocation**: Keep state as close as possible to the components that consume it.
|
|
31
|
-
- **Composition to Prevent Re-renders**: Pass expensive static subtrees as `children` to wrapper components holding state so the children do not re-render when the wrapper updates.
|
|
32
|
-
|
|
33
|
-
```tsx
|
|
34
|
-
export function ExpandableCard({ title, children }: { title: string; children: React.ReactNode }) {
|
|
35
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<div className="rounded-xl border p-4">
|
|
39
|
-
<button
|
|
40
|
-
type="button"
|
|
41
|
-
onClick={() => setIsOpen(v => !v)}
|
|
42
|
-
className="flex w-full justify-between font-semibold"
|
|
43
|
-
aria-expanded={isOpen}
|
|
44
|
-
>
|
|
45
|
-
<span>{title}</span>
|
|
46
|
-
<span>{isOpen ? '−' : '+'}</span>
|
|
47
|
-
</button>
|
|
48
|
-
{isOpen && <div className="mt-3 pt-3 border-t">{children}</div>}
|
|
49
|
-
</div>
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### 2. Optimistic UI Updates & Concurrent Actions (`useOptimistic`, `useTransition`)
|
|
55
|
-
|
|
56
|
-
- Provide instantaneous visual feedback for user actions without waiting for server network roundtrips.
|
|
57
|
-
|
|
58
|
-
```tsx
|
|
59
|
-
import { useOptimistic, useTransition } from 'react';
|
|
60
|
-
|
|
61
|
-
export function TodoList({ todos, onAdd }: { todos: Todo[]; onAdd: (text: string) => Promise<void> }) {
|
|
62
|
-
const [isPending, startTransition] = useTransition();
|
|
63
|
-
const [optimisticTodos, addOptimisticTodo] = useOptimistic(
|
|
64
|
-
todos,
|
|
65
|
-
(state, newText: string) => [...state, { id: 'temp-' + Date.now(), text: newText, isPending: true }]
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
const handleAction = async (formData: FormData) => {
|
|
69
|
-
const text = formData.get('todo') as string;
|
|
70
|
-
if (!text?.trim()) return;
|
|
71
|
-
|
|
72
|
-
startTransition(async () => {
|
|
73
|
-
addOptimisticTodo(text);
|
|
74
|
-
await onAdd(text);
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
return (
|
|
79
|
-
<form action={handleAction} className="space-y-4">
|
|
80
|
-
<input name="todo" placeholder="Add a new task..." className="border p-2 rounded" />
|
|
81
|
-
<button type="submit" disabled={isPending} className="bg-primary text-white px-4 py-2 rounded">
|
|
82
|
-
{isPending ? 'Saving...' : 'Add'}
|
|
83
|
-
</button>
|
|
84
|
-
<ul className="divide-y">
|
|
85
|
-
{optimisticTodos.map(todo => (
|
|
86
|
-
<li key={todo.id} className={todo.isPending ? 'opacity-50 italic' : ''}>
|
|
87
|
-
{todo.text}
|
|
88
|
-
</li>
|
|
89
|
-
))}
|
|
90
|
-
</ul>
|
|
91
|
-
</form>
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
### 3. Derived State vs. Effects Anti-Pattern
|
|
97
|
-
|
|
98
|
-
```tsx
|
|
99
|
-
// [GOOD] Computed directly during render (or memoized if expensive)
|
|
100
|
-
function SearchResults({ query, items }: { query: string; items: Item[] }) {
|
|
101
|
-
const filtered = useMemo(() => {
|
|
102
|
-
const q = query.trim().toLowerCase();
|
|
103
|
-
if (!q) return items;
|
|
104
|
-
return items.filter(i => i.title.toLowerCase().includes(q));
|
|
105
|
-
}, [query, items]);
|
|
106
|
-
|
|
107
|
-
return <List items={filtered} />;
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
## Code Examples
|
|
112
|
-
|
|
113
|
-
See `EXAMPLES.md` for detailed code examples and hook implementations.
|
|
114
|
-
|
|
115
|
-
## Validation Checklist
|
|
116
|
-
|
|
117
|
-
- [ ] Zero `useEffect` hooks used for derived calculations.
|
|
118
|
-
- [ ] Every list mapping has a unique, non-index entity ID key.
|
|
119
|
-
- [ ] Subcomponents declared in parent render functions are extracted to top-level scope.
|
|
120
|
-
- [ ] Effects with event listeners, timers, or abortable requests include clean-up returns.
|
|
121
|
-
- [ ] Reusable components are composed cleanly via `children` or render props.
|
|
122
|
-
|
|
123
|
-
## Common Mistakes
|
|
124
|
-
|
|
125
|
-
- Setting state inside `useEffect` based on prop changes rather than deriving values inline.
|
|
126
|
-
- Declaring nested components within component bodies.
|
|
127
|
-
- Using index keys causing input focus loss or animations breaking on list mutations.
|
|
128
|
-
|
|
129
|
-
## Integration Notes
|
|
130
|
-
|
|
131
|
-
- Pairs with `typescript` for type safety on props, generics, and ref forwarding.
|
|
132
|
-
- Pairs with `ui-ux-pro` and `web-accessibility` for UI tokens and ARIA standards.
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# react Troubleshooting & Common Mistakes
|
|
2
|
-
|
|
3
|
-
## 1. Infinite Render Loops in useEffect
|
|
4
|
-
|
|
5
|
-
- **Symptom**: Browser freezes, "Maximum update depth exceeded" error.
|
|
6
|
-
- **Root Cause**: Creating new object or array literals inside component body and passing them to useEffect dependency array.
|
|
7
|
-
- **Fix**: Colocate state, compute derived state during render without useEffect, or use primitive dependency values.
|
|
8
|
-
|
|
9
|
-
## 2. Stale Closures in Callbacks
|
|
10
|
-
|
|
11
|
-
- **Symptom**: Event handler or setTimeout accesses outdated state values.
|
|
12
|
-
- **Root Cause**: Callback closing over initial state without updated dependency.
|
|
13
|
-
- **Fix**: Use functional state updates (`setCount(c => c + 1)`) or `useRef` for mutable references.
|
|
14
|
-
|
|
15
|
-
## 3. Prop Drilling vs Context Performance
|
|
16
|
-
|
|
17
|
-
- **Symptom**: Changing a small state variable causes the entire component tree to re-render.
|
|
18
|
-
- **Root Cause**: Storing rapidly changing state in a single monolithic React Context.
|
|
19
|
-
- **Fix**: Split contexts by domain or migrate client UI state to Zustand with granular selectors.
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
# React — Best Practices
|
|
2
|
-
|
|
3
|
-
## Component Architecture
|
|
4
|
-
|
|
5
|
-
- **Prefer function components** with hooks over class components
|
|
6
|
-
- **One component per file** — name file same as component
|
|
7
|
-
- **Composition over inheritance** — use children and render props
|
|
8
|
-
- **Keep components small** — if > 150 lines, split it
|
|
9
|
-
|
|
10
|
-
## Hooks
|
|
11
|
-
|
|
12
|
-
- **useState** for local state, **useReducer** for complex state
|
|
13
|
-
- **useEffect** — always specify dependencies, clean up subscriptions
|
|
14
|
-
- **Custom hooks** — extract reusable logic into `use*` functions
|
|
15
|
-
- **useMemo/useCallback** — only when you have measured a performance problem
|
|
16
|
-
|
|
17
|
-
## State Management
|
|
18
|
-
|
|
19
|
-
- **Local state first** — don't reach for global state until you need it
|
|
20
|
-
- **Lift state up** — find the closest common ancestor
|
|
21
|
-
- **Context** — for cross-cutting concerns (theme, auth, locale)
|
|
22
|
-
- **External store** (Zustand, Jotai) — for truly global, frequently updated state
|
|
23
|
-
|
|
24
|
-
## Patterns
|
|
25
|
-
|
|
26
|
-
### Container/Presenter
|
|
27
|
-
|
|
28
|
-
```tsx
|
|
29
|
-
// Container — handles logic
|
|
30
|
-
function UserListContainer() {
|
|
31
|
-
const users = useUsers();
|
|
32
|
-
return <UserList users={users} />;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Presenter — handles display
|
|
36
|
-
function UserList({ users }: { users: User[] }) {
|
|
37
|
-
return <ul>{users.map(u => <UserItem key={u.id} user={u} />)}</ul>;
|
|
38
|
-
}
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### Error Boundaries
|
|
42
|
-
|
|
43
|
-
- Wrap major sections in Error Boundaries
|
|
44
|
-
- Provide meaningful fallback UI
|
|
45
|
-
- Log errors to monitoring service
|
|
46
|
-
|
|
47
|
-
### Loading States
|
|
48
|
-
|
|
49
|
-
- Always handle: `loading`, `error`, `empty`, `data` states
|
|
50
|
-
- Use Suspense where supported
|
|
51
|
-
- Show skeleton screens, not spinners
|
|
52
|
-
|
|
53
|
-
## Performance
|
|
54
|
-
|
|
55
|
-
- **React.memo** — only for expensive renders with stable props
|
|
56
|
-
- **Code splitting** — lazy load routes and heavy components
|
|
57
|
-
- **Virtualization** — for lists > 100 items
|
|
58
|
-
- **Image optimization** — use next/image or lazy loading
|
|
59
|
-
- **Avoid** — inline object/array creation in JSX props
|
|
60
|
-
|
|
61
|
-
## Anti-Patterns (Avoid)
|
|
62
|
-
|
|
63
|
-
- [FAIL] Props drilling more than 2 levels — use Context or state management
|
|
64
|
-
- [FAIL] useEffect for derived state — use useMemo instead
|
|
65
|
-
- [FAIL] Index as key — use stable unique IDs
|
|
66
|
-
- [FAIL] Mutating state directly — always create new references
|
|
67
|
-
- [FAIL] God components — split into smaller, focused components
|
|
68
|
-
- [FAIL] Business logic in components — extract to hooks or services
|
|
69
|
-
|
|
70
|
-
## Testing
|
|
71
|
-
|
|
72
|
-
- **React Testing Library** — test behavior, not implementation
|
|
73
|
-
- Test user interactions, not component internals
|
|
74
|
-
- Mock API calls, not React hooks
|
|
75
|
-
- Use `screen.getByRole` over `getByTestId`
|
|
76
|
-
|
|
77
|
-
## File Structure
|
|
78
|
-
|
|
79
|
-
```
|
|
80
|
-
components/
|
|
81
|
-
Button/
|
|
82
|
-
Button.tsx
|
|
83
|
-
Button.test.tsx
|
|
84
|
-
Button.module.css
|
|
85
|
-
index.ts
|
|
86
|
-
hooks/
|
|
87
|
-
useAuth.ts
|
|
88
|
-
useDebounce.ts
|
|
89
|
-
services/
|
|
90
|
-
api.ts
|
|
91
|
-
types/
|
|
92
|
-
user.ts
|
|
93
|
-
```
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
id: react
|
|
2
|
-
name: React
|
|
3
|
-
category: frontend
|
|
4
|
-
type: instruction-only
|
|
5
|
-
tags: [frontend, spa, jsx, components, hooks]
|
|
6
|
-
requires: [typescript]
|
|
7
|
-
optional: [tailwind, react-query, zustand, next-auth]
|
|
8
|
-
conflicts: [vue, angular, svelte]
|
|
9
|
-
weight: 8
|
|
10
|
-
documents:
|
|
11
|
-
- react.md
|
|
12
|
-
resources:
|
|
13
|
-
- EXAMPLES.md
|
|
14
|
-
- SKILL.md
|
|
15
|
-
- TROUBLESHOOTING.md
|
|
16
|
-
- VALIDATION.json
|
|
17
|
-
- react.md
|