contextos-agents 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/AGENTS.md +421 -0
- package/.agents/adapters/aider/export.js +137 -0
- package/.agents/adapters/claude/export.js +55 -0
- package/.agents/adapters/copilot/export.js +107 -0
- package/.agents/adapters/cursor/export.js +210 -0
- package/.agents/adapters/gemini/export.js +115 -0
- package/.agents/adapters/shared.js +119 -0
- package/.agents/adapters/zed/export.js +111 -0
- package/.agents/core/profiles/backend.yaml +47 -0
- package/.agents/core/profiles/enterprise.yaml +46 -0
- package/.agents/core/profiles/frontend.yaml +46 -0
- package/.agents/core/profiles/hackathon.yaml +45 -0
- package/.agents/core/profiles/mvp.yaml +43 -0
- package/.agents/core/profiles/startup.yaml +48 -0
- package/.agents/core/skills/adapters/EXAMPLES.md +19 -0
- package/.agents/core/skills/adapters/SKILL.md +105 -0
- package/.agents/core/skills/adapters/TROUBLESHOOTING.md +7 -0
- package/.agents/core/skills/adapters/VALIDATION.json +12 -0
- package/.agents/core/skills/adapters/skill.yaml +10 -0
- package/.agents/core/skills/architecture-diagrams/SKILL.md +108 -0
- package/.agents/core/skills/architecture-diagrams/VALIDATION.json +12 -0
- package/.agents/core/skills/architecture-diagrams/skill.yaml +8 -0
- package/.agents/core/skills/brutalist-design/SKILL.md +150 -0
- package/.agents/core/skills/brutalist-design/VALIDATION.json +12 -0
- package/.agents/core/skills/brutalist-design/skill.yaml +8 -0
- package/.agents/core/skills/context-manager/EXAMPLES.md +19 -0
- package/.agents/core/skills/context-manager/SKILL.md +126 -0
- package/.agents/core/skills/context-manager/TROUBLESHOOTING.md +7 -0
- package/.agents/core/skills/context-manager/VALIDATION.json +12 -0
- package/.agents/core/skills/context-manager/skill.yaml +10 -0
- package/.agents/core/skills/context-os/EXAMPLES.md +21 -0
- package/.agents/core/skills/context-os/SKILL.md +169 -0
- package/.agents/core/skills/context-os/TROUBLESHOOTING.md +7 -0
- package/.agents/core/skills/context-os/VALIDATION.json +12 -0
- package/.agents/core/skills/context-os/packs.yaml +59 -0
- package/.agents/core/skills/context-os/references/context-rules.md +68 -0
- package/.agents/core/skills/context-os/references/pipeline.md +119 -0
- package/.agents/core/skills/context-os/references/project-graph.md +103 -0
- package/.agents/core/skills/context-os/rules.yaml +135 -0
- package/.agents/core/skills/context-os/skill.yaml +10 -0
- package/.agents/core/skills/database/EXAMPLES.md +74 -0
- package/.agents/core/skills/database/SKILL.md +101 -0
- package/.agents/core/skills/database/TROUBLESHOOTING.md +18 -0
- package/.agents/core/skills/database/VALIDATION.json +11 -0
- package/.agents/core/skills/database/skill.yaml +25 -0
- package/.agents/core/skills/ddd/EXAMPLES.md +42 -0
- package/.agents/core/skills/ddd/SKILL.md +247 -0
- package/.agents/core/skills/ddd/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/ddd/VALIDATION.json +12 -0
- package/.agents/core/skills/ddd/ddd.md +178 -0
- package/.agents/core/skills/ddd/skill.yaml +10 -0
- package/.agents/core/skills/decisions/EXAMPLES.md +35 -0
- package/.agents/core/skills/decisions/SKILL.md +90 -0
- package/.agents/core/skills/decisions/TROUBLESHOOTING.md +13 -0
- package/.agents/core/skills/decisions/VALIDATION.json +12 -0
- package/.agents/core/skills/decisions/skill.yaml +10 -0
- package/.agents/core/skills/docker/EXAMPLES.md +56 -0
- package/.agents/core/skills/docker/SKILL.md +63 -0
- package/.agents/core/skills/docker/TROUBLESHOOTING.md +18 -0
- package/.agents/core/skills/docker/VALIDATION.json +11 -0
- package/.agents/core/skills/docker/skill.yaml +23 -0
- package/.agents/core/skills/engineering-workflow/EXAMPLES.md +57 -0
- package/.agents/core/skills/engineering-workflow/SKILL.md +343 -0
- package/.agents/core/skills/engineering-workflow/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/engineering-workflow/VALIDATION.json +12 -0
- package/.agents/core/skills/engineering-workflow/skill.yaml +13 -0
- package/.agents/core/skills/fastapi/EXAMPLES.md +36 -0
- package/.agents/core/skills/fastapi/SKILL.md +148 -0
- package/.agents/core/skills/fastapi/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/fastapi/VALIDATION.json +12 -0
- package/.agents/core/skills/fastapi/fastapi.md +112 -0
- package/.agents/core/skills/fastapi/skill.yaml +10 -0
- package/.agents/core/skills/gemini-precision/SKILL.md +169 -0
- package/.agents/core/skills/gemini-precision/VALIDATION.json +12 -0
- package/.agents/core/skills/gemini-precision/skill.yaml +9 -0
- package/.agents/core/skills/generators/EXAMPLES.md +19 -0
- package/.agents/core/skills/generators/SKILL.md +112 -0
- package/.agents/core/skills/generators/TROUBLESHOOTING.md +7 -0
- package/.agents/core/skills/generators/VALIDATION.json +12 -0
- package/.agents/core/skills/generators/skill.yaml +10 -0
- package/.agents/core/skills/generators/templates/API.md +77 -0
- package/.agents/core/skills/generators/templates/ARCHITECTURE.md +70 -0
- package/.agents/core/skills/generators/templates/DATABASE.md +42 -0
- package/.agents/core/skills/generators/templates/DECISION.md +46 -0
- package/.agents/core/skills/generators/templates/PRD.md +67 -0
- package/.agents/core/skills/generators/templates/PROJECT_GRAPH.md +56 -0
- package/.agents/core/skills/generators/templates/ROADMAP.md +51 -0
- package/.agents/core/skills/generators/templates/TASKS.md +43 -0
- package/.agents/core/skills/generators/templates/UI.md +73 -0
- package/.agents/core/skills/graphify/EXAMPLES.md +73 -0
- package/.agents/core/skills/graphify/SKILL.md +130 -0
- package/.agents/core/skills/graphify/VALIDATION.json +12 -0
- package/.agents/core/skills/graphify/skill.yaml +13 -0
- package/.agents/core/skills/gstack-roles/EXAMPLES.md +23 -0
- package/.agents/core/skills/gstack-roles/SKILL.md +152 -0
- package/.agents/core/skills/gstack-roles/TROUBLESHOOTING.md +13 -0
- package/.agents/core/skills/gstack-roles/VALIDATION.json +12 -0
- package/.agents/core/skills/gstack-roles/skill.yaml +12 -0
- package/.agents/core/skills/impeccable-design/EXAMPLES.md +26 -0
- package/.agents/core/skills/impeccable-design/SKILL.md +201 -0
- package/.agents/core/skills/impeccable-design/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/impeccable-design/VALIDATION.json +12 -0
- package/.agents/core/skills/impeccable-design/skill.yaml +14 -0
- package/.agents/core/skills/interview-me/SKILL.md +97 -0
- package/.agents/core/skills/interview-me/VALIDATION.json +12 -0
- package/.agents/core/skills/interview-me/skill.yaml +8 -0
- package/.agents/core/skills/microservices/EXAMPLES.md +38 -0
- package/.agents/core/skills/microservices/SKILL.md +164 -0
- package/.agents/core/skills/microservices/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/microservices/VALIDATION.json +12 -0
- package/.agents/core/skills/microservices/microservices.md +119 -0
- package/.agents/core/skills/microservices/skill.yaml +10 -0
- package/.agents/core/skills/minimalist-design/SKILL.md +113 -0
- package/.agents/core/skills/minimalist-design/VALIDATION.json +12 -0
- package/.agents/core/skills/minimalist-design/skill.yaml +8 -0
- package/.agents/core/skills/nestjs/EXAMPLES.md +40 -0
- package/.agents/core/skills/nestjs/SKILL.md +139 -0
- package/.agents/core/skills/nestjs/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/nestjs/VALIDATION.json +12 -0
- package/.agents/core/skills/nestjs/nestjs.md +103 -0
- package/.agents/core/skills/nestjs/skill.yaml +10 -0
- package/.agents/core/skills/nextjs/EXAMPLES.md +40 -0
- package/.agents/core/skills/nextjs/SKILL.md +163 -0
- package/.agents/core/skills/nextjs/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/nextjs/VALIDATION.json +12 -0
- package/.agents/core/skills/nextjs/nextjs.md +67 -0
- package/.agents/core/skills/nextjs/skill.yaml +10 -0
- package/.agents/core/skills/node/EXAMPLES.md +80 -0
- package/.agents/core/skills/node/SKILL.md +128 -0
- package/.agents/core/skills/node/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/node/VALIDATION.json +12 -0
- package/.agents/core/skills/node/node.md +87 -0
- package/.agents/core/skills/node/skill.yaml +10 -0
- package/.agents/core/skills/performance/EXAMPLES.md +30 -0
- package/.agents/core/skills/performance/SKILL.md +75 -0
- package/.agents/core/skills/performance/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/performance/VALIDATION.json +12 -0
- package/.agents/core/skills/performance/performance.md +52 -0
- package/.agents/core/skills/performance/skill.yaml +10 -0
- package/.agents/core/skills/ponytail-mindset/EXAMPLES.md +45 -0
- package/.agents/core/skills/ponytail-mindset/SKILL.md +193 -0
- package/.agents/core/skills/ponytail-mindset/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/ponytail-mindset/VALIDATION.json +12 -0
- package/.agents/core/skills/ponytail-mindset/skill.yaml +14 -0
- package/.agents/core/skills/react/EXAMPLES.md +79 -0
- package/.agents/core/skills/react/SKILL.md +132 -0
- package/.agents/core/skills/react/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/react/VALIDATION.json +12 -0
- package/.agents/core/skills/react/react.md +93 -0
- package/.agents/core/skills/react/skill.yaml +10 -0
- package/.agents/core/skills/react-best-practices/SKILL.md +155 -0
- package/.agents/core/skills/react-best-practices/VALIDATION.json +12 -0
- package/.agents/core/skills/react-best-practices/skill.yaml +10 -0
- package/.agents/core/skills/redesign-audit/SKILL.md +117 -0
- package/.agents/core/skills/redesign-audit/VALIDATION.json +12 -0
- package/.agents/core/skills/redesign-audit/skill.yaml +8 -0
- package/.agents/core/skills/security/EXAMPLES.md +64 -0
- package/.agents/core/skills/security/SKILL.md +158 -0
- package/.agents/core/skills/security/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/security/VALIDATION.json +12 -0
- package/.agents/core/skills/security/security.md +106 -0
- package/.agents/core/skills/security/skill.yaml +10 -0
- package/.agents/core/skills/soft-design/SKILL.md +108 -0
- package/.agents/core/skills/soft-design/VALIDATION.json +12 -0
- package/.agents/core/skills/soft-design/skill.yaml +8 -0
- package/.agents/core/skills/state-management/EXAMPLES.md +56 -0
- package/.agents/core/skills/state-management/SKILL.md +48 -0
- package/.agents/core/skills/state-management/TROUBLESHOOTING.md +18 -0
- package/.agents/core/skills/state-management/VALIDATION.json +11 -0
- package/.agents/core/skills/state-management/skill.yaml +22 -0
- package/.agents/core/skills/subagent-orchestrator/SKILL.md +100 -0
- package/.agents/core/skills/subagent-orchestrator/VALIDATION.json +12 -0
- package/.agents/core/skills/subagent-orchestrator/skill.yaml +8 -0
- package/.agents/core/skills/system-design/EXAMPLES.md +75 -0
- package/.agents/core/skills/system-design/SKILL.md +419 -0
- package/.agents/core/skills/system-design/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/system-design/VALIDATION.json +12 -0
- package/.agents/core/skills/system-design/skill.yaml +13 -0
- package/.agents/core/skills/system-design/system-design.md +112 -0
- package/.agents/core/skills/testing/EXAMPLES.md +71 -0
- package/.agents/core/skills/testing/SKILL.md +70 -0
- package/.agents/core/skills/testing/TROUBLESHOOTING.md +18 -0
- package/.agents/core/skills/testing/VALIDATION.json +11 -0
- package/.agents/core/skills/testing/skill.yaml +26 -0
- package/.agents/core/skills/typescript/EXAMPLES.md +64 -0
- package/.agents/core/skills/typescript/SKILL.md +112 -0
- package/.agents/core/skills/typescript/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/typescript/VALIDATION.json +12 -0
- package/.agents/core/skills/typescript/skill.yaml +10 -0
- package/.agents/core/skills/typescript/typescript.md +71 -0
- package/.agents/core/skills/ui-design/EXAMPLES.md +21 -0
- package/.agents/core/skills/ui-design/SKILL.md +124 -0
- package/.agents/core/skills/ui-design/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/ui-design/VALIDATION.json +12 -0
- package/.agents/core/skills/ui-design/skill.yaml +10 -0
- package/.agents/core/skills/ui-design/ui.md +88 -0
- package/.agents/core/skills/ui-ux-pro/EXAMPLES.md +62 -0
- package/.agents/core/skills/ui-ux-pro/SKILL.md +375 -0
- package/.agents/core/skills/ui-ux-pro/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/ui-ux-pro/VALIDATION.json +12 -0
- package/.agents/core/skills/ui-ux-pro/skill.yaml +13 -0
- package/.agents/core/skills/ux-design/EXAMPLES.md +36 -0
- package/.agents/core/skills/ux-design/SKILL.md +116 -0
- package/.agents/core/skills/ux-design/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/ux-design/VALIDATION.json +12 -0
- package/.agents/core/skills/ux-design/skill.yaml +10 -0
- package/.agents/core/skills/ux-design/ux.md +80 -0
- package/.agents/core/skills/vercel-optimize/SKILL.md +83 -0
- package/.agents/core/skills/vercel-optimize/VALIDATION.json +12 -0
- package/.agents/core/skills/vercel-optimize/skill.yaml +10 -0
- package/.agents/core/skills/web-accessibility/EXAMPLES.md +39 -0
- package/.agents/core/skills/web-accessibility/SKILL.md +170 -0
- package/.agents/core/skills/web-accessibility/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/web-accessibility/VALIDATION.json +12 -0
- package/.agents/core/skills/web-accessibility/accessibility.md +63 -0
- package/.agents/core/skills/web-accessibility/skill.yaml +10 -0
- package/.agents/ctx.js +370 -0
- package/.agents/generated/claude/skills/adapters/SKILL.md +126 -0
- package/.agents/generated/claude/skills/architecture-diagrams/SKILL.md +101 -0
- package/.agents/generated/claude/skills/brutalist-design/SKILL.md +145 -0
- package/.agents/generated/claude/skills/context-manager/SKILL.md +147 -0
- package/.agents/generated/claude/skills/context-os/SKILL.md +191 -0
- package/.agents/generated/claude/skills/database/SKILL.md +191 -0
- package/.agents/generated/claude/skills/ddd/SKILL.md +305 -0
- package/.agents/generated/claude/skills/decisions/SKILL.md +134 -0
- package/.agents/generated/claude/skills/docker/SKILL.md +135 -0
- package/.agents/generated/claude/skills/engineering-workflow/SKILL.md +414 -0
- package/.agents/generated/claude/skills/fastapi/SKILL.md +200 -0
- package/.agents/generated/claude/skills/gemini-precision/SKILL.md +161 -0
- package/.agents/generated/claude/skills/generators/SKILL.md +133 -0
- package/.agents/generated/claude/skills/graphify/SKILL.md +198 -0
- package/.agents/generated/claude/skills/gstack-roles/SKILL.md +184 -0
- package/.agents/generated/claude/skills/impeccable-design/SKILL.md +241 -0
- package/.agents/generated/claude/skills/interview-me/SKILL.md +90 -0
- package/.agents/generated/claude/skills/microservices/SKILL.md +218 -0
- package/.agents/generated/claude/skills/minimalist-design/SKILL.md +108 -0
- package/.agents/generated/claude/skills/nestjs/SKILL.md +195 -0
- package/.agents/generated/claude/skills/nextjs/SKILL.md +219 -0
- package/.agents/generated/claude/skills/node/SKILL.md +224 -0
- package/.agents/generated/claude/skills/performance/SKILL.md +121 -0
- package/.agents/generated/claude/skills/ponytail-mindset/SKILL.md +252 -0
- package/.agents/generated/claude/skills/react/SKILL.md +227 -0
- package/.agents/generated/claude/skills/react-best-practices/SKILL.md +146 -0
- package/.agents/generated/claude/skills/redesign-audit/SKILL.md +112 -0
- package/.agents/generated/claude/skills/security/SKILL.md +237 -0
- package/.agents/generated/claude/skills/soft-design/SKILL.md +103 -0
- package/.agents/generated/claude/skills/state-management/SKILL.md +120 -0
- package/.agents/generated/claude/skills/subagent-orchestrator/SKILL.md +93 -0
- package/.agents/generated/claude/skills/system-design/SKILL.md +507 -0
- package/.agents/generated/claude/skills/testing/SKILL.md +157 -0
- package/.agents/generated/claude/skills/typescript/SKILL.md +192 -0
- package/.agents/generated/claude/skills/ui-design/SKILL.md +161 -0
- package/.agents/generated/claude/skills/ui-ux-pro/SKILL.md +451 -0
- package/.agents/generated/claude/skills/ux-design/SKILL.md +168 -0
- package/.agents/generated/claude/skills/vercel-optimize/SKILL.md +76 -0
- package/.agents/generated/claude/skills/web-accessibility/SKILL.md +225 -0
- package/.agents/generated/gemini/skills/adapters/SKILL.md +135 -0
- package/.agents/generated/gemini/skills/architecture-diagrams/SKILL.md +107 -0
- package/.agents/generated/gemini/skills/brutalist-design/SKILL.md +151 -0
- package/.agents/generated/gemini/skills/context-manager/SKILL.md +156 -0
- package/.agents/generated/gemini/skills/context-os/SKILL.md +200 -0
- package/.agents/generated/gemini/skills/database/SKILL.md +200 -0
- package/.agents/generated/gemini/skills/ddd/SKILL.md +314 -0
- package/.agents/generated/gemini/skills/decisions/SKILL.md +143 -0
- package/.agents/generated/gemini/skills/docker/SKILL.md +144 -0
- package/.agents/generated/gemini/skills/engineering-workflow/SKILL.md +423 -0
- package/.agents/generated/gemini/skills/fastapi/SKILL.md +209 -0
- package/.agents/generated/gemini/skills/gemini-precision/SKILL.md +167 -0
- package/.agents/generated/gemini/skills/generators/SKILL.md +142 -0
- package/.agents/generated/gemini/skills/graphify/SKILL.md +205 -0
- package/.agents/generated/gemini/skills/gstack-roles/SKILL.md +193 -0
- package/.agents/generated/gemini/skills/impeccable-design/SKILL.md +250 -0
- package/.agents/generated/gemini/skills/interview-me/SKILL.md +96 -0
- package/.agents/generated/gemini/skills/microservices/SKILL.md +227 -0
- package/.agents/generated/gemini/skills/minimalist-design/SKILL.md +114 -0
- package/.agents/generated/gemini/skills/nestjs/SKILL.md +204 -0
- package/.agents/generated/gemini/skills/nextjs/SKILL.md +298 -0
- package/.agents/generated/gemini/skills/node/SKILL.md +323 -0
- package/.agents/generated/gemini/skills/performance/SKILL.md +185 -0
- package/.agents/generated/gemini/skills/ponytail-mindset/SKILL.md +261 -0
- package/.agents/generated/gemini/skills/react/SKILL.md +332 -0
- package/.agents/generated/gemini/skills/react-best-practices/SKILL.md +152 -0
- package/.agents/generated/gemini/skills/redesign-audit/SKILL.md +118 -0
- package/.agents/generated/gemini/skills/security/SKILL.md +355 -0
- package/.agents/generated/gemini/skills/soft-design/SKILL.md +109 -0
- package/.agents/generated/gemini/skills/state-management/SKILL.md +129 -0
- package/.agents/generated/gemini/skills/subagent-orchestrator/SKILL.md +99 -0
- package/.agents/generated/gemini/skills/system-design/SKILL.md +631 -0
- package/.agents/generated/gemini/skills/testing/SKILL.md +166 -0
- package/.agents/generated/gemini/skills/typescript/SKILL.md +275 -0
- package/.agents/generated/gemini/skills/ui-design/SKILL.md +170 -0
- package/.agents/generated/gemini/skills/ui-ux-pro/SKILL.md +460 -0
- package/.agents/generated/gemini/skills/ux-design/SKILL.md +177 -0
- package/.agents/generated/gemini/skills/vercel-optimize/SKILL.md +82 -0
- package/.agents/generated/gemini/skills/web-accessibility/SKILL.md +300 -0
- package/.agents/mcp/runtime.py +454 -0
- package/.agents/mcp/server.mjs +189373 -0
- package/.agents/plugins.js +574 -0
- package/.agents/profiles.js +267 -0
- package/.agents/resolver.js +336 -0
- package/.agents/skills-index.json +200 -0
- package/.agents/skills.json +6 -0
- package/.agents/validate.js +500 -0
- package/LICENSE +21 -0
- package/README.md +415 -0
- package/benchmarks/gemini-issues.js +533 -0
- package/bin/index.js +458 -0
- package/package.json +70 -0
- package/registry.json +53 -0
- package/registry.schema.json +32 -0
|
@@ -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,87 @@
|
|
|
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
|
+
```
|
|
@@ -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,52 @@
|
|
|
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
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# ponytail-mindset Examples — Anti-patterns vs ContextOS Standard
|
|
2
|
+
|
|
3
|
+
## Example 1: Data Formatting and Manipulation
|
|
4
|
+
|
|
5
|
+
### Anti-pattern: Over-engineered Custom Utility Class
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
// BAD: 40 lines of boilerplate for relative date formatting
|
|
9
|
+
export class DateFormatterService {
|
|
10
|
+
private static instance: DateFormatterService;
|
|
11
|
+
public static getInstance() { /* singleton boilerplate */ }
|
|
12
|
+
public formatRelative(date: Date): string {
|
|
13
|
+
const diff = Date.now() - date.getTime();
|
|
14
|
+
// 30 lines of manual math, plurals, and string building
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Best practice: ContextOS Standard (Standard Library Native API)
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
// GOOD: Native Intl API, zero bundle cost, handles all locales
|
|
23
|
+
export const formatRelativeTime = (date: Date, locale = 'en'): string => {
|
|
24
|
+
const diffDays = Math.round((date.getTime() - Date.now()) / (1000 * 60 * 60 * 24));
|
|
25
|
+
return new Intl.RelativeTimeFormat(locale, { numeric: 'auto' }).format(diffDays, 'day');
|
|
26
|
+
};
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Example 2: Component Library Reuse
|
|
32
|
+
|
|
33
|
+
### Anti-pattern: Hand-rolled Modal from Scratch
|
|
34
|
+
|
|
35
|
+
```text
|
|
36
|
+
BAD: Writing custom overlay DOM, manual scroll locking, manual focus trapping,
|
|
37
|
+
and custom keydown listeners. Burns 300+ lines of fragile code.
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Best practice: ContextOS Standard (Leverage Established Primitives)
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# GOOD: Install battle-tested primitive that handles ARIA, portals, and keyboard navigation
|
|
44
|
+
npx shadcn@latest add dialog
|
|
45
|
+
```
|