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.
- package/.agents/adapters/aider/export.js +2 -2
- package/.agents/adapters/claude/export.js +53 -2
- package/.agents/adapters/drift-detector.js +6 -3
- package/.agents/adapters/pure-compiler.js +18 -6
- package/.agents/ctx.js +13 -8
- package/.agents/plugins.js +347 -26
- package/.agents/profiles.js +32 -11
- package/README.md +38 -3
- package/bin/commands/hook.js +50 -12
- package/bin/commands/scan.js +10 -3
- package/bin/index.js +165 -53
- package/bin/lib/git-snapshot.js +70 -43
- package/bin/lib/scan.js +108 -27
- package/bin/lib/ui.js +140 -0
- package/catalog/skills/adapters/EXAMPLES.md +19 -0
- package/catalog/skills/adapters/SKILL.md +101 -0
- package/catalog/skills/adapters/TROUBLESHOOTING.md +7 -0
- package/catalog/skills/adapters/VALIDATION.json +12 -0
- package/catalog/skills/adapters/skill.yaml +13 -0
- package/catalog/skills/api-design/EXAMPLES.md +91 -0
- package/catalog/skills/api-design/SKILL.md +63 -0
- package/catalog/skills/api-design/TROUBLESHOOTING.md +54 -0
- package/catalog/skills/api-design/VALIDATION.json +11 -0
- package/catalog/skills/api-design/skill.yaml +14 -0
- package/catalog/skills/architecture-diagrams/SKILL.md +108 -0
- package/catalog/skills/architecture-diagrams/VALIDATION.json +12 -0
- package/catalog/skills/architecture-diagrams/skill.yaml +9 -0
- package/catalog/skills/brutalist-design/EXAMPLES.md +59 -0
- package/catalog/skills/brutalist-design/SKILL.md +150 -0
- package/catalog/skills/brutalist-design/VALIDATION.json +12 -0
- package/catalog/skills/brutalist-design/skill.yaml +10 -0
- package/catalog/skills/ci-cd/EXAMPLES.md +79 -0
- package/catalog/skills/ci-cd/SKILL.md +69 -0
- package/catalog/skills/ci-cd/TROUBLESHOOTING.md +52 -0
- package/catalog/skills/ci-cd/VALIDATION.json +11 -0
- package/catalog/skills/ci-cd/skill.yaml +13 -0
- package/catalog/skills/database/EXAMPLES.md +74 -0
- package/catalog/skills/database/SKILL.md +101 -0
- package/catalog/skills/database/TROUBLESHOOTING.md +18 -0
- package/catalog/skills/database/VALIDATION.json +11 -0
- package/catalog/skills/database/skill.yaml +14 -0
- package/catalog/skills/ddd/EXAMPLES.md +42 -0
- package/catalog/skills/ddd/SKILL.md +247 -0
- package/catalog/skills/ddd/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/ddd/VALIDATION.json +12 -0
- package/catalog/skills/ddd/skill.yaml +14 -0
- package/catalog/skills/decisions/EXAMPLES.md +35 -0
- package/catalog/skills/decisions/SKILL.md +90 -0
- package/catalog/skills/decisions/TROUBLESHOOTING.md +13 -0
- package/catalog/skills/decisions/VALIDATION.json +12 -0
- package/catalog/skills/decisions/skill.yaml +13 -0
- package/catalog/skills/docker/EXAMPLES.md +56 -0
- package/catalog/skills/docker/SKILL.md +169 -0
- package/catalog/skills/docker/TROUBLESHOOTING.md +18 -0
- package/catalog/skills/docker/VALIDATION.json +11 -0
- package/catalog/skills/docker/skill.yaml +13 -0
- package/catalog/skills/fastapi/EXAMPLES.md +36 -0
- package/catalog/skills/fastapi/SKILL.md +171 -0
- package/catalog/skills/fastapi/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/fastapi/VALIDATION.json +12 -0
- package/catalog/skills/fastapi/skill.yaml +14 -0
- package/catalog/skills/generators/EXAMPLES.md +19 -0
- package/catalog/skills/generators/SKILL.md +110 -0
- package/catalog/skills/generators/TROUBLESHOOTING.md +7 -0
- package/catalog/skills/generators/VALIDATION.json +12 -0
- package/catalog/skills/generators/skill.yaml +22 -0
- package/catalog/skills/generators/templates/API.md +77 -0
- package/catalog/skills/generators/templates/ARCHITECTURE.md +70 -0
- package/catalog/skills/generators/templates/DATABASE.md +42 -0
- package/catalog/skills/generators/templates/DECISION.md +46 -0
- package/catalog/skills/generators/templates/PRD.md +67 -0
- package/catalog/skills/generators/templates/PROJECT_GRAPH.md +56 -0
- package/catalog/skills/generators/templates/ROADMAP.md +51 -0
- package/catalog/skills/generators/templates/TASKS.md +43 -0
- package/catalog/skills/generators/templates/UI.md +73 -0
- package/catalog/skills/graphify/EXAMPLES.md +73 -0
- package/catalog/skills/graphify/SKILL.md +130 -0
- package/catalog/skills/graphify/VALIDATION.json +12 -0
- package/catalog/skills/graphify/skill.yaml +13 -0
- package/catalog/skills/impeccable-design/EXAMPLES.md +26 -0
- package/catalog/skills/impeccable-design/SKILL.md +201 -0
- package/catalog/skills/impeccable-design/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/impeccable-design/VALIDATION.json +12 -0
- package/catalog/skills/impeccable-design/skill.yaml +15 -0
- package/catalog/skills/interview-me/SKILL.md +97 -0
- package/catalog/skills/interview-me/VALIDATION.json +12 -0
- package/catalog/skills/interview-me/skill.yaml +9 -0
- package/catalog/skills/microservices/EXAMPLES.md +38 -0
- package/catalog/skills/microservices/SKILL.md +164 -0
- package/catalog/skills/microservices/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/microservices/VALIDATION.json +12 -0
- package/catalog/skills/microservices/skill.yaml +14 -0
- package/catalog/skills/minimalist-design/EXAMPLES.md +58 -0
- package/catalog/skills/minimalist-design/SKILL.md +113 -0
- package/catalog/skills/minimalist-design/VALIDATION.json +12 -0
- package/catalog/skills/minimalist-design/skill.yaml +10 -0
- package/catalog/skills/nestjs/EXAMPLES.md +40 -0
- package/catalog/skills/nestjs/SKILL.md +139 -0
- package/catalog/skills/nestjs/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/nestjs/VALIDATION.json +12 -0
- package/catalog/skills/nestjs/skill.yaml +14 -0
- package/catalog/skills/nextjs/EXAMPLES.md +40 -0
- package/catalog/skills/nextjs/SKILL.md +163 -0
- package/catalog/skills/nextjs/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/nextjs/VALIDATION.json +12 -0
- package/catalog/skills/nextjs/skill.yaml +14 -0
- package/catalog/skills/node/EXAMPLES.md +80 -0
- package/catalog/skills/node/SKILL.md +128 -0
- package/catalog/skills/node/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/node/VALIDATION.json +12 -0
- package/catalog/skills/node/skill.yaml +14 -0
- package/catalog/skills/performance/EXAMPLES.md +30 -0
- package/catalog/skills/performance/SKILL.md +75 -0
- package/catalog/skills/performance/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/performance/VALIDATION.json +12 -0
- package/catalog/skills/performance/skill.yaml +14 -0
- package/catalog/skills/react/EXAMPLES.md +79 -0
- package/catalog/skills/react/SKILL.md +132 -0
- package/catalog/skills/react/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/react/VALIDATION.json +12 -0
- package/catalog/skills/react/skill.yaml +14 -0
- package/catalog/skills/react-best-practices/SKILL.md +158 -0
- package/catalog/skills/react-best-practices/VALIDATION.json +12 -0
- package/catalog/skills/react-best-practices/skill.yaml +13 -0
- package/catalog/skills/redesign-audit/SKILL.md +117 -0
- package/catalog/skills/redesign-audit/VALIDATION.json +12 -0
- package/catalog/skills/redesign-audit/skill.yaml +9 -0
- package/catalog/skills/security-audit/EXAMPLES.md +79 -0
- package/catalog/skills/security-audit/SKILL.md +91 -0
- package/catalog/skills/security-audit/TROUBLESHOOTING.md +46 -0
- package/catalog/skills/security-audit/VALIDATION.json +11 -0
- package/catalog/skills/security-audit/skill.yaml +14 -0
- package/catalog/skills/soft-design/EXAMPLES.md +51 -0
- package/catalog/skills/soft-design/SKILL.md +108 -0
- package/catalog/skills/soft-design/VALIDATION.json +12 -0
- package/catalog/skills/soft-design/skill.yaml +10 -0
- package/catalog/skills/state-management/EXAMPLES.md +56 -0
- package/catalog/skills/state-management/SKILL.md +168 -0
- package/catalog/skills/state-management/TROUBLESHOOTING.md +18 -0
- package/catalog/skills/state-management/VALIDATION.json +11 -0
- package/catalog/skills/state-management/skill.yaml +14 -0
- package/catalog/skills/subagent-orchestrator/SKILL.md +117 -0
- package/catalog/skills/subagent-orchestrator/VALIDATION.json +12 -0
- package/catalog/skills/subagent-orchestrator/skill.yaml +9 -0
- package/catalog/skills/system-design/EXAMPLES.md +75 -0
- package/catalog/skills/system-design/SKILL.md +419 -0
- package/catalog/skills/system-design/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/system-design/VALIDATION.json +12 -0
- package/catalog/skills/system-design/skill.yaml +14 -0
- package/catalog/skills/terraform/EXAMPLES.md +74 -0
- package/catalog/skills/terraform/SKILL.md +55 -0
- package/catalog/skills/terraform/TROUBLESHOOTING.md +53 -0
- package/catalog/skills/terraform/VALIDATION.json +11 -0
- package/catalog/skills/terraform/skill.yaml +14 -0
- package/catalog/skills/testing/EXAMPLES.md +122 -0
- package/catalog/skills/testing/SKILL.md +70 -0
- package/catalog/skills/testing/TROUBLESHOOTING.md +18 -0
- package/catalog/skills/testing/VALIDATION.json +11 -0
- package/catalog/skills/testing/skill.yaml +14 -0
- package/catalog/skills/typescript/EXAMPLES.md +64 -0
- package/catalog/skills/typescript/SKILL.md +112 -0
- package/catalog/skills/typescript/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/typescript/VALIDATION.json +12 -0
- package/catalog/skills/typescript/skill.yaml +14 -0
- package/catalog/skills/ui-design/EXAMPLES.md +21 -0
- package/catalog/skills/ui-design/SKILL.md +124 -0
- package/catalog/skills/ui-design/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/ui-design/VALIDATION.json +12 -0
- package/catalog/skills/ui-design/skill.yaml +16 -0
- package/catalog/skills/ui-ux-pro/EXAMPLES.md +62 -0
- package/catalog/skills/ui-ux-pro/SKILL.md +418 -0
- package/catalog/skills/ui-ux-pro/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/ui-ux-pro/VALIDATION.json +12 -0
- package/catalog/skills/ui-ux-pro/skill.yaml +14 -0
- package/catalog/skills/ux-design/EXAMPLES.md +36 -0
- package/catalog/skills/ux-design/SKILL.md +116 -0
- package/catalog/skills/ux-design/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/ux-design/VALIDATION.json +12 -0
- package/catalog/skills/ux-design/skill.yaml +16 -0
- package/catalog/skills/vercel-optimize/SKILL.md +83 -0
- package/catalog/skills/vercel-optimize/VALIDATION.json +12 -0
- package/catalog/skills/vercel-optimize/scripts/collect-signals.mjs +131 -0
- package/catalog/skills/vercel-optimize/scripts/gate-investigations.mjs +142 -0
- package/catalog/skills/vercel-optimize/scripts/merge-signals.mjs +143 -0
- package/catalog/skills/vercel-optimize/scripts/scan-codebase.mjs +174 -0
- package/catalog/skills/vercel-optimize/skill.yaml +15 -0
- package/catalog/skills/web-accessibility/EXAMPLES.md +39 -0
- package/catalog/skills/web-accessibility/SKILL.md +151 -0
- package/catalog/skills/web-accessibility/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/web-accessibility/VALIDATION.json +12 -0
- package/catalog/skills/web-accessibility/skill.yaml +14 -0
- package/package.json +3 -2
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# CI/CD - Examples & GitHub Actions Configurations
|
|
2
|
+
|
|
3
|
+
## Example 1: Production Quality Gate Workflow
|
|
4
|
+
|
|
5
|
+
```yaml
|
|
6
|
+
# .github/workflows/ci.yml
|
|
7
|
+
name: CI Quality Gates
|
|
8
|
+
|
|
9
|
+
on:
|
|
10
|
+
pull_request:
|
|
11
|
+
branches: [main]
|
|
12
|
+
push:
|
|
13
|
+
branches: [main]
|
|
14
|
+
|
|
15
|
+
concurrency:
|
|
16
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
17
|
+
cancel-in-progress: true
|
|
18
|
+
|
|
19
|
+
permissions:
|
|
20
|
+
contents: read
|
|
21
|
+
|
|
22
|
+
jobs:
|
|
23
|
+
quality:
|
|
24
|
+
name: Lint, Types & Security
|
|
25
|
+
runs-on: ubuntu-latest
|
|
26
|
+
steps:
|
|
27
|
+
- name: Checkout Code
|
|
28
|
+
uses: actions/checkout@v4
|
|
29
|
+
|
|
30
|
+
- name: Setup Node.js
|
|
31
|
+
uses: actions/setup-node@v4
|
|
32
|
+
with:
|
|
33
|
+
node-version: '22'
|
|
34
|
+
cache: 'npm'
|
|
35
|
+
|
|
36
|
+
- name: Install Dependencies
|
|
37
|
+
run: npm ci
|
|
38
|
+
|
|
39
|
+
- name: Secret Scan
|
|
40
|
+
run: npm run check:secrets
|
|
41
|
+
|
|
42
|
+
- name: Linter & Format Check
|
|
43
|
+
run: npm run lint
|
|
44
|
+
|
|
45
|
+
- name: Type Check
|
|
46
|
+
run: npx tsc --noEmit
|
|
47
|
+
|
|
48
|
+
- name: Unit Tests with Coverage
|
|
49
|
+
run: npm test -- --coverage
|
|
50
|
+
|
|
51
|
+
- name: Build Verification
|
|
52
|
+
run: npm run build
|
|
53
|
+
|
|
54
|
+
- name: Dependency Audit
|
|
55
|
+
run: npm audit --audit-level=high
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Example 2: Polyglot Matrix Test Stage
|
|
61
|
+
|
|
62
|
+
```yaml
|
|
63
|
+
test-matrix:
|
|
64
|
+
name: Node Test Matrix
|
|
65
|
+
needs: quality
|
|
66
|
+
runs-on: ubuntu-latest
|
|
67
|
+
strategy:
|
|
68
|
+
fail-fast: false
|
|
69
|
+
matrix:
|
|
70
|
+
node-version: ['20', '22']
|
|
71
|
+
steps:
|
|
72
|
+
- uses: actions/checkout@v4
|
|
73
|
+
- uses: actions/setup-node@v4
|
|
74
|
+
with:
|
|
75
|
+
node-version: ${{ matrix.node-version }}
|
|
76
|
+
cache: 'npm'
|
|
77
|
+
- run: npm ci
|
|
78
|
+
- run: npm test
|
|
79
|
+
```
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ci-cd
|
|
3
|
+
description: Automates CI/CD pipeline setup. Enforces unskippable quality gates, shift-left static analysis, secret scanning, and hardened GitHub Actions workflows.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# CI/CD and Automation
|
|
7
|
+
|
|
8
|
+
Automate quality gates so no change reaches production without passing tests, lint, type checking, security scans, and build verification.
|
|
9
|
+
|
|
10
|
+
## Core Philosophy
|
|
11
|
+
|
|
12
|
+
- **Shift Left**: Catch problems as early in the delivery lifecycle as possible. A defect caught during static analysis or linting takes seconds to fix; the same defect discovered in production takes hours and damages reliability.
|
|
13
|
+
- **Faster is Safer**: Small, frequent, automated releases drastically lower blast radius and risk compared to infrequent bulk deployments.
|
|
14
|
+
- **Unskippable Gates Invariant**: Never disable a failing rule or skip a test suite just to make a pipeline green. Fix the root cause in the code.
|
|
15
|
+
|
|
16
|
+
## The Quality Gate Pipeline
|
|
17
|
+
|
|
18
|
+
Every Pull Request must successfully traverse these automated stages before merge approval:
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
Pull Request Opened
|
|
22
|
+
│
|
|
23
|
+
▼
|
|
24
|
+
1. Secret Scanning (prevent credential leaks before running untrusted steps)
|
|
25
|
+
│
|
|
26
|
+
▼
|
|
27
|
+
2. Lint & Formatting (eslint, prettier, markdownlint)
|
|
28
|
+
│
|
|
29
|
+
▼
|
|
30
|
+
3. Type Checking (tsc --noEmit, pyright, mypy)
|
|
31
|
+
│
|
|
32
|
+
▼
|
|
33
|
+
4. Unit Tests (vitest, jest, pytest with coverage thresholds)
|
|
34
|
+
│
|
|
35
|
+
▼
|
|
36
|
+
5. Production Build (bundling, tree-shaking, static generation)
|
|
37
|
+
│
|
|
38
|
+
▼
|
|
39
|
+
6. Integration Tests (API contracts, database migrations)
|
|
40
|
+
│
|
|
41
|
+
▼
|
|
42
|
+
7. Security Audit (npm audit, trivy, dependency vulnerability checks)
|
|
43
|
+
│
|
|
44
|
+
▼
|
|
45
|
+
8. Bundle Budget (bundle size checks against baseline thresholds)
|
|
46
|
+
│
|
|
47
|
+
▼
|
|
48
|
+
Merge Allowed
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Hardened Pipeline Standards
|
|
52
|
+
|
|
53
|
+
1. **Least-Privilege Token Permissions**:
|
|
54
|
+
Explicitly declare workflow and job permissions at the top of the workflow file. Default to read-only access:
|
|
55
|
+
```yaml
|
|
56
|
+
permissions:
|
|
57
|
+
contents: read
|
|
58
|
+
```
|
|
59
|
+
2. **Deterministic Dependency Installation**:
|
|
60
|
+
Always use frozen lockfiles (`npm ci` instead of `npm install`, `uv sync --frozen` instead of `pip install`).
|
|
61
|
+
3. **Concurrency Cancellation**:
|
|
62
|
+
Automatically cancel in-progress runs when a newer commit is pushed to the same Pull Request branch:
|
|
63
|
+
```yaml
|
|
64
|
+
concurrency:
|
|
65
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
66
|
+
cancel-in-progress: true
|
|
67
|
+
```
|
|
68
|
+
4. **Action Pinning**:
|
|
69
|
+
Reference trusted actions using verified release tags (e.g. `actions/checkout@v4`) or full commit SHAs.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# CI/CD - Troubleshooting & Common Edge Cases
|
|
2
|
+
|
|
3
|
+
## Common Diagnostic Scenarios
|
|
4
|
+
|
|
5
|
+
### 1. Flaky Integration Tests in CI Environments
|
|
6
|
+
|
|
7
|
+
- **Symptom**: Test suite randomly fails in GitHub Actions but always passes on developer machines.
|
|
8
|
+
- **Root Cause**: Race conditions, port collisions, unawaited background tasks, or timezone dependencies (`new Date().getHours()`) differing between UTC runners and local environments.
|
|
9
|
+
- **Fix Protocol**:
|
|
10
|
+
1. Fix runner timezones to UTC in CI setup steps (`TZ: 'UTC'`).
|
|
11
|
+
2. Eliminate hardcoded ports in integration tests; use ephemeral ports (`0`) or testcontainers.
|
|
12
|
+
3. Ensure all asynchronous operations and database transactions are explicitly awaited before asserting and tearing down.
|
|
13
|
+
4. Never use `retry` plugins to mask flaky tests; isolate the asynchronous race condition.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
### 2. GitHub Actions Token Permission Denied (`Resource not accessible by integration`)
|
|
18
|
+
|
|
19
|
+
- **Symptom**: CI workflow fails at the checkout, comment, or release stage with an authorization error.
|
|
20
|
+
- **Root Cause**: The repository enforces secure defaults with read-only tokens, but the workflow needs to write statuses, PR comments, or packages.
|
|
21
|
+
- **Fix Protocol**:
|
|
22
|
+
- Declare explicit, least-privilege permissions at the job level rather than granting global admin rights:
|
|
23
|
+
```yaml
|
|
24
|
+
jobs:
|
|
25
|
+
comment-pr:
|
|
26
|
+
runs-on: ubuntu-latest
|
|
27
|
+
permissions:
|
|
28
|
+
contents: read
|
|
29
|
+
pull-requests: write
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
### 3. Exceeded Runner Minutes & Slow CI Builds
|
|
35
|
+
|
|
36
|
+
- **Symptom**: Workflow takes > 15 minutes to run, exhausting GitHub Actions free-tier minutes.
|
|
37
|
+
- **Root Cause**: Running `npm install` without package manager caching, sequential execution of independent checks, and missing concurrency cancellation.
|
|
38
|
+
- **Fix Protocol**:
|
|
39
|
+
1. Use `actions/setup-node@v4` with `cache: 'npm'` to reuse cached node_modules across runs.
|
|
40
|
+
2. Split monolithic jobs into parallel jobs: run lint, type-check, and unit tests concurrently.
|
|
41
|
+
3. Add `concurrency` cancellation to cancel stale builds when a developer pushes new commits to an open PR.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
### 4. Bundle Size Budget Check Failures
|
|
46
|
+
|
|
47
|
+
- **Symptom**: PR fails on `bundlesize` check with `Bundle size exceeded by 4.2 KB`.
|
|
48
|
+
- **Root Cause**: An imported third-party library pulled in heavy un-treeshaken dependencies or large date/locale libraries.
|
|
49
|
+
- **Fix Protocol**:
|
|
50
|
+
1. Inspect the bundle visualizer or source map explorer.
|
|
51
|
+
2. Replace broad root imports (`import { map } from 'lodash'`) with direct submodule imports (`import map from 'lodash/map'`).
|
|
52
|
+
3. Dynamically import heavy UI widgets (modals, charts, rich text editors) using `React.lazy()` or `next/dynamic`.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"skill": "ci-cd",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"checks": [
|
|
5
|
+
"Shift-left quality gates pipeline implemented in order",
|
|
6
|
+
"Least-privilege token permissions declared (contents: read)",
|
|
7
|
+
"Deterministic dependency installation enforced with frozen lockfile",
|
|
8
|
+
"Concurrency cancellation configured for PR branch updates",
|
|
9
|
+
"Unskippable gates invariant enforced without disabling rules"
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
schemaVersion: 2
|
|
2
|
+
name: ci-cd
|
|
3
|
+
description: Shift-left CI/CD pipeline automation inspired by Addy Osmani. Enforces unskippable quality gates, least-privilege token permissions, and deterministic GitHub Actions workflows.
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
category: devops
|
|
6
|
+
type: instruction-only
|
|
7
|
+
requires:
|
|
8
|
+
- engineering-workflow
|
|
9
|
+
resources:
|
|
10
|
+
- EXAMPLES.md
|
|
11
|
+
- SKILL.md
|
|
12
|
+
- TROUBLESHOOTING.md
|
|
13
|
+
- VALIDATION.json
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Database Examples - Anti-patterns vs ContextOS Standard
|
|
2
|
+
|
|
3
|
+
## Example 1: Solving the N+1 Query Problem
|
|
4
|
+
|
|
5
|
+
### Anti-pattern: Anti-pattern (N+1 database queries in a loop)
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
// BAD: 1 query for users + N queries for posts!
|
|
9
|
+
const users = await prisma.user.findMany();
|
|
10
|
+
const usersWithPosts = [];
|
|
11
|
+
for (const user of users) {
|
|
12
|
+
const posts = await prisma.post.findMany({ where: { userId: user.id } }); // N queries!
|
|
13
|
+
usersWithPosts.push({ ...user, posts });
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Best practice: ContextOS Standard (Batch query or relational include)
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
// GOOD: 1 single optimized batch query
|
|
21
|
+
const usersWithPosts = await prisma.user.findMany({
|
|
22
|
+
where: { isActive: true },
|
|
23
|
+
select: {
|
|
24
|
+
id: true,
|
|
25
|
+
name: true,
|
|
26
|
+
email: true,
|
|
27
|
+
posts: {
|
|
28
|
+
where: { published: true },
|
|
29
|
+
select: { id: true, title: true, createdAt: true },
|
|
30
|
+
take: 5
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Example 2: Safe Atomic Transactions with Locking
|
|
39
|
+
|
|
40
|
+
### Anti-pattern: Anti-pattern (Unprotected read-modify-write race condition)
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
// BAD: race condition between reading balance and updating
|
|
44
|
+
const account = await prisma.account.findUnique({ where: { id } });
|
|
45
|
+
if (account.balance >= amount) {
|
|
46
|
+
await prisma.account.update({
|
|
47
|
+
where: { id },
|
|
48
|
+
data: { balance: account.balance - amount }
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Best practice: ContextOS Standard (Atomic conditional update in transaction)
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
// GOOD: atomic database transaction with invariant check
|
|
57
|
+
export async function deductBalance(accountId: string, amount: number) {
|
|
58
|
+
return await prisma.$transaction(async (tx) => {
|
|
59
|
+
const updated = await tx.account.updateMany({
|
|
60
|
+
where: {
|
|
61
|
+
id: accountId,
|
|
62
|
+
balance: { gte: amount }
|
|
63
|
+
},
|
|
64
|
+
data: {
|
|
65
|
+
balance: { decrement: amount }
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
if (updated.count === 0) {
|
|
70
|
+
throw new InsufficientFundsError(accountId);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
```
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: database
|
|
3
|
+
description: Database architecture, schema design, Prisma, Drizzle ORM, indexing strategies, migrations, and N+1 query resolution.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# database
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
Relational database design, query optimization, migration safety, connection pooling in serverless environments, and ORM usage across PostgreSQL, Prisma, and Drizzle.
|
|
11
|
+
|
|
12
|
+
## When to Use
|
|
13
|
+
|
|
14
|
+
Activate for tasks involving database schema design, migrations, indexing, relational models, ORM queries, transactions, or query performance tuning.
|
|
15
|
+
|
|
16
|
+
## Rules & Patterns
|
|
17
|
+
|
|
18
|
+
### Negative Constraints (What NOT to Do)
|
|
19
|
+
|
|
20
|
+
1. **NEVER do `SELECT *` in production**: Always select explicit columns required by the caller to minimize memory bandwidth and lock footprint.
|
|
21
|
+
2. **NEVER run destructive migrations without backward compatibility**: Always follow expand-and-contract (Phase 1: add new column as nullable; Phase 2: backfill; Phase 3: make non-nullable & remove old column).
|
|
22
|
+
3. **NEVER execute queries in loops (The N+1 Anti-Pattern)**: Always use batch loading (`inArray`, `DataLoader`, or relational `include` / `JOIN`).
|
|
23
|
+
4. **NEVER leave foreign keys without indexes**: In PostgreSQL/MySQL, child foreign key columns must always have an index to prevent table-level locking on cascade deletes.
|
|
24
|
+
5. **NEVER perform multi-entity writes without a database transaction**: Any operation touching multiple records must use `prisma.$transaction` or `db.transaction`.
|
|
25
|
+
6. **NEVER open unpooled database connections in Serverless / Edge functions**: Serverless scale-outs will instantly exhaust PostgreSQL's `max_connections`.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
### Zero-Downtime Migrations (Expand-and-Contract)
|
|
30
|
+
|
|
31
|
+
When modifying schemas with zero downtime:
|
|
32
|
+
|
|
33
|
+
1. **Phase 1 (Expand)**: Add the new column as `NULLABLE` (or with a default value). Deploy the application code that reads from old column and writes to both old and new.
|
|
34
|
+
2. **Phase 2 (Backfill)**: Run an asynchronous batch migration job in chunks (e.g. 1000 rows at a time) to populate data from old column to new column.
|
|
35
|
+
3. **Phase 3 (Contract)**: Update application code to read and write exclusively from the new column.
|
|
36
|
+
4. **Phase 4 (Cleanup)**: Once traffic is fully shifted, remove the old column and mark the new column as `NOT NULL` in a separate migration.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
### Serverless & Edge Connection Pooling
|
|
41
|
+
|
|
42
|
+
In serverless environments (AWS Lambda, Vercel Functions):
|
|
43
|
+
|
|
44
|
+
- Always connect via a connection pooler:
|
|
45
|
+
- **Prisma**: Use Prisma Accelerate or configure transaction mode connection URLs.
|
|
46
|
+
- **Drizzle / Node-Postgres**: Use `@neondatabase/serverless` or connect to PgBouncer pooler port (`6543`) with `max: 1` per serverless container.
|
|
47
|
+
- Set strict statement timeouts (e.g. `statement_timeout = '5000'`) to prevent hanging queries from exhausting pool capacity.
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
### Indexing & Performance Rules
|
|
52
|
+
|
|
53
|
+
- **B-Tree Indexes**: For high-cardinality filters (`status`, `user_id`, `created_at`).
|
|
54
|
+
- **Composite Indexes**: When querying multiple columns together (`WHERE organization_id = ? AND status = ?`), order columns in index by equality first, range second.
|
|
55
|
+
- **Partial Indexes**: For sparse boolean flags (`WHERE is_processed = false`).
|
|
56
|
+
- **Covering Indexes**: Include frequently selected columns (`INCLUDE (title, created_at)`) to enable index-only scans without table heap access.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Code Examples
|
|
61
|
+
|
|
62
|
+
### Zero-Downtime Column Rename (Drizzle ORM)
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
// Step 1 (Expand): Keep old column, add new column
|
|
66
|
+
export const users = pgTable('users', {
|
|
67
|
+
id: uuid('id').primaryKey().defaultRandom(),
|
|
68
|
+
fullName: varchar('full_name', { length: 255 }), // new column
|
|
69
|
+
name: varchar('name', { length: 255 }), // old column kept during transition
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// App write logic during transition:
|
|
73
|
+
await db.insert(users).values({
|
|
74
|
+
name: input.name,
|
|
75
|
+
fullName: input.name
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## Validation Checklist
|
|
82
|
+
|
|
83
|
+
- [ ] All database queries select explicit required columns (no `SELECT *`).
|
|
84
|
+
- [ ] Foreign keys have matching indexes on child tables.
|
|
85
|
+
- [ ] Multi-table writes wrapped in ACID transactions.
|
|
86
|
+
- [ ] No N+1 queries in loops.
|
|
87
|
+
- [ ] Schema migrations tested against expand-and-contract pattern.
|
|
88
|
+
- [ ] Serverless database connection string uses pooling proxy.
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Common Mistakes
|
|
93
|
+
|
|
94
|
+
- **Missing pagination limits**: Unbounded `findMany()` calls leading to Out-Of-Memory crashes under production volume.
|
|
95
|
+
- **Locking entire tables**: Adding `NOT NULL` columns with heavy compute defaults in PostgreSQL without concurrent index creation.
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Integration Notes
|
|
100
|
+
|
|
101
|
+
- Interacts with `system-design`, `ddd`, and `security` (multi-tenant tenantId scoping).
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Database Troubleshooting Guide
|
|
2
|
+
|
|
3
|
+
## Common Issues & Fixes
|
|
4
|
+
|
|
5
|
+
### 1. Connection Pool Exhaustion in Serverless / Edge
|
|
6
|
+
|
|
7
|
+
- **Cause**: Creating a new PrismaClient / DB connection instance on every serverless function invocation.
|
|
8
|
+
- **Fix**: Declare PrismaClient as a global singleton across warm lambdas, and enable PgBouncer or Prisma Accelerate.
|
|
9
|
+
|
|
10
|
+
### 2. Slow Queries on Large Tables
|
|
11
|
+
|
|
12
|
+
- **Cause**: Missing composite index on filtered and ordered columns.
|
|
13
|
+
- **Fix**: Run `EXPLAIN ANALYZE <query>` and add targeted indexes matching the WHERE and ORDER BY columns.
|
|
14
|
+
|
|
15
|
+
### 3. Database Deadlocks during Concurrent Transactions
|
|
16
|
+
|
|
17
|
+
- **Cause**: Different transactions updating resources in different orders.
|
|
18
|
+
- **Fix**: Always acquire locks and update entities in a deterministic alphabetical or ID-ordered sequence.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"skill": "database",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"checks": [
|
|
5
|
+
"No SELECT * in application queries",
|
|
6
|
+
"All foreign keys indexed",
|
|
7
|
+
"Multi-table writes enclosed in database transactions",
|
|
8
|
+
"No N+1 queries in loops",
|
|
9
|
+
"Safe expand-and-contract migration strategy"
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
schemaVersion: 2
|
|
2
|
+
name: database
|
|
3
|
+
description: Database architecture, schema design, Prisma, Drizzle ORM, indexing strategies, migrations, and N+1 query resolution.
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
category: backend
|
|
6
|
+
type: instruction-only
|
|
7
|
+
requires:
|
|
8
|
+
- system-design
|
|
9
|
+
- typescript
|
|
10
|
+
resources:
|
|
11
|
+
- EXAMPLES.md
|
|
12
|
+
- SKILL.md
|
|
13
|
+
- TROUBLESHOOTING.md
|
|
14
|
+
- VALIDATION.json
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# ddd Examples - Anti-patterns vs ContextOS Standard
|
|
2
|
+
|
|
3
|
+
## Example 1: Domain Entities vs Anemic Models
|
|
4
|
+
|
|
5
|
+
### Anti-pattern: Anemic Domain Model with Leaky Setters
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
// BAD: Zero business invariants; any caller can corrupt state
|
|
9
|
+
class BankAccount {
|
|
10
|
+
public balance: number = 0;
|
|
11
|
+
public isFrozen: boolean = false;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Logic leaked into controller or service
|
|
15
|
+
account.balance -= 500; // Overdraft not checked!
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### Best practice: ContextOS Standard (Rich Domain Model with Guarded Invariants)
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
// GOOD: Invariants strictly enforced inside Aggregate Root
|
|
22
|
+
class BankAccount {
|
|
23
|
+
private _balance: number;
|
|
24
|
+
private _isFrozen: boolean;
|
|
25
|
+
|
|
26
|
+
constructor(id: string, initialDeposit: Money) {
|
|
27
|
+
this._balance = initialDeposit.amount;
|
|
28
|
+
this._isFrozen = false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public withdraw(amount: Money): void {
|
|
32
|
+
if (this._isFrozen) {
|
|
33
|
+
throw new AccountFrozenException('Cannot withdraw from a frozen account');
|
|
34
|
+
}
|
|
35
|
+
if (this._balance < amount.amount) {
|
|
36
|
+
throw new InsufficientFundsException('Insufficient funds for withdrawal');
|
|
37
|
+
}
|
|
38
|
+
this._balance -= amount.amount;
|
|
39
|
+
this.addDomainEvent(new MoneyWithdrawnEvent(this.id, amount));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|