contextos-agents 1.7.0 → 2.0.0-beta.3
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 +16 -50
- 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 +100 -104
- 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 +537 -112
- package/.agents/customization-dx.js +282 -0
- package/.agents/doctor.js +855 -66
- 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 +278 -64
- package/.agents/profiles.js +486 -51
- package/.agents/resolver/canonical-resolver.js +1348 -0
- package/.agents/resolver.js +50 -534
- package/.agents/rules/rule-catalog.js +525 -0
- 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/skills-index.json +6 -166
- package/.agents/stats.js +9 -9
- 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 +87 -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,112 +0,0 @@
|
|
|
1
|
-
# System Design — Patterns & Principles
|
|
2
|
-
|
|
3
|
-
## Architecture Patterns
|
|
4
|
-
|
|
5
|
-
### Monolith (Start Here)
|
|
6
|
-
|
|
7
|
-
- **When**: MVP, small team, < 100K users
|
|
8
|
-
- **Structure**: Modular monolith with clear boundaries
|
|
9
|
-
- **Rule**: You can always extract microservices later. You can't easily merge them back.
|
|
10
|
-
|
|
11
|
-
### Microservices
|
|
12
|
-
|
|
13
|
-
- **When**: Team > 10 engineers, independent deployment needed
|
|
14
|
-
- **Communication**: REST (sync), Message Queue (async)
|
|
15
|
-
- **Data**: Each service owns its database
|
|
16
|
-
- **Pitfalls**: Network complexity, distributed transactions, debugging difficulty
|
|
17
|
-
|
|
18
|
-
### Event-Driven
|
|
19
|
-
|
|
20
|
-
- **When**: Loose coupling between services, async processing
|
|
21
|
-
- **Patterns**: Event Sourcing, CQRS, Pub/Sub
|
|
22
|
-
- **Tools**: Kafka, RabbitMQ, AWS SQS, Redis Streams
|
|
23
|
-
|
|
24
|
-
## Scalability
|
|
25
|
-
|
|
26
|
-
### Horizontal vs Vertical
|
|
27
|
-
|
|
28
|
-
- **Vertical first** — upgrade your server before distributing
|
|
29
|
-
- **Horizontal when** — you hit single-machine limits or need redundancy
|
|
30
|
-
|
|
31
|
-
### Database Scaling
|
|
32
|
-
|
|
33
|
-
1. **Indexes** — most common fix for slow queries
|
|
34
|
-
2. **Read replicas** — for read-heavy workloads
|
|
35
|
-
3. **Connection pooling** — PgBouncer, connection limits
|
|
36
|
-
4. **Caching** — Redis for hot data
|
|
37
|
-
5. **Sharding** — last resort, adds massive complexity
|
|
38
|
-
|
|
39
|
-
### Caching Layers
|
|
40
|
-
|
|
41
|
-
```
|
|
42
|
-
Client Cache (browser) → CDN → API Cache (Redis) → Database
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
| Strategy | Description |
|
|
46
|
-
| --- | --- |
|
|
47
|
-
| Cache-Aside | App checks cache first, fetches from DB on miss |
|
|
48
|
-
| Write-Through | App writes to cache AND DB simultaneously |
|
|
49
|
-
| Write-Behind | App writes to cache, async write to DB |
|
|
50
|
-
| TTL-based | Set expiry, accept stale data |
|
|
51
|
-
|
|
52
|
-
## Load Balancing
|
|
53
|
-
|
|
54
|
-
- **Round Robin** — simple, default
|
|
55
|
-
- **Least Connections** — for varying request duration
|
|
56
|
-
- **IP Hash** — for sticky sessions (avoid if possible)
|
|
57
|
-
- **Health checks** — remove unhealthy instances
|
|
58
|
-
|
|
59
|
-
## API Design
|
|
60
|
-
|
|
61
|
-
### REST Conventions
|
|
62
|
-
|
|
63
|
-
```
|
|
64
|
-
GET /users → List users
|
|
65
|
-
GET /users/:id → Get user
|
|
66
|
-
POST /users → Create user
|
|
67
|
-
PUT /users/:id → Full update
|
|
68
|
-
PATCH /users/:id → Partial update
|
|
69
|
-
DELETE /users/:id → Delete user
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### Pagination
|
|
73
|
-
|
|
74
|
-
- Cursor-based for real-time data (recommended)
|
|
75
|
-
- Offset-based for static data
|
|
76
|
-
|
|
77
|
-
### Versioning
|
|
78
|
-
|
|
79
|
-
- URL-based (`/v1/`, `/v2/`) — simplest
|
|
80
|
-
- Header-based — more flexible
|
|
81
|
-
|
|
82
|
-
## Reliability
|
|
83
|
-
|
|
84
|
-
- **Circuit breaker** — stop calling failing services
|
|
85
|
-
- **Retry with exponential backoff** — for transient failures
|
|
86
|
-
- **Timeout** — every external call needs a timeout
|
|
87
|
-
- **Health checks** — `/health` endpoint for load balancers
|
|
88
|
-
- **Graceful degradation** — work with reduced functionality
|
|
89
|
-
|
|
90
|
-
## Data Storage
|
|
91
|
-
|
|
92
|
-
| Use Case | Technology |
|
|
93
|
-
| --- | --- |
|
|
94
|
-
| Relational data, ACID | PostgreSQL |
|
|
95
|
-
| Key-value, caching | Redis |
|
|
96
|
-
| Full-text search | Elasticsearch, Meilisearch |
|
|
97
|
-
| Document store | MongoDB (if truly schemaless) |
|
|
98
|
-
| Time series | TimescaleDB, InfluxDB |
|
|
99
|
-
| Blob storage | S3, R2 |
|
|
100
|
-
| Queue | Redis Streams, RabbitMQ, SQS |
|
|
101
|
-
|
|
102
|
-
## Decision Framework
|
|
103
|
-
|
|
104
|
-
Before choosing an architecture:
|
|
105
|
-
|
|
106
|
-
1. What's the expected load? (users, requests/sec)
|
|
107
|
-
2. What's the team size?
|
|
108
|
-
3. What's the timeline?
|
|
109
|
-
4. What are the consistency requirements?
|
|
110
|
-
5. What's the budget?
|
|
111
|
-
|
|
112
|
-
**Default answer**: Start with a monolith, PostgreSQL, Redis cache. Extract services only when you have data showing you need to.
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
# Testing Examples — Anti-patterns vs ContextOS Standard
|
|
2
|
-
|
|
3
|
-
## Example 1: React Component Testing
|
|
4
|
-
|
|
5
|
-
### Anti-pattern: Anti-pattern (Brittle query & implementation coupling)
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
// BAD: querying by CSS class or test-id and testing internal state
|
|
9
|
-
test('submits form', async () => {
|
|
10
|
-
const wrapper = render(<LoginForm />);
|
|
11
|
-
const input = wrapper.container.querySelector('.email-input');
|
|
12
|
-
fireEvent.change(input, { target: { value: 'user@test.com' } });
|
|
13
|
-
fireEvent.click(wrapper.container.querySelector('#submit-btn'));
|
|
14
|
-
expect(wrapper.state().isSubmitted).toBe(true); // Brittle!
|
|
15
|
-
});
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
### Best practice: ContextOS Standard (User-centric role queries & userEvent)
|
|
19
|
-
|
|
20
|
-
```typescript
|
|
21
|
-
// GOOD: user-facing roles, userEvent, async wait
|
|
22
|
-
import { render, screen } from '@testing-library/react';
|
|
23
|
-
import userEvent from '@testing-library/user-event';
|
|
24
|
-
import { LoginForm } from './LoginForm';
|
|
25
|
-
|
|
26
|
-
test('submits form with valid user credentials', async () => {
|
|
27
|
-
const user = userEvent.setup();
|
|
28
|
-
const onSubmit = vi.fn();
|
|
29
|
-
render(<LoginForm onSubmit={onSubmit} />);
|
|
30
|
-
|
|
31
|
-
await user.type(screen.getByLabelText(/email address/i), 'user@test.com');
|
|
32
|
-
await user.type(screen.getByLabelText(/password/i), 'SecureP@ss123!');
|
|
33
|
-
await user.click(screen.getByRole('button', { name: /sign in/i }));
|
|
34
|
-
|
|
35
|
-
expect(onSubmit).toHaveBeenCalledWith({
|
|
36
|
-
email: 'user@test.com',
|
|
37
|
-
password: 'SecureP@ss123!'
|
|
38
|
-
});
|
|
39
|
-
expect(screen.queryByRole('alert')).not.toBeInTheDocument();
|
|
40
|
-
});
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
---
|
|
44
|
-
|
|
45
|
-
## Example 2: API Mocking with MSW (Mock Service Worker)
|
|
46
|
-
|
|
47
|
-
### Anti-pattern: Anti-pattern (Hardcoded global fetch monkey-patching)
|
|
48
|
-
|
|
49
|
-
```typescript
|
|
50
|
-
// BAD: globally overwriting fetch breaks other tests and hides actual contract
|
|
51
|
-
global.fetch = vi.fn().mockResolvedValue({
|
|
52
|
-
json: () => Promise.resolve({ data: 'ok' })
|
|
53
|
-
});
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### Best practice: ContextOS Standard (Network boundary mocking)
|
|
57
|
-
|
|
58
|
-
```typescript
|
|
59
|
-
// GOOD: declarative MSW network handler
|
|
60
|
-
import { http, HttpResponse } from 'msw';
|
|
61
|
-
import { setupServer } from 'msw/node';
|
|
62
|
-
|
|
63
|
-
export const server = setupServer(
|
|
64
|
-
http.get('/api/users/:id', ({ params }) => {
|
|
65
|
-
if (params.id === '404') {
|
|
66
|
-
return new HttpResponse(null, { status: 404 });
|
|
67
|
-
}
|
|
68
|
-
return HttpResponse.json({ id: params.id, name: 'Alice Smith' });
|
|
69
|
-
})
|
|
70
|
-
);
|
|
71
|
-
```
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: testing
|
|
3
|
-
description: Vitest, React Testing Library, and Playwright testing standards. Enforces TDD/BDD, test pyramid, zero brittle mocks, and complete assertion coverage.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Testing
|
|
7
|
-
|
|
8
|
-
## Overview
|
|
9
|
-
|
|
10
|
-
Testing strategy across unit, component, integration, and end-to-end testing suites using Vitest, React Testing Library, and Playwright.
|
|
11
|
-
|
|
12
|
-
## When to Use
|
|
13
|
-
|
|
14
|
-
Activate for any task involving unit tests, integration tests, E2E testing, TDD/BDD workflows, or fixing regression bugs.
|
|
15
|
-
|
|
16
|
-
## Rules & Patterns
|
|
17
|
-
|
|
18
|
-
### ️ The ContextOS Testing Pyramid
|
|
19
|
-
|
|
20
|
-
```
|
|
21
|
-
/\
|
|
22
|
-
/E2E\ 10% — Playwright (Critical user journeys, auth, checkout)
|
|
23
|
-
/-----\
|
|
24
|
-
/ Integ \ 20% — API & Component Integration (RTL + MSW / Supertest)
|
|
25
|
-
/---------\
|
|
26
|
-
/ Unit \ 70% — Pure functions, Domain Entities, Utils (Vitest)
|
|
27
|
-
/-------------\
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
### Negative Constraints (What NOT to Do)
|
|
31
|
-
|
|
32
|
-
1. **NEVER mock internal implementation details**: Mock ONLY external I/O boundaries (HTTP network requests via MSW, Database via test containers or in-memory DB).
|
|
33
|
-
2. **NEVER test implementation details**: In React Testing Library, query by user-facing roles (`getByRole`, `getByLabelText`), NEVER by CSS selectors or internal component state.
|
|
34
|
-
3. **NEVER write assertions without an expected failure mode**: Each test must test a single logical behavior and fail if that behavior breaks.
|
|
35
|
-
4. **NEVER leave flaky tests or arbitrary sleep (`await delay(1000)`)**: Always use `waitFor()` or explicit event triggers with timeouts.
|
|
36
|
-
5. **NEVER share mutable state between tests**: Every test must have isolated state via `beforeEach()` setup and clean reset.
|
|
37
|
-
|
|
38
|
-
### AAA Standard Pattern
|
|
39
|
-
|
|
40
|
-
```typescript
|
|
41
|
-
describe('Feature / Unit', () => {
|
|
42
|
-
it('should achieve expected outcome when given specific condition', async () => {
|
|
43
|
-
// 1. ARRANGE
|
|
44
|
-
const user = createTestUser({ role: 'admin' });
|
|
45
|
-
// 2. ACT
|
|
46
|
-
const result = await processOrder(user, sampleCart);
|
|
47
|
-
// 3. ASSERT
|
|
48
|
-
expect(result.status).toBe('confirmed');
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
## Code Examples
|
|
54
|
-
|
|
55
|
-
See `EXAMPLES.md` for detailed anti-patterns and production testing code.
|
|
56
|
-
|
|
57
|
-
## Validation Checklist
|
|
58
|
-
|
|
59
|
-
- [ ] Tests follow Arrange-Act-Assert (AAA) structure
|
|
60
|
-
- [ ] No brittle CSS selectors or private state inspections
|
|
61
|
-
- [ ] Mocks isolated strictly to network/IO boundaries (MSW)
|
|
62
|
-
- [ ] Fast execution (< 5s for unit suite) with zero flaky sleeps
|
|
63
|
-
|
|
64
|
-
## Common Mistakes
|
|
65
|
-
|
|
66
|
-
- Over-mocking modules instead of running real pure logic. See `TROUBLESHOOTING.md`.
|
|
67
|
-
|
|
68
|
-
## Integration Notes
|
|
69
|
-
|
|
70
|
-
Interacts directly with `engineering-workflow` (Verify phase), `react`, and `typescript`.
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# Testing Troubleshooting Guide
|
|
2
|
-
|
|
3
|
-
## Common Issues & Fixes
|
|
4
|
-
|
|
5
|
-
### 1. `act(...)` warning in React Testing Library
|
|
6
|
-
|
|
7
|
-
- **Cause**: An asynchronous state update triggered after the test completed.
|
|
8
|
-
- **Fix**: Ensure all async operations are awaited using `await waitFor(() => ...)` or `await screen.findByRole(...)`.
|
|
9
|
-
|
|
10
|
-
### 2. Tests pass in isolation but fail in concurrent test runs
|
|
11
|
-
|
|
12
|
-
- **Cause**: Shared in-memory state or un-reset singleton.
|
|
13
|
-
- **Fix**: Reset all mocks and in-memory databases in `beforeEach(() => vi.clearAllMocks())` and `afterEach(() => cleanup())`.
|
|
14
|
-
|
|
15
|
-
### 3. Playwright timeout waiting for selector
|
|
16
|
-
|
|
17
|
-
- **Cause**: Element is animating or blocked behind a modal/overlay.
|
|
18
|
-
- **Fix**: Use web-first assertions like `await expect(page.getByRole('button')).toBeVisible()` which automatically retry until timeout.
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"skill": "testing",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"checks": [
|
|
5
|
-
"Test pyramid ratio enforced (70% unit/integration)",
|
|
6
|
-
"AAA (Arrange-Act-Assert) pattern implemented",
|
|
7
|
-
"No internal state inspection or brittle selectors",
|
|
8
|
-
"MSW used for network boundaries",
|
|
9
|
-
"Zero shared state between test executions"
|
|
10
|
-
]
|
|
11
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
name: testing
|
|
2
|
-
description: Vitest, React Testing Library, and Playwright testing standards. Enforces TDD/BDD, test pyramid, zero brittle mocks, and complete assertion coverage.
|
|
3
|
-
version: 1.0.0
|
|
4
|
-
category: engineering
|
|
5
|
-
type: instruction-only
|
|
6
|
-
requires:
|
|
7
|
-
- engineering-workflow
|
|
8
|
-
- typescript
|
|
9
|
-
triggers:
|
|
10
|
-
files:
|
|
11
|
-
- "*.test.ts"
|
|
12
|
-
- "*.test.tsx"
|
|
13
|
-
- "*.test.js"
|
|
14
|
-
- "*.spec.ts"
|
|
15
|
-
- "*.spec.tsx"
|
|
16
|
-
- "vitest.config.*"
|
|
17
|
-
- "playwright.config.*"
|
|
18
|
-
- "jest.config.*"
|
|
19
|
-
keywords:
|
|
20
|
-
- "test"
|
|
21
|
-
- "vitest"
|
|
22
|
-
- "playwright"
|
|
23
|
-
- "unit test"
|
|
24
|
-
- "e2e"
|
|
25
|
-
- "mock"
|
|
26
|
-
- "assert"
|
|
27
|
-
- "coverage"
|
|
28
|
-
resources:
|
|
29
|
-
- EXAMPLES.md
|
|
30
|
-
- SKILL.md
|
|
31
|
-
- TROUBLESHOOTING.md
|
|
32
|
-
- VALIDATION.json
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
# TypeScript Examples — Anti-patterns vs ContextOS Standard
|
|
2
|
-
|
|
3
|
-
## Example 1: Type-Safe Parsing with Zod (No `any`)
|
|
4
|
-
|
|
5
|
-
### Anti-pattern: Anti-pattern (Blind type assertion with `as`)
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
// BAD: using 'as User' bypasses runtime validation completely
|
|
9
|
-
async function fetchUser(id: string): Promise<User> {
|
|
10
|
-
const res = await fetch(`/api/users/${id}`);
|
|
11
|
-
const data = await res.json();
|
|
12
|
-
return data as User; // Runtime crash if payload changes!
|
|
13
|
-
}
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
### Best practice: ContextOS Standard (Runtime schema validation with Zod)
|
|
17
|
-
|
|
18
|
-
```typescript
|
|
19
|
-
// GOOD: guaranteed runtime and compile-time type safety
|
|
20
|
-
import { z } from 'zod';
|
|
21
|
-
|
|
22
|
-
export const UserSchema = z.object({
|
|
23
|
-
id: z.string().uuid(),
|
|
24
|
-
name: z.string().min(1),
|
|
25
|
-
email: z.string().email(),
|
|
26
|
-
role: z.enum(['admin', 'member', 'guest']),
|
|
27
|
-
createdAt: z.string().datetime(),
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
export type User = z.infer<typeof UserSchema>;
|
|
31
|
-
|
|
32
|
-
export async function fetchUser(id: string): Promise<User> {
|
|
33
|
-
const res = await fetch(`/api/users/${id}`);
|
|
34
|
-
if (!res.ok) throw new Error(`Fetch failed with status ${res.status}`);
|
|
35
|
-
const raw: unknown = await res.json();
|
|
36
|
-
return UserSchema.parse(raw);
|
|
37
|
-
}
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
---
|
|
41
|
-
|
|
42
|
-
## Example 2: Discriminated Unions for State Handling
|
|
43
|
-
|
|
44
|
-
### Anti-pattern: Anti-pattern (Optional soup with boolean flags)
|
|
45
|
-
|
|
46
|
-
```typescript
|
|
47
|
-
// BAD: impossible states can be represented (e.g. isLoading: true AND error: 'Failed')
|
|
48
|
-
interface AsyncState<T> {
|
|
49
|
-
data?: T;
|
|
50
|
-
isLoading: boolean;
|
|
51
|
-
error?: string;
|
|
52
|
-
}
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### Best practice: ContextOS Standard (Discriminated Union)
|
|
56
|
-
|
|
57
|
-
```typescript
|
|
58
|
-
// GOOD: impossible states are impossible at compile-time
|
|
59
|
-
export type AsyncState<T> =
|
|
60
|
-
| { readonly status: 'idle' }
|
|
61
|
-
| { readonly status: 'loading' }
|
|
62
|
-
| { readonly status: 'success'; readonly data: T }
|
|
63
|
-
| { readonly status: 'error'; readonly error: Error };
|
|
64
|
-
```
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: TypeScript
|
|
3
|
-
description: >
|
|
4
|
-
ContextOS skill for TypeScript
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# TypeScript
|
|
8
|
-
|
|
9
|
-
## Overview
|
|
10
|
-
|
|
11
|
-
Strict TypeScript engineering standard. Enforces noImplicitAny, discriminated unions, branded types, immutability, exhaustive switch checks, and zero unsafe any or as unknown as T casts.
|
|
12
|
-
|
|
13
|
-
## When to Use
|
|
14
|
-
|
|
15
|
-
Activate on all TypeScript and JavaScript codebases to ensure compile-time type safety, robust domain modeling, and foolproof function contracts.
|
|
16
|
-
|
|
17
|
-
## Negative Constraints (What NOT to Do)
|
|
18
|
-
|
|
19
|
-
1. **NEVER use `any`**: Use `unknown` with type guards, discriminated unions, or Zod schemas.
|
|
20
|
-
2. **NEVER use type assertions (`as Type` or `as unknown as Type`) to bypass safety**: Fix the underlying type signature or use runtime narrowing (`instanceof`, `typeof`, `in`).
|
|
21
|
-
3. **NEVER use non-null assertions (`foo!.bar`)**: Handle `null` and `undefined` with optional chaining (`?.`) or explicit error guards.
|
|
22
|
-
4. **NEVER export mutable global arrays or object constants**: Always mark constant objects and arrays with `as const` and `readonly`.
|
|
23
|
-
5. **NEVER omit explicit return types on exported functions**: Exported public APIs must declare explicit return types to protect consumers.
|
|
24
|
-
|
|
25
|
-
## Rules & Patterns
|
|
26
|
-
|
|
27
|
-
## Strict Mode
|
|
28
|
-
|
|
29
|
-
Always use strict TypeScript configuration:
|
|
30
|
-
|
|
31
|
-
```json
|
|
32
|
-
{
|
|
33
|
-
"compilerOptions": {
|
|
34
|
-
"strict": true,
|
|
35
|
-
"noUncheckedIndexedAccess": true,
|
|
36
|
-
"noImplicitReturns": true,
|
|
37
|
-
"noFallthroughCasesInSwitch": true
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Types
|
|
43
|
-
|
|
44
|
-
- **Prefer `interface`** for object shapes, `type` for unions/intersections
|
|
45
|
-
- **No `any`** — use `unknown` if type is truly unknown, then narrow
|
|
46
|
-
- **Explicit return types** for exported functions
|
|
47
|
-
- **Const assertions** — `as const` for literal types
|
|
48
|
-
|
|
49
|
-
```typescript
|
|
50
|
-
// Good
|
|
51
|
-
interface User {
|
|
52
|
-
id: string;
|
|
53
|
-
name: string;
|
|
54
|
-
role: 'admin' | 'user';
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Unions
|
|
58
|
-
type Result<T> = { ok: true; data: T } | { ok: false; error: string };
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
## Utility Types
|
|
62
|
-
|
|
63
|
-
- `Partial<T>` — all properties optional
|
|
64
|
-
- `Required<T>` — all properties required
|
|
65
|
-
- `Pick<T, K>` — select specific properties
|
|
66
|
-
- `Omit<T, K>` — remove specific properties
|
|
67
|
-
- `Record<K, V>` — key-value map
|
|
68
|
-
|
|
69
|
-
## Type Guards
|
|
70
|
-
|
|
71
|
-
```typescript
|
|
72
|
-
function isUser(value: unknown): value is User {
|
|
73
|
-
return typeof value === 'object' && value !== null && 'id' in value;
|
|
74
|
-
}
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
## Generic Patterns
|
|
78
|
-
|
|
79
|
-
```typescript
|
|
80
|
-
// Repository pattern
|
|
81
|
-
interface Repository<T extends { id: string }> {
|
|
82
|
-
findById(id: string): Promise<T | null>;
|
|
83
|
-
create(data: Omit<T, 'id'>): Promise<T>;
|
|
84
|
-
update(id: string, data: Partial<T>): Promise<T>;
|
|
85
|
-
delete(id: string): Promise<void>;
|
|
86
|
-
}
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
## Anti-Patterns
|
|
90
|
-
|
|
91
|
-
- [FAIL] `any` — use `unknown` + type guards
|
|
92
|
-
- [FAIL] Type assertions (`as`) — prefer type guards
|
|
93
|
-
- [FAIL] Non-null assertions (`!`) — handle null explicitly
|
|
94
|
-
- [FAIL] Enums — prefer union types or `as const` objects
|
|
95
|
-
- [FAIL] Complex generics without JSDoc — document intent
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
## Code Examples
|
|
99
|
-
|
|
100
|
-
See `EXAMPLES.md` for detailed code examples.
|
|
101
|
-
|
|
102
|
-
## Validation Checklist
|
|
103
|
-
|
|
104
|
-
What to verify during the review phase before completing the task.
|
|
105
|
-
|
|
106
|
-
## Common Mistakes
|
|
107
|
-
|
|
108
|
-
Anti-patterns and things to explicitly avoid. See `TROUBLESHOOTING.md`.
|
|
109
|
-
|
|
110
|
-
## Integration Notes
|
|
111
|
-
|
|
112
|
-
How this skill interacts with other skills.
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# typescript Troubleshooting & Common Mistakes
|
|
2
|
-
|
|
3
|
-
## 1. Excessive Use of `any` or `as unknown as T`
|
|
4
|
-
|
|
5
|
-
- **Symptom**: Runtime `TypeError: Cannot read properties of undefined` in supposedly typed TypeScript code.
|
|
6
|
-
- **Root Cause**: Bypassing type checking with `any` or forceful type assertions.
|
|
7
|
-
- **Fix**: Use `unknown` with type guards, Zod schemas, or discriminated unions.
|
|
8
|
-
|
|
9
|
-
## 2. Non-Exhaustive Switch on Unions
|
|
10
|
-
|
|
11
|
-
- **Symptom**: New union member added but some switch statements fail to handle it, producing bugs.
|
|
12
|
-
- **Root Cause**: Missing exhaustive type checking in `default:` case.
|
|
13
|
-
- **Fix**: Add `default: const _exhaustive: never = action; throw new Error(_exhaustive);` to let the compiler catch missing branches.
|
|
14
|
-
|
|
15
|
-
## 3. Inaccurate Generics Constraints
|
|
16
|
-
|
|
17
|
-
- **Symptom**: Generic functions that lose type inference and resolve to `unknown`.
|
|
18
|
-
- **Root Cause**: Over-specifying generics or missing `extends` constraints.
|
|
19
|
-
- **Fix**: Constrain generics narrowly: `function get<T, K extends keyof T>(obj: T, key: K): T[K]`.
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
id: typescript
|
|
2
|
-
name: TypeScript
|
|
3
|
-
category: frontend
|
|
4
|
-
type: instruction-only
|
|
5
|
-
tags: [frontend, backend, types, static-analysis]
|
|
6
|
-
requires: []
|
|
7
|
-
optional: [zod, prisma]
|
|
8
|
-
conflicts: []
|
|
9
|
-
weight: 9
|
|
10
|
-
documents:
|
|
11
|
-
- typescript.md
|
|
12
|
-
resources:
|
|
13
|
-
- EXAMPLES.md
|
|
14
|
-
- SKILL.md
|
|
15
|
-
- TROUBLESHOOTING.md
|
|
16
|
-
- VALIDATION.json
|
|
17
|
-
- typescript.md
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
# TypeScript — Best Practices
|
|
2
|
-
|
|
3
|
-
## Strict Mode
|
|
4
|
-
|
|
5
|
-
Always use strict TypeScript configuration:
|
|
6
|
-
|
|
7
|
-
```json
|
|
8
|
-
{
|
|
9
|
-
"compilerOptions": {
|
|
10
|
-
"strict": true,
|
|
11
|
-
"noUncheckedIndexedAccess": true,
|
|
12
|
-
"noImplicitReturns": true,
|
|
13
|
-
"noFallthroughCasesInSwitch": true
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Types
|
|
19
|
-
|
|
20
|
-
- **Prefer `interface`** for object shapes, `type` for unions/intersections
|
|
21
|
-
- **No `any`** — use `unknown` if type is truly unknown, then narrow
|
|
22
|
-
- **Explicit return types** for exported functions
|
|
23
|
-
- **Const assertions** — `as const` for literal types
|
|
24
|
-
|
|
25
|
-
```typescript
|
|
26
|
-
// Good
|
|
27
|
-
interface User {
|
|
28
|
-
id: string;
|
|
29
|
-
name: string;
|
|
30
|
-
role: 'admin' | 'user';
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Unions
|
|
34
|
-
type Result<T> = { ok: true; data: T } | { ok: false; error: string };
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## Utility Types
|
|
38
|
-
|
|
39
|
-
- `Partial<T>` — all properties optional
|
|
40
|
-
- `Required<T>` — all properties required
|
|
41
|
-
- `Pick<T, K>` — select specific properties
|
|
42
|
-
- `Omit<T, K>` — remove specific properties
|
|
43
|
-
- `Record<K, V>` — key-value map
|
|
44
|
-
|
|
45
|
-
## Type Guards
|
|
46
|
-
|
|
47
|
-
```typescript
|
|
48
|
-
function isUser(value: unknown): value is User {
|
|
49
|
-
return typeof value === 'object' && value !== null && 'id' in value;
|
|
50
|
-
}
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
## Generic Patterns
|
|
54
|
-
|
|
55
|
-
```typescript
|
|
56
|
-
// Repository pattern
|
|
57
|
-
interface Repository<T extends { id: string }> {
|
|
58
|
-
findById(id: string): Promise<T | null>;
|
|
59
|
-
create(data: Omit<T, 'id'>): Promise<T>;
|
|
60
|
-
update(id: string, data: Partial<T>): Promise<T>;
|
|
61
|
-
delete(id: string): Promise<void>;
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## Anti-Patterns
|
|
66
|
-
|
|
67
|
-
- [FAIL] `any` — use `unknown` + type guards
|
|
68
|
-
- [FAIL] Type assertions (`as`) — prefer type guards
|
|
69
|
-
- [FAIL] Non-null assertions (`!`) — handle null explicitly
|
|
70
|
-
- [FAIL] Enums — prefer union types or `as const` objects
|
|
71
|
-
- [FAIL] Complex generics without JSDoc — document intent
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# ui-design Examples — Anti-patterns vs ContextOS Standard
|
|
2
|
-
|
|
3
|
-
## Example 1: Component Token Consistency
|
|
4
|
-
|
|
5
|
-
### Anti-pattern: Hardcoded Arbitrary Tailwind Utilities
|
|
6
|
-
|
|
7
|
-
```tsx
|
|
8
|
-
// BAD: Inconsistent spacing, arbitrary colors, unmaintainable styling
|
|
9
|
-
<div className="p-[13px] bg-[#1a1b2e] rounded-[7px] text-[#99aab5] border border-[#2b2d42]">
|
|
10
|
-
<button className="px-[15px] py-[7px] bg-[#5865f2] hover:bg-[#4752c4]">Action</button>
|
|
11
|
-
</div>
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
### Best practice: ContextOS Standard (Semantic Theme Tokens)
|
|
15
|
-
|
|
16
|
-
```tsx
|
|
17
|
-
// GOOD: Consistent scale utilities driven by Tailwind v4 @theme design tokens
|
|
18
|
-
<div className="p-4 bg-card rounded-lg text-muted-foreground border border-border">
|
|
19
|
-
<Button variant="primary" size="md">Action</Button>
|
|
20
|
-
</div>
|
|
21
|
-
```
|