contextos-agents 2.1.0 → 2.2.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.
Files changed (192) hide show
  1. package/.agents/adapters/aider/export.js +2 -2
  2. package/.agents/adapters/claude/export.js +53 -2
  3. package/.agents/adapters/drift-detector.js +6 -3
  4. package/.agents/adapters/pure-compiler.js +18 -6
  5. package/.agents/ctx.js +13 -8
  6. package/.agents/plugins.js +347 -26
  7. package/.agents/profiles.js +32 -11
  8. package/README.md +38 -3
  9. package/bin/commands/hook.js +50 -12
  10. package/bin/commands/scan.js +10 -3
  11. package/bin/index.js +165 -53
  12. package/bin/lib/git-snapshot.js +70 -43
  13. package/bin/lib/scan.js +108 -27
  14. package/bin/lib/ui.js +140 -0
  15. package/catalog/skills/adapters/EXAMPLES.md +19 -0
  16. package/catalog/skills/adapters/SKILL.md +101 -0
  17. package/catalog/skills/adapters/TROUBLESHOOTING.md +7 -0
  18. package/catalog/skills/adapters/VALIDATION.json +12 -0
  19. package/catalog/skills/adapters/skill.yaml +13 -0
  20. package/catalog/skills/api-design/EXAMPLES.md +91 -0
  21. package/catalog/skills/api-design/SKILL.md +63 -0
  22. package/catalog/skills/api-design/TROUBLESHOOTING.md +54 -0
  23. package/catalog/skills/api-design/VALIDATION.json +11 -0
  24. package/catalog/skills/api-design/skill.yaml +14 -0
  25. package/catalog/skills/architecture-diagrams/SKILL.md +108 -0
  26. package/catalog/skills/architecture-diagrams/VALIDATION.json +12 -0
  27. package/catalog/skills/architecture-diagrams/skill.yaml +9 -0
  28. package/catalog/skills/brutalist-design/EXAMPLES.md +59 -0
  29. package/catalog/skills/brutalist-design/SKILL.md +150 -0
  30. package/catalog/skills/brutalist-design/VALIDATION.json +12 -0
  31. package/catalog/skills/brutalist-design/skill.yaml +10 -0
  32. package/catalog/skills/ci-cd/EXAMPLES.md +79 -0
  33. package/catalog/skills/ci-cd/SKILL.md +69 -0
  34. package/catalog/skills/ci-cd/TROUBLESHOOTING.md +52 -0
  35. package/catalog/skills/ci-cd/VALIDATION.json +11 -0
  36. package/catalog/skills/ci-cd/skill.yaml +13 -0
  37. package/catalog/skills/database/EXAMPLES.md +74 -0
  38. package/catalog/skills/database/SKILL.md +101 -0
  39. package/catalog/skills/database/TROUBLESHOOTING.md +18 -0
  40. package/catalog/skills/database/VALIDATION.json +11 -0
  41. package/catalog/skills/database/skill.yaml +14 -0
  42. package/catalog/skills/ddd/EXAMPLES.md +42 -0
  43. package/catalog/skills/ddd/SKILL.md +247 -0
  44. package/catalog/skills/ddd/TROUBLESHOOTING.md +19 -0
  45. package/catalog/skills/ddd/VALIDATION.json +12 -0
  46. package/catalog/skills/ddd/skill.yaml +14 -0
  47. package/catalog/skills/decisions/EXAMPLES.md +35 -0
  48. package/catalog/skills/decisions/SKILL.md +90 -0
  49. package/catalog/skills/decisions/TROUBLESHOOTING.md +13 -0
  50. package/catalog/skills/decisions/VALIDATION.json +12 -0
  51. package/catalog/skills/decisions/skill.yaml +13 -0
  52. package/catalog/skills/docker/EXAMPLES.md +56 -0
  53. package/catalog/skills/docker/SKILL.md +169 -0
  54. package/catalog/skills/docker/TROUBLESHOOTING.md +18 -0
  55. package/catalog/skills/docker/VALIDATION.json +11 -0
  56. package/catalog/skills/docker/skill.yaml +13 -0
  57. package/catalog/skills/fastapi/EXAMPLES.md +36 -0
  58. package/catalog/skills/fastapi/SKILL.md +171 -0
  59. package/catalog/skills/fastapi/TROUBLESHOOTING.md +19 -0
  60. package/catalog/skills/fastapi/VALIDATION.json +12 -0
  61. package/catalog/skills/fastapi/skill.yaml +14 -0
  62. package/catalog/skills/generators/EXAMPLES.md +19 -0
  63. package/catalog/skills/generators/SKILL.md +110 -0
  64. package/catalog/skills/generators/TROUBLESHOOTING.md +7 -0
  65. package/catalog/skills/generators/VALIDATION.json +12 -0
  66. package/catalog/skills/generators/skill.yaml +22 -0
  67. package/catalog/skills/generators/templates/API.md +77 -0
  68. package/catalog/skills/generators/templates/ARCHITECTURE.md +70 -0
  69. package/catalog/skills/generators/templates/DATABASE.md +42 -0
  70. package/catalog/skills/generators/templates/DECISION.md +46 -0
  71. package/catalog/skills/generators/templates/PRD.md +67 -0
  72. package/catalog/skills/generators/templates/PROJECT_GRAPH.md +56 -0
  73. package/catalog/skills/generators/templates/ROADMAP.md +51 -0
  74. package/catalog/skills/generators/templates/TASKS.md +43 -0
  75. package/catalog/skills/generators/templates/UI.md +73 -0
  76. package/catalog/skills/graphify/EXAMPLES.md +73 -0
  77. package/catalog/skills/graphify/SKILL.md +130 -0
  78. package/catalog/skills/graphify/VALIDATION.json +12 -0
  79. package/catalog/skills/graphify/skill.yaml +13 -0
  80. package/catalog/skills/impeccable-design/EXAMPLES.md +26 -0
  81. package/catalog/skills/impeccable-design/SKILL.md +201 -0
  82. package/catalog/skills/impeccable-design/TROUBLESHOOTING.md +19 -0
  83. package/catalog/skills/impeccable-design/VALIDATION.json +12 -0
  84. package/catalog/skills/impeccable-design/skill.yaml +15 -0
  85. package/catalog/skills/interview-me/SKILL.md +97 -0
  86. package/catalog/skills/interview-me/VALIDATION.json +12 -0
  87. package/catalog/skills/interview-me/skill.yaml +9 -0
  88. package/catalog/skills/microservices/EXAMPLES.md +38 -0
  89. package/catalog/skills/microservices/SKILL.md +164 -0
  90. package/catalog/skills/microservices/TROUBLESHOOTING.md +19 -0
  91. package/catalog/skills/microservices/VALIDATION.json +12 -0
  92. package/catalog/skills/microservices/skill.yaml +14 -0
  93. package/catalog/skills/minimalist-design/EXAMPLES.md +58 -0
  94. package/catalog/skills/minimalist-design/SKILL.md +113 -0
  95. package/catalog/skills/minimalist-design/VALIDATION.json +12 -0
  96. package/catalog/skills/minimalist-design/skill.yaml +10 -0
  97. package/catalog/skills/nestjs/EXAMPLES.md +40 -0
  98. package/catalog/skills/nestjs/SKILL.md +139 -0
  99. package/catalog/skills/nestjs/TROUBLESHOOTING.md +19 -0
  100. package/catalog/skills/nestjs/VALIDATION.json +12 -0
  101. package/catalog/skills/nestjs/skill.yaml +14 -0
  102. package/catalog/skills/nextjs/EXAMPLES.md +40 -0
  103. package/catalog/skills/nextjs/SKILL.md +163 -0
  104. package/catalog/skills/nextjs/TROUBLESHOOTING.md +19 -0
  105. package/catalog/skills/nextjs/VALIDATION.json +12 -0
  106. package/catalog/skills/nextjs/skill.yaml +14 -0
  107. package/catalog/skills/node/EXAMPLES.md +80 -0
  108. package/catalog/skills/node/SKILL.md +128 -0
  109. package/catalog/skills/node/TROUBLESHOOTING.md +19 -0
  110. package/catalog/skills/node/VALIDATION.json +12 -0
  111. package/catalog/skills/node/skill.yaml +14 -0
  112. package/catalog/skills/performance/EXAMPLES.md +30 -0
  113. package/catalog/skills/performance/SKILL.md +75 -0
  114. package/catalog/skills/performance/TROUBLESHOOTING.md +19 -0
  115. package/catalog/skills/performance/VALIDATION.json +12 -0
  116. package/catalog/skills/performance/skill.yaml +14 -0
  117. package/catalog/skills/react/EXAMPLES.md +79 -0
  118. package/catalog/skills/react/SKILL.md +132 -0
  119. package/catalog/skills/react/TROUBLESHOOTING.md +19 -0
  120. package/catalog/skills/react/VALIDATION.json +12 -0
  121. package/catalog/skills/react/skill.yaml +14 -0
  122. package/catalog/skills/react-best-practices/SKILL.md +158 -0
  123. package/catalog/skills/react-best-practices/VALIDATION.json +12 -0
  124. package/catalog/skills/react-best-practices/skill.yaml +13 -0
  125. package/catalog/skills/redesign-audit/SKILL.md +117 -0
  126. package/catalog/skills/redesign-audit/VALIDATION.json +12 -0
  127. package/catalog/skills/redesign-audit/skill.yaml +9 -0
  128. package/catalog/skills/security-audit/EXAMPLES.md +79 -0
  129. package/catalog/skills/security-audit/SKILL.md +91 -0
  130. package/catalog/skills/security-audit/TROUBLESHOOTING.md +46 -0
  131. package/catalog/skills/security-audit/VALIDATION.json +11 -0
  132. package/catalog/skills/security-audit/skill.yaml +14 -0
  133. package/catalog/skills/soft-design/EXAMPLES.md +51 -0
  134. package/catalog/skills/soft-design/SKILL.md +108 -0
  135. package/catalog/skills/soft-design/VALIDATION.json +12 -0
  136. package/catalog/skills/soft-design/skill.yaml +10 -0
  137. package/catalog/skills/state-management/EXAMPLES.md +56 -0
  138. package/catalog/skills/state-management/SKILL.md +168 -0
  139. package/catalog/skills/state-management/TROUBLESHOOTING.md +18 -0
  140. package/catalog/skills/state-management/VALIDATION.json +11 -0
  141. package/catalog/skills/state-management/skill.yaml +14 -0
  142. package/catalog/skills/subagent-orchestrator/SKILL.md +117 -0
  143. package/catalog/skills/subagent-orchestrator/VALIDATION.json +12 -0
  144. package/catalog/skills/subagent-orchestrator/skill.yaml +9 -0
  145. package/catalog/skills/system-design/EXAMPLES.md +75 -0
  146. package/catalog/skills/system-design/SKILL.md +419 -0
  147. package/catalog/skills/system-design/TROUBLESHOOTING.md +19 -0
  148. package/catalog/skills/system-design/VALIDATION.json +12 -0
  149. package/catalog/skills/system-design/skill.yaml +14 -0
  150. package/catalog/skills/terraform/EXAMPLES.md +74 -0
  151. package/catalog/skills/terraform/SKILL.md +55 -0
  152. package/catalog/skills/terraform/TROUBLESHOOTING.md +53 -0
  153. package/catalog/skills/terraform/VALIDATION.json +11 -0
  154. package/catalog/skills/terraform/skill.yaml +14 -0
  155. package/catalog/skills/testing/EXAMPLES.md +122 -0
  156. package/catalog/skills/testing/SKILL.md +70 -0
  157. package/catalog/skills/testing/TROUBLESHOOTING.md +18 -0
  158. package/catalog/skills/testing/VALIDATION.json +11 -0
  159. package/catalog/skills/testing/skill.yaml +14 -0
  160. package/catalog/skills/typescript/EXAMPLES.md +64 -0
  161. package/catalog/skills/typescript/SKILL.md +112 -0
  162. package/catalog/skills/typescript/TROUBLESHOOTING.md +19 -0
  163. package/catalog/skills/typescript/VALIDATION.json +12 -0
  164. package/catalog/skills/typescript/skill.yaml +14 -0
  165. package/catalog/skills/ui-design/EXAMPLES.md +21 -0
  166. package/catalog/skills/ui-design/SKILL.md +124 -0
  167. package/catalog/skills/ui-design/TROUBLESHOOTING.md +19 -0
  168. package/catalog/skills/ui-design/VALIDATION.json +12 -0
  169. package/catalog/skills/ui-design/skill.yaml +16 -0
  170. package/catalog/skills/ui-ux-pro/EXAMPLES.md +62 -0
  171. package/catalog/skills/ui-ux-pro/SKILL.md +418 -0
  172. package/catalog/skills/ui-ux-pro/TROUBLESHOOTING.md +19 -0
  173. package/catalog/skills/ui-ux-pro/VALIDATION.json +12 -0
  174. package/catalog/skills/ui-ux-pro/skill.yaml +14 -0
  175. package/catalog/skills/ux-design/EXAMPLES.md +36 -0
  176. package/catalog/skills/ux-design/SKILL.md +116 -0
  177. package/catalog/skills/ux-design/TROUBLESHOOTING.md +19 -0
  178. package/catalog/skills/ux-design/VALIDATION.json +12 -0
  179. package/catalog/skills/ux-design/skill.yaml +16 -0
  180. package/catalog/skills/vercel-optimize/SKILL.md +83 -0
  181. package/catalog/skills/vercel-optimize/VALIDATION.json +12 -0
  182. package/catalog/skills/vercel-optimize/scripts/collect-signals.mjs +131 -0
  183. package/catalog/skills/vercel-optimize/scripts/gate-investigations.mjs +142 -0
  184. package/catalog/skills/vercel-optimize/scripts/merge-signals.mjs +143 -0
  185. package/catalog/skills/vercel-optimize/scripts/scan-codebase.mjs +174 -0
  186. package/catalog/skills/vercel-optimize/skill.yaml +15 -0
  187. package/catalog/skills/web-accessibility/EXAMPLES.md +39 -0
  188. package/catalog/skills/web-accessibility/SKILL.md +151 -0
  189. package/catalog/skills/web-accessibility/TROUBLESHOOTING.md +19 -0
  190. package/catalog/skills/web-accessibility/VALIDATION.json +12 -0
  191. package/catalog/skills/web-accessibility/skill.yaml +14 -0
  192. package/package.json +3 -2
@@ -0,0 +1,80 @@
1
+ # Node.js Examples - Anti-patterns vs ContextOS Standard
2
+
3
+ ## Example 1: Graceful Process Shutdown
4
+
5
+ ### Anti-pattern: Anti-pattern (Abruptly killing process and dropping in-flight requests)
6
+
7
+ ```javascript
8
+ // BAD: drops active database transactions and in-flight HTTP connections
9
+ process.on('SIGTERM', () => {
10
+ process.exit(0);
11
+ });
12
+ ```
13
+
14
+ ### Best practice: ContextOS Standard (Graceful connection draining)
15
+
16
+ ```typescript
17
+ // GOOD: drains active requests, closes database connections, and exits safely
18
+ import http from 'http';
19
+ import { prisma } from './db';
20
+ import { logger } from './logger';
21
+
22
+ export function setupGracefulShutdown(server: http.Server) {
23
+ const shutdown = async (signal: string) => {
24
+ logger.info(`Received ${signal}. Starting graceful shutdown...`);
25
+
26
+ server.close(async () => {
27
+ logger.info('HTTP server closed.');
28
+ try {
29
+ await prisma.$disconnect();
30
+ logger.info('Database pool closed.');
31
+ process.exit(0);
32
+ } catch (err) {
33
+ logger.error('Error during database disconnect:', err);
34
+ process.exit(1);
35
+ }
36
+ });
37
+
38
+ // Force shutdown after timeout if connections hang
39
+ setTimeout(() => {
40
+ logger.error('Forceful shutdown timeout reached.');
41
+ process.exit(1);
42
+ }, 10_000).unref();
43
+ };
44
+
45
+ process.on('SIGTERM', () => shutdown('SIGTERM'));
46
+ process.on('SIGINT', () => shutdown('SIGINT'));
47
+ }
48
+ ```
49
+
50
+ ---
51
+
52
+ ## Example 2: Stream-based File Processing
53
+
54
+ ### Anti-pattern: Anti-pattern (Loading entire 500MB file into buffer)
55
+
56
+ ```typescript
57
+ // BAD: easily causes Out Of Memory (OOM) crashes under concurrency
58
+ app.get('/download/:file', async (req, res) => {
59
+ const data = await fs.promises.readFile(`/uploads/${req.params.file}`);
60
+ res.send(data);
61
+ });
62
+ ```
63
+
64
+ ### Best practice: ContextOS Standard (Piping read stream with pipeline)
65
+
66
+ ```typescript
67
+ // GOOD: constant memory usage (O(1) RAM) regardless of file size
68
+ import fs from 'fs';
69
+ import { pipeline } from 'stream/promises';
70
+
71
+ app.get('/download/:file', async (req, res, next) => {
72
+ try {
73
+ const filePath = `/uploads/${req.params.file}`;
74
+ const readStream = fs.createReadStream(filePath);
75
+ await pipeline(readStream, res);
76
+ } catch (err) {
77
+ next(err);
78
+ }
79
+ });
80
+ ```
@@ -0,0 +1,128 @@
1
+ ---
2
+ name: Node.js
3
+ description: >
4
+ ContextOS skill for Node.js
5
+ ---
6
+
7
+ # Node.js
8
+
9
+ ## Overview
10
+
11
+ Production-grade Node.js runtime and server standard. Enforces async event loop non-blocking hygiene, graceful shutdown, structured JSON logging with correlation IDs, and unhandled rejection guards.
12
+
13
+ ## When to Use
14
+
15
+ Activate when developing Node.js HTTP servers, Express/Fastify APIs, background workers, CLI tools, or stream-based data pipelines.
16
+
17
+ ## Negative Constraints (What NOT to Do)
18
+
19
+ 1. **NEVER execute synchronous filesystem/crypto calls in request handlers (`fs.readFileSync`)**: Always use async promises (`fs.promises.*`) to avoid blocking the event loop.
20
+ 2. **NEVER leave uncaught promise rejections**: Every async route must use `express-async-errors` or wrap operations in try/catch calling `next(err)`.
21
+ 3. **NEVER buffer large files/payloads entirely in memory (`fs.readFile`)**: Always use Streams or Pipelines (`stream.pipeline`) for processing large files.
22
+ 4. **NEVER store in-memory session or user state on a single process instance**: Use Redis or an external state store to allow multi-instance scaling.
23
+ 5. **NEVER ignore `SIGTERM` / `SIGINT` shutdown signals**: Always implement graceful shutdown to close open DB pools and drain active HTTP connections.
24
+
25
+ ## Rules & Patterns
26
+
27
+ ## Architecture
28
+
29
+ - **Layered architecture**: Routes → Controllers → Services → Repositories
30
+ - **Dependency injection** - don't import dependencies directly in services
31
+ - **Config from environment** - never hardcode secrets, use env variables
32
+ - **Graceful shutdown** - handle SIGTERM, close connections, drain requests
33
+
34
+ ## Error Handling
35
+
36
+ - **Never swallow errors** - always handle or re-throw
37
+ - **Custom error classes** - extend Error with HTTP status codes
38
+ - **Global error handler** - catch unhandled rejections and uncaught exceptions
39
+ - **Structured logging** - JSON logs with request ID, timestamp, level
40
+
41
+ ```typescript
42
+ class AppError extends Error {
43
+ constructor(
44
+ public message: string,
45
+ public statusCode: number = 500,
46
+ public code: string = 'INTERNAL_ERROR'
47
+ ) {
48
+ super(message);
49
+ this.name = 'AppError';
50
+ }
51
+ }
52
+ ```
53
+
54
+ ## API Design
55
+
56
+ - **RESTful conventions** - GET (read), POST (create), PUT (full update), PATCH (partial), DELETE
57
+ - **Consistent response format** - `{ data, error, pagination }`
58
+ - **Validation at the edge** - validate request body/params with Zod or Joi
59
+ - **Rate limiting** - protect against abuse
60
+ - **CORS** - configure explicitly, never use `*` in production
61
+
62
+ ## Security
63
+
64
+ - **Helmet.js** - security headers
65
+ - **Input validation** - never trust client input
66
+ - **SQL injection** - always use parameterized queries
67
+ - **XSS** - sanitize output, use Content-Security-Policy
68
+ - **Authentication** - JWT with short expiry + refresh tokens
69
+ - **Secrets** - environment variables, never in code
70
+
71
+ ## Database
72
+
73
+ - **Connection pooling** - don't create connections per request
74
+ - **Migrations** - version-controlled schema changes
75
+ - **Transactions** - for multi-step operations
76
+ - **Indexes** - add indexes for frequently queried columns
77
+
78
+ ## Performance
79
+
80
+ - **Async/await** - never block the event loop
81
+ - **Streaming** - for large files and data sets
82
+ - **Caching** - Redis for frequently accessed data
83
+ - **Clustering** - use PM2 or cluster module for multi-core
84
+
85
+ ## Testing
86
+
87
+ - **Unit tests** - services and utilities
88
+ - **Integration tests** - API endpoints with test database
89
+ - **Test isolation** - each test should be independent
90
+ - **Fixtures** - use factories, not shared state
91
+
92
+ ## File Structure
93
+
94
+ ```
95
+ src/
96
+ ├── config/ # Configuration
97
+ ├── modules/ # Feature modules
98
+ │ └── users/
99
+ │ ├── users.controller.ts
100
+ │ ├── users.service.ts
101
+ │ ├── users.repository.ts
102
+ │ ├── users.routes.ts
103
+ │ ├── users.types.ts
104
+ │ └── users.test.ts
105
+ ├── shared/ # Shared utilities
106
+ │ ├── middleware/
107
+ │ ├── errors/
108
+ │ └── utils/
109
+ ├── types/ # Global types
110
+ └── app.ts # App entry point
111
+ ```
112
+
113
+
114
+ ## Code Examples
115
+
116
+ See `EXAMPLES.md` for detailed code examples.
117
+
118
+ ## Validation Checklist
119
+
120
+ What to verify during the review phase before completing the task.
121
+
122
+ ## Common Mistakes
123
+
124
+ Anti-patterns and things to explicitly avoid. See `TROUBLESHOOTING.md`.
125
+
126
+ ## Integration Notes
127
+
128
+ How this skill interacts with other skills.
@@ -0,0 +1,19 @@
1
+ # node Troubleshooting & Common Mistakes
2
+
3
+ ## 1. Unhandled Promise Rejections Crashing the Process
4
+
5
+ - **Symptom**: Node process crashes abruptly without clear stack trace in production.
6
+ - **Root Cause**: Missing `process.on('unhandledRejection')` handler in Node.js >= 15.
7
+ - **Fix**: Always register top-level unhandledRejection and uncaughtException logging before exiting cleanly.
8
+
9
+ ## 2. Event Loop Starvation
10
+
11
+ - **Symptom**: API endpoints stop responding or latency spikes to 10+ seconds.
12
+ - **Root Cause**: Heavy synchronous operations (`JSON.parse` on a 50MB file, sync bcrypt hashing, or regex catastrophic backtracking).
13
+ - **Fix**: Offload CPU-heavy tasks to Worker Threads or use async worker queues.
14
+
15
+ ## 3. Memory Leaks in Event Emitters
16
+
17
+ - **Symptom**: "MaxListenersExceededWarning: Possible EventEmitter memory leak detected".
18
+ - **Root Cause**: Adding listeners inside request handlers without removing them on close.
19
+ - **Fix**: Remove listeners in cleanup callbacks or use `AbortController` signals.
@@ -0,0 +1,12 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "rules_followed": {
6
+ "type": "boolean"
7
+ }
8
+ },
9
+ "required": [
10
+ "rules_followed"
11
+ ]
12
+ }
@@ -0,0 +1,14 @@
1
+ schemaVersion: 2
2
+ id: node
3
+ name: Node.js
4
+ category: backend
5
+ type: instruction-only
6
+ requires: [typescript]
7
+ optional: [postgres, redis, docker]
8
+ conflicts: []
9
+ weight: 7
10
+ resources:
11
+ - EXAMPLES.md
12
+ - SKILL.md
13
+ - TROUBLESHOOTING.md
14
+ - VALIDATION.json
@@ -0,0 +1,30 @@
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
+ ```
@@ -0,0 +1,75 @@
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.
@@ -0,0 +1,19 @@
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.
@@ -0,0 +1,12 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "rules_followed": {
6
+ "type": "boolean"
7
+ }
8
+ },
9
+ "required": [
10
+ "rules_followed"
11
+ ]
12
+ }
@@ -0,0 +1,14 @@
1
+ schemaVersion: 2
2
+ id: performance
3
+ name: Web Performance
4
+ category: frontend
5
+ type: instruction-only
6
+ requires: []
7
+ optional: [react, nextjs]
8
+ conflicts: []
9
+ weight: 6
10
+ resources:
11
+ - EXAMPLES.md
12
+ - SKILL.md
13
+ - TROUBLESHOOTING.md
14
+ - VALIDATION.json
@@ -0,0 +1,79 @@
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
+ ```
@@ -0,0 +1,132 @@
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.
@@ -0,0 +1,19 @@
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.
@@ -0,0 +1,12 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "rules_followed": {
6
+ "type": "boolean"
7
+ }
8
+ },
9
+ "required": [
10
+ "rules_followed"
11
+ ]
12
+ }
@@ -0,0 +1,14 @@
1
+ schemaVersion: 2
2
+ id: react
3
+ name: React
4
+ category: frontend
5
+ type: instruction-only
6
+ requires: [typescript]
7
+ optional: [tailwind, react-query, zustand, next-auth]
8
+ conflicts: [vue, angular, svelte]
9
+ weight: 8
10
+ resources:
11
+ - EXAMPLES.md
12
+ - SKILL.md
13
+ - TROUBLESHOOTING.md
14
+ - VALIDATION.json