@juho0719/cckit 0.1.1
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/assets/agents/architect.md +211 -0
- package/assets/agents/build-error-resolver.md +114 -0
- package/assets/agents/ccwin-code-reviewer.md +224 -0
- package/assets/agents/database-reviewer.md +91 -0
- package/assets/agents/doc-updater.md +107 -0
- package/assets/agents/e2e-runner.md +107 -0
- package/assets/agents/planner.md +212 -0
- package/assets/agents/python-reviewer.md +98 -0
- package/assets/agents/refactor-cleaner.md +85 -0
- package/assets/agents/security-reviewer.md +108 -0
- package/assets/agents/superpower-code-reviewer.md +48 -0
- package/assets/agents/tdd-guide.md +80 -0
- package/assets/commands/build-fix.md +62 -0
- package/assets/commands/checkpoint.md +74 -0
- package/assets/commands/code-review.md +40 -0
- package/assets/commands/e2e.md +362 -0
- package/assets/commands/eval.md +120 -0
- package/assets/commands/orchestrate.md +172 -0
- package/assets/commands/plan.md +113 -0
- package/assets/commands/python-review.md +297 -0
- package/assets/commands/refactor-clean.md +80 -0
- package/assets/commands/sessions.md +305 -0
- package/assets/commands/tdd.md +326 -0
- package/assets/commands/test-coverage.md +69 -0
- package/assets/commands/update-codemaps.md +72 -0
- package/assets/commands/update-docs.md +84 -0
- package/assets/commands/verify.md +59 -0
- package/assets/hooks/post-edit-format.js +49 -0
- package/assets/hooks/post-edit-typecheck.js +96 -0
- package/assets/mcps/mcp-servers.json +92 -0
- package/assets/rules/common/agents.md +49 -0
- package/assets/rules/common/coding-style.md +48 -0
- package/assets/rules/common/git-workflow.md +45 -0
- package/assets/rules/common/hooks.md +30 -0
- package/assets/rules/common/patterns.md +31 -0
- package/assets/rules/common/performance.md +55 -0
- package/assets/rules/common/security.md +29 -0
- package/assets/rules/common/testing.md +29 -0
- package/assets/rules/python/coding-style.md +42 -0
- package/assets/rules/python/hooks.md +19 -0
- package/assets/rules/python/patterns.md +39 -0
- package/assets/rules/python/security.md +30 -0
- package/assets/rules/python/testing.md +38 -0
- package/assets/rules/typescript/coding-style.md +18 -0
- package/assets/rules/typescript/hooks.md +19 -0
- package/assets/rules/typescript/patterns.md +39 -0
- package/assets/rules/typescript/security.md +30 -0
- package/assets/rules/typescript/testing.md +38 -0
- package/assets/skills/api-design/SKILL.md +522 -0
- package/assets/skills/backend-patterns/SKILL.md +597 -0
- package/assets/skills/brainstorming/SKILL.md +96 -0
- package/assets/skills/coding-standards/SKILL.md +529 -0
- package/assets/skills/database-migrations/SKILL.md +334 -0
- package/assets/skills/deployment-patterns/SKILL.md +426 -0
- package/assets/skills/dispatching-parallel-agents/SKILL.md +180 -0
- package/assets/skills/docker-patterns/SKILL.md +363 -0
- package/assets/skills/e2e-testing/SKILL.md +325 -0
- package/assets/skills/eval-harness/SKILL.md +235 -0
- package/assets/skills/executing-plans/SKILL.md +84 -0
- package/assets/skills/finishing-a-development-branch/SKILL.md +200 -0
- package/assets/skills/frontend-patterns/SKILL.md +641 -0
- package/assets/skills/iterative-retrieval/SKILL.md +210 -0
- package/assets/skills/postgres-patterns/SKILL.md +145 -0
- package/assets/skills/python-patterns/SKILL.md +749 -0
- package/assets/skills/python-testing/SKILL.md +815 -0
- package/assets/skills/receiving-code-review/SKILL.md +213 -0
- package/assets/skills/requesting-code-review/SKILL.md +105 -0
- package/assets/skills/requesting-code-review/code-reviewer-template.md +146 -0
- package/assets/skills/subagent-driven-development/SKILL.md +242 -0
- package/assets/skills/subagent-driven-development/code-quality-reviewer-prompt.md +20 -0
- package/assets/skills/subagent-driven-development/implementer-prompt.md +78 -0
- package/assets/skills/subagent-driven-development/spec-reviewer-prompt.md +61 -0
- package/assets/skills/systematic-debugging/CREATION-LOG.md +114 -0
- package/assets/skills/systematic-debugging/SKILL.md +296 -0
- package/assets/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
- package/assets/skills/systematic-debugging/condition-based-waiting.md +115 -0
- package/assets/skills/systematic-debugging/defense-in-depth.md +122 -0
- package/assets/skills/systematic-debugging/root-cause-tracing.md +169 -0
- package/assets/skills/systematic-debugging/scripts/find-polluter.sh +63 -0
- package/assets/skills/systematic-debugging/test-academic.md +14 -0
- package/assets/skills/systematic-debugging/test-pressure-1.md +58 -0
- package/assets/skills/systematic-debugging/test-pressure-2.md +68 -0
- package/assets/skills/systematic-debugging/test-pressure-3.md +69 -0
- package/assets/skills/tdd-workflow/SKILL.md +409 -0
- package/assets/skills/test-driven-development/SKILL.md +371 -0
- package/assets/skills/test-driven-development/testing-anti-patterns.md +299 -0
- package/assets/skills/using-git-worktrees/SKILL.md +218 -0
- package/assets/skills/verification-before-completion/SKILL.md +139 -0
- package/assets/skills/verification-loop/SKILL.md +125 -0
- package/assets/skills/writing-plans/SKILL.md +116 -0
- package/dist/agents-AEKT67A6.js +9 -0
- package/dist/chunk-3GUKEMND.js +28 -0
- package/dist/chunk-3UNN3IBE.js +54 -0
- package/dist/chunk-3Y26YU4R.js +27 -0
- package/dist/chunk-5XOKKPAA.js +21 -0
- package/dist/chunk-6B46AIFM.js +136 -0
- package/dist/chunk-EYY2IZ7N.js +27 -0
- package/dist/chunk-K25UZZVG.js +17 -0
- package/dist/chunk-KEENFBLL.js +24 -0
- package/dist/chunk-RMUKD7CW.js +44 -0
- package/dist/chunk-W63UKEIT.js +50 -0
- package/dist/cli-VZRGF733.js +238 -0
- package/dist/commands-P5LILVZ5.js +9 -0
- package/dist/hooks-IIG2XK4I.js +9 -0
- package/dist/index.js +131 -0
- package/dist/mcps-67Q7TBGW.js +6 -0
- package/dist/paths-FT6KBIRD.js +10 -0
- package/dist/registry-EGXWYWWK.js +17 -0
- package/dist/rules-2CPBVNNJ.js +7 -0
- package/dist/skills-ULMW3UCM.js +8 -0
- package/package.json +36 -0
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: deployment-patterns
|
|
3
|
+
description: Deployment workflows, CI/CD pipeline patterns, Docker containerization, health checks, rollback strategies, and production readiness checklists for web applications.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Deployment Patterns
|
|
7
|
+
|
|
8
|
+
Production deployment workflows and CI/CD best practices.
|
|
9
|
+
|
|
10
|
+
## When to Activate
|
|
11
|
+
|
|
12
|
+
- Setting up CI/CD pipelines
|
|
13
|
+
- Dockerizing an application
|
|
14
|
+
- Planning deployment strategy (blue-green, canary, rolling)
|
|
15
|
+
- Implementing health checks and readiness probes
|
|
16
|
+
- Preparing for a production release
|
|
17
|
+
- Configuring environment-specific settings
|
|
18
|
+
|
|
19
|
+
## Deployment Strategies
|
|
20
|
+
|
|
21
|
+
### Rolling Deployment (Default)
|
|
22
|
+
|
|
23
|
+
Replace instances gradually — old and new versions run simultaneously during rollout.
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
Instance 1: v1 → v2 (update first)
|
|
27
|
+
Instance 2: v1 (still running v1)
|
|
28
|
+
Instance 3: v1 (still running v1)
|
|
29
|
+
|
|
30
|
+
Instance 1: v2
|
|
31
|
+
Instance 2: v1 → v2 (update second)
|
|
32
|
+
Instance 3: v1
|
|
33
|
+
|
|
34
|
+
Instance 1: v2
|
|
35
|
+
Instance 2: v2
|
|
36
|
+
Instance 3: v1 → v2 (update last)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**Pros:** Zero downtime, gradual rollout
|
|
40
|
+
**Cons:** Two versions run simultaneously — requires backward-compatible changes
|
|
41
|
+
**Use when:** Standard deployments, backward-compatible changes
|
|
42
|
+
|
|
43
|
+
### Blue-Green Deployment
|
|
44
|
+
|
|
45
|
+
Run two identical environments. Switch traffic atomically.
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
Blue (v1) ← traffic
|
|
49
|
+
Green (v2) idle, running new version
|
|
50
|
+
|
|
51
|
+
# After verification:
|
|
52
|
+
Blue (v1) idle (becomes standby)
|
|
53
|
+
Green (v2) ← traffic
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Pros:** Instant rollback (switch back to blue), clean cutover
|
|
57
|
+
**Cons:** Requires 2x infrastructure during deployment
|
|
58
|
+
**Use when:** Critical services, zero-tolerance for issues
|
|
59
|
+
|
|
60
|
+
### Canary Deployment
|
|
61
|
+
|
|
62
|
+
Route a small percentage of traffic to the new version first.
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
v1: 95% of traffic
|
|
66
|
+
v2: 5% of traffic (canary)
|
|
67
|
+
|
|
68
|
+
# If metrics look good:
|
|
69
|
+
v1: 50% of traffic
|
|
70
|
+
v2: 50% of traffic
|
|
71
|
+
|
|
72
|
+
# Final:
|
|
73
|
+
v2: 100% of traffic
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**Pros:** Catches issues with real traffic before full rollout
|
|
77
|
+
**Cons:** Requires traffic splitting infrastructure, monitoring
|
|
78
|
+
**Use when:** High-traffic services, risky changes, feature flags
|
|
79
|
+
|
|
80
|
+
## Docker
|
|
81
|
+
|
|
82
|
+
### Multi-Stage Dockerfile (Node.js)
|
|
83
|
+
|
|
84
|
+
```dockerfile
|
|
85
|
+
# Stage 1: Install dependencies
|
|
86
|
+
FROM node:22-alpine AS deps
|
|
87
|
+
WORKDIR /app
|
|
88
|
+
COPY package.json package-lock.json ./
|
|
89
|
+
RUN npm ci --production=false
|
|
90
|
+
|
|
91
|
+
# Stage 2: Build
|
|
92
|
+
FROM node:22-alpine AS builder
|
|
93
|
+
WORKDIR /app
|
|
94
|
+
COPY --from=deps /app/node_modules ./node_modules
|
|
95
|
+
COPY . .
|
|
96
|
+
RUN npm run build
|
|
97
|
+
RUN npm prune --production
|
|
98
|
+
|
|
99
|
+
# Stage 3: Production image
|
|
100
|
+
FROM node:22-alpine AS runner
|
|
101
|
+
WORKDIR /app
|
|
102
|
+
|
|
103
|
+
RUN addgroup -g 1001 -S appgroup && adduser -S appuser -u 1001
|
|
104
|
+
USER appuser
|
|
105
|
+
|
|
106
|
+
COPY --from=builder --chown=appuser:appgroup /app/node_modules ./node_modules
|
|
107
|
+
COPY --from=builder --chown=appuser:appgroup /app/dist ./dist
|
|
108
|
+
COPY --from=builder --chown=appuser:appgroup /app/package.json ./
|
|
109
|
+
|
|
110
|
+
ENV NODE_ENV=production
|
|
111
|
+
EXPOSE 3000
|
|
112
|
+
|
|
113
|
+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
114
|
+
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1
|
|
115
|
+
|
|
116
|
+
CMD ["node", "dist/server.js"]
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Multi-Stage Dockerfile (Go)
|
|
120
|
+
|
|
121
|
+
```dockerfile
|
|
122
|
+
FROM golang:1.22-alpine AS builder
|
|
123
|
+
WORKDIR /app
|
|
124
|
+
COPY go.mod go.sum ./
|
|
125
|
+
RUN go mod download
|
|
126
|
+
COPY . .
|
|
127
|
+
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /server ./cmd/server
|
|
128
|
+
|
|
129
|
+
FROM alpine:3.19 AS runner
|
|
130
|
+
RUN apk --no-cache add ca-certificates
|
|
131
|
+
RUN adduser -D -u 1001 appuser
|
|
132
|
+
USER appuser
|
|
133
|
+
|
|
134
|
+
COPY --from=builder /server /server
|
|
135
|
+
|
|
136
|
+
EXPOSE 8080
|
|
137
|
+
HEALTHCHECK --interval=30s --timeout=3s CMD wget -qO- http://localhost:8080/health || exit 1
|
|
138
|
+
CMD ["/server"]
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Multi-Stage Dockerfile (Python/Django)
|
|
142
|
+
|
|
143
|
+
```dockerfile
|
|
144
|
+
FROM python:3.12-slim AS builder
|
|
145
|
+
WORKDIR /app
|
|
146
|
+
RUN pip install --no-cache-dir uv
|
|
147
|
+
COPY requirements.txt .
|
|
148
|
+
RUN uv pip install --system --no-cache -r requirements.txt
|
|
149
|
+
|
|
150
|
+
FROM python:3.12-slim AS runner
|
|
151
|
+
WORKDIR /app
|
|
152
|
+
|
|
153
|
+
RUN useradd -r -u 1001 appuser
|
|
154
|
+
USER appuser
|
|
155
|
+
|
|
156
|
+
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
|
|
157
|
+
COPY --from=builder /usr/local/bin /usr/local/bin
|
|
158
|
+
COPY . .
|
|
159
|
+
|
|
160
|
+
ENV PYTHONUNBUFFERED=1
|
|
161
|
+
EXPOSE 8000
|
|
162
|
+
|
|
163
|
+
HEALTHCHECK --interval=30s --timeout=3s CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health/')" || exit 1
|
|
164
|
+
CMD ["gunicorn", "config.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "4"]
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Docker Best Practices
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
# GOOD practices
|
|
171
|
+
- Use specific version tags (node:22-alpine, not node:latest)
|
|
172
|
+
- Multi-stage builds to minimize image size
|
|
173
|
+
- Run as non-root user
|
|
174
|
+
- Copy dependency files first (layer caching)
|
|
175
|
+
- Use .dockerignore to exclude node_modules, .git, tests
|
|
176
|
+
- Add HEALTHCHECK instruction
|
|
177
|
+
- Set resource limits in docker-compose or k8s
|
|
178
|
+
|
|
179
|
+
# BAD practices
|
|
180
|
+
- Running as root
|
|
181
|
+
- Using :latest tags
|
|
182
|
+
- Copying entire repo in one COPY layer
|
|
183
|
+
- Installing dev dependencies in production image
|
|
184
|
+
- Storing secrets in image (use env vars or secrets manager)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## CI/CD Pipeline
|
|
188
|
+
|
|
189
|
+
### GitHub Actions (Standard Pipeline)
|
|
190
|
+
|
|
191
|
+
```yaml
|
|
192
|
+
name: CI/CD
|
|
193
|
+
|
|
194
|
+
on:
|
|
195
|
+
push:
|
|
196
|
+
branches: [main]
|
|
197
|
+
pull_request:
|
|
198
|
+
branches: [main]
|
|
199
|
+
|
|
200
|
+
jobs:
|
|
201
|
+
test:
|
|
202
|
+
runs-on: ubuntu-latest
|
|
203
|
+
steps:
|
|
204
|
+
- uses: actions/checkout@v4
|
|
205
|
+
- uses: actions/setup-node@v4
|
|
206
|
+
with:
|
|
207
|
+
node-version: 22
|
|
208
|
+
cache: npm
|
|
209
|
+
- run: npm ci
|
|
210
|
+
- run: npm run lint
|
|
211
|
+
- run: npm run typecheck
|
|
212
|
+
- run: npm test -- --coverage
|
|
213
|
+
- uses: actions/upload-artifact@v4
|
|
214
|
+
if: always()
|
|
215
|
+
with:
|
|
216
|
+
name: coverage
|
|
217
|
+
path: coverage/
|
|
218
|
+
|
|
219
|
+
build:
|
|
220
|
+
needs: test
|
|
221
|
+
runs-on: ubuntu-latest
|
|
222
|
+
if: github.ref == 'refs/heads/main'
|
|
223
|
+
steps:
|
|
224
|
+
- uses: actions/checkout@v4
|
|
225
|
+
- uses: docker/setup-buildx-action@v3
|
|
226
|
+
- uses: docker/login-action@v3
|
|
227
|
+
with:
|
|
228
|
+
registry: ghcr.io
|
|
229
|
+
username: ${{ github.actor }}
|
|
230
|
+
password: ${{ secrets.GITHUB_TOKEN }}
|
|
231
|
+
- uses: docker/build-push-action@v5
|
|
232
|
+
with:
|
|
233
|
+
push: true
|
|
234
|
+
tags: ghcr.io/${{ github.repository }}:${{ github.sha }}
|
|
235
|
+
cache-from: type=gha
|
|
236
|
+
cache-to: type=gha,mode=max
|
|
237
|
+
|
|
238
|
+
deploy:
|
|
239
|
+
needs: build
|
|
240
|
+
runs-on: ubuntu-latest
|
|
241
|
+
if: github.ref == 'refs/heads/main'
|
|
242
|
+
environment: production
|
|
243
|
+
steps:
|
|
244
|
+
- name: Deploy to production
|
|
245
|
+
run: |
|
|
246
|
+
# Platform-specific deployment command
|
|
247
|
+
# Railway: railway up
|
|
248
|
+
# Vercel: vercel --prod
|
|
249
|
+
# K8s: kubectl set image deployment/app app=ghcr.io/${{ github.repository }}:${{ github.sha }}
|
|
250
|
+
echo "Deploying ${{ github.sha }}"
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Pipeline Stages
|
|
254
|
+
|
|
255
|
+
```
|
|
256
|
+
PR opened:
|
|
257
|
+
lint → typecheck → unit tests → integration tests → preview deploy
|
|
258
|
+
|
|
259
|
+
Merged to main:
|
|
260
|
+
lint → typecheck → unit tests → integration tests → build image → deploy staging → smoke tests → deploy production
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## Health Checks
|
|
264
|
+
|
|
265
|
+
### Health Check Endpoint
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
// Simple health check
|
|
269
|
+
app.get("/health", (req, res) => {
|
|
270
|
+
res.status(200).json({ status: "ok" });
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
// Detailed health check (for internal monitoring)
|
|
274
|
+
app.get("/health/detailed", async (req, res) => {
|
|
275
|
+
const checks = {
|
|
276
|
+
database: await checkDatabase(),
|
|
277
|
+
redis: await checkRedis(),
|
|
278
|
+
externalApi: await checkExternalApi(),
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
const allHealthy = Object.values(checks).every(c => c.status === "ok");
|
|
282
|
+
|
|
283
|
+
res.status(allHealthy ? 200 : 503).json({
|
|
284
|
+
status: allHealthy ? "ok" : "degraded",
|
|
285
|
+
timestamp: new Date().toISOString(),
|
|
286
|
+
version: process.env.APP_VERSION || "unknown",
|
|
287
|
+
uptime: process.uptime(),
|
|
288
|
+
checks,
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
async function checkDatabase(): Promise<HealthCheck> {
|
|
293
|
+
try {
|
|
294
|
+
await db.query("SELECT 1");
|
|
295
|
+
return { status: "ok", latency_ms: 2 };
|
|
296
|
+
} catch (err) {
|
|
297
|
+
return { status: "error", message: "Database unreachable" };
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### Kubernetes Probes
|
|
303
|
+
|
|
304
|
+
```yaml
|
|
305
|
+
livenessProbe:
|
|
306
|
+
httpGet:
|
|
307
|
+
path: /health
|
|
308
|
+
port: 3000
|
|
309
|
+
initialDelaySeconds: 10
|
|
310
|
+
periodSeconds: 30
|
|
311
|
+
failureThreshold: 3
|
|
312
|
+
|
|
313
|
+
readinessProbe:
|
|
314
|
+
httpGet:
|
|
315
|
+
path: /health
|
|
316
|
+
port: 3000
|
|
317
|
+
initialDelaySeconds: 5
|
|
318
|
+
periodSeconds: 10
|
|
319
|
+
failureThreshold: 2
|
|
320
|
+
|
|
321
|
+
startupProbe:
|
|
322
|
+
httpGet:
|
|
323
|
+
path: /health
|
|
324
|
+
port: 3000
|
|
325
|
+
initialDelaySeconds: 0
|
|
326
|
+
periodSeconds: 5
|
|
327
|
+
failureThreshold: 30 # 30 * 5s = 150s max startup time
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## Environment Configuration
|
|
331
|
+
|
|
332
|
+
### Twelve-Factor App Pattern
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
# All config via environment variables — never in code
|
|
336
|
+
DATABASE_URL=postgres://user:pass@host:5432/db
|
|
337
|
+
REDIS_URL=redis://host:6379/0
|
|
338
|
+
API_KEY=${API_KEY} # injected by secrets manager
|
|
339
|
+
LOG_LEVEL=info
|
|
340
|
+
PORT=3000
|
|
341
|
+
|
|
342
|
+
# Environment-specific behavior
|
|
343
|
+
NODE_ENV=production # or staging, development
|
|
344
|
+
APP_ENV=production # explicit app environment
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### Configuration Validation
|
|
348
|
+
|
|
349
|
+
```typescript
|
|
350
|
+
import { z } from "zod";
|
|
351
|
+
|
|
352
|
+
const envSchema = z.object({
|
|
353
|
+
NODE_ENV: z.enum(["development", "staging", "production"]),
|
|
354
|
+
PORT: z.coerce.number().default(3000),
|
|
355
|
+
DATABASE_URL: z.string().url(),
|
|
356
|
+
REDIS_URL: z.string().url(),
|
|
357
|
+
JWT_SECRET: z.string().min(32),
|
|
358
|
+
LOG_LEVEL: z.enum(["debug", "info", "warn", "error"]).default("info"),
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
// Validate at startup — fail fast if config is wrong
|
|
362
|
+
export const env = envSchema.parse(process.env);
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
## Rollback Strategy
|
|
366
|
+
|
|
367
|
+
### Instant Rollback
|
|
368
|
+
|
|
369
|
+
```bash
|
|
370
|
+
# Docker/Kubernetes: point to previous image
|
|
371
|
+
kubectl rollout undo deployment/app
|
|
372
|
+
|
|
373
|
+
# Vercel: promote previous deployment
|
|
374
|
+
vercel rollback
|
|
375
|
+
|
|
376
|
+
# Railway: redeploy previous commit
|
|
377
|
+
railway up --commit <previous-sha>
|
|
378
|
+
|
|
379
|
+
# Database: rollback migration (if reversible)
|
|
380
|
+
npx prisma migrate resolve --rolled-back <migration-name>
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
### Rollback Checklist
|
|
384
|
+
|
|
385
|
+
- [ ] Previous image/artifact is available and tagged
|
|
386
|
+
- [ ] Database migrations are backward-compatible (no destructive changes)
|
|
387
|
+
- [ ] Feature flags can disable new features without deploy
|
|
388
|
+
- [ ] Monitoring alerts configured for error rate spikes
|
|
389
|
+
- [ ] Rollback tested in staging before production release
|
|
390
|
+
|
|
391
|
+
## Production Readiness Checklist
|
|
392
|
+
|
|
393
|
+
Before any production deployment:
|
|
394
|
+
|
|
395
|
+
### Application
|
|
396
|
+
- [ ] All tests pass (unit, integration, E2E)
|
|
397
|
+
- [ ] No hardcoded secrets in code or config files
|
|
398
|
+
- [ ] Error handling covers all edge cases
|
|
399
|
+
- [ ] Logging is structured (JSON) and does not contain PII
|
|
400
|
+
- [ ] Health check endpoint returns meaningful status
|
|
401
|
+
|
|
402
|
+
### Infrastructure
|
|
403
|
+
- [ ] Docker image builds reproducibly (pinned versions)
|
|
404
|
+
- [ ] Environment variables documented and validated at startup
|
|
405
|
+
- [ ] Resource limits set (CPU, memory)
|
|
406
|
+
- [ ] Horizontal scaling configured (min/max instances)
|
|
407
|
+
- [ ] SSL/TLS enabled on all endpoints
|
|
408
|
+
|
|
409
|
+
### Monitoring
|
|
410
|
+
- [ ] Application metrics exported (request rate, latency, errors)
|
|
411
|
+
- [ ] Alerts configured for error rate > threshold
|
|
412
|
+
- [ ] Log aggregation set up (structured logs, searchable)
|
|
413
|
+
- [ ] Uptime monitoring on health endpoint
|
|
414
|
+
|
|
415
|
+
### Security
|
|
416
|
+
- [ ] Dependencies scanned for CVEs
|
|
417
|
+
- [ ] CORS configured for allowed origins only
|
|
418
|
+
- [ ] Rate limiting enabled on public endpoints
|
|
419
|
+
- [ ] Authentication and authorization verified
|
|
420
|
+
- [ ] Security headers set (CSP, HSTS, X-Frame-Options)
|
|
421
|
+
|
|
422
|
+
### Operations
|
|
423
|
+
- [ ] Rollback plan documented and tested
|
|
424
|
+
- [ ] Database migration tested against production-sized data
|
|
425
|
+
- [ ] Runbook for common failure scenarios
|
|
426
|
+
- [ ] On-call rotation and escalation path defined
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: dispatching-parallel-agents
|
|
3
|
+
description: Use when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Dispatching Parallel Agents
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
When you have multiple unrelated failures (different test files, different subsystems, different bugs), investigating them sequentially wastes time. Each investigation is independent and can happen in parallel.
|
|
11
|
+
|
|
12
|
+
**Core principle:** Dispatch one agent per independent problem domain. Let them work concurrently.
|
|
13
|
+
|
|
14
|
+
## When to Use
|
|
15
|
+
|
|
16
|
+
```dot
|
|
17
|
+
digraph when_to_use {
|
|
18
|
+
"Multiple failures?" [shape=diamond];
|
|
19
|
+
"Are they independent?" [shape=diamond];
|
|
20
|
+
"Single agent investigates all" [shape=box];
|
|
21
|
+
"One agent per problem domain" [shape=box];
|
|
22
|
+
"Can they work in parallel?" [shape=diamond];
|
|
23
|
+
"Sequential agents" [shape=box];
|
|
24
|
+
"Parallel dispatch" [shape=box];
|
|
25
|
+
|
|
26
|
+
"Multiple failures?" -> "Are they independent?" [label="yes"];
|
|
27
|
+
"Are they independent?" -> "Single agent investigates all" [label="no - related"];
|
|
28
|
+
"Are they independent?" -> "Can they work in parallel?" [label="yes"];
|
|
29
|
+
"Can they work in parallel?" -> "Parallel dispatch" [label="yes"];
|
|
30
|
+
"Can they work in parallel?" -> "Sequential agents" [label="no - shared state"];
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Use when:**
|
|
35
|
+
- 3+ test files failing with different root causes
|
|
36
|
+
- Multiple subsystems broken independently
|
|
37
|
+
- Each problem can be understood without context from others
|
|
38
|
+
- No shared state between investigations
|
|
39
|
+
|
|
40
|
+
**Don't use when:**
|
|
41
|
+
- Failures are related (fix one might fix others)
|
|
42
|
+
- Need to understand full system state
|
|
43
|
+
- Agents would interfere with each other
|
|
44
|
+
|
|
45
|
+
## The Pattern
|
|
46
|
+
|
|
47
|
+
### 1. Identify Independent Domains
|
|
48
|
+
|
|
49
|
+
Group failures by what's broken:
|
|
50
|
+
- File A tests: Tool approval flow
|
|
51
|
+
- File B tests: Batch completion behavior
|
|
52
|
+
- File C tests: Abort functionality
|
|
53
|
+
|
|
54
|
+
Each domain is independent - fixing tool approval doesn't affect abort tests.
|
|
55
|
+
|
|
56
|
+
### 2. Create Focused Agent Tasks
|
|
57
|
+
|
|
58
|
+
Each agent gets:
|
|
59
|
+
- **Specific scope:** One test file or subsystem
|
|
60
|
+
- **Clear goal:** Make these tests pass
|
|
61
|
+
- **Constraints:** Don't change other code
|
|
62
|
+
- **Expected output:** Summary of what you found and fixed
|
|
63
|
+
|
|
64
|
+
### 3. Dispatch in Parallel
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
// In Claude Code / AI environment
|
|
68
|
+
Task("Fix agent-tool-abort.test.ts failures")
|
|
69
|
+
Task("Fix batch-completion-behavior.test.ts failures")
|
|
70
|
+
Task("Fix tool-approval-race-conditions.test.ts failures")
|
|
71
|
+
// All three run concurrently
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 4. Review and Integrate
|
|
75
|
+
|
|
76
|
+
When agents return:
|
|
77
|
+
- Read each summary
|
|
78
|
+
- Verify fixes don't conflict
|
|
79
|
+
- Run full test suite
|
|
80
|
+
- Integrate all changes
|
|
81
|
+
|
|
82
|
+
## Agent Prompt Structure
|
|
83
|
+
|
|
84
|
+
Good agent prompts are:
|
|
85
|
+
1. **Focused** - One clear problem domain
|
|
86
|
+
2. **Self-contained** - All context needed to understand the problem
|
|
87
|
+
3. **Specific about output** - What should the agent return?
|
|
88
|
+
|
|
89
|
+
```markdown
|
|
90
|
+
Fix the 3 failing tests in src/agents/agent-tool-abort.test.ts:
|
|
91
|
+
|
|
92
|
+
1. "should abort tool with partial output capture" - expects 'interrupted at' in message
|
|
93
|
+
2. "should handle mixed completed and aborted tools" - fast tool aborted instead of completed
|
|
94
|
+
3. "should properly track pendingToolCount" - expects 3 results but gets 0
|
|
95
|
+
|
|
96
|
+
These are timing/race condition issues. Your task:
|
|
97
|
+
|
|
98
|
+
1. Read the test file and understand what each test verifies
|
|
99
|
+
2. Identify root cause - timing issues or actual bugs?
|
|
100
|
+
3. Fix by:
|
|
101
|
+
- Replacing arbitrary timeouts with event-based waiting
|
|
102
|
+
- Fixing bugs in abort implementation if found
|
|
103
|
+
- Adjusting test expectations if testing changed behavior
|
|
104
|
+
|
|
105
|
+
Do NOT just increase timeouts - find the real issue.
|
|
106
|
+
|
|
107
|
+
Return: Summary of what you found and what you fixed.
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Common Mistakes
|
|
111
|
+
|
|
112
|
+
**❌ Too broad:** "Fix all the tests" - agent gets lost
|
|
113
|
+
**✅ Specific:** "Fix agent-tool-abort.test.ts" - focused scope
|
|
114
|
+
|
|
115
|
+
**❌ No context:** "Fix the race condition" - agent doesn't know where
|
|
116
|
+
**✅ Context:** Paste the error messages and test names
|
|
117
|
+
|
|
118
|
+
**❌ No constraints:** Agent might refactor everything
|
|
119
|
+
**✅ Constraints:** "Do NOT change production code" or "Fix tests only"
|
|
120
|
+
|
|
121
|
+
**❌ Vague output:** "Fix it" - you don't know what changed
|
|
122
|
+
**✅ Specific:** "Return summary of root cause and changes"
|
|
123
|
+
|
|
124
|
+
## When NOT to Use
|
|
125
|
+
|
|
126
|
+
**Related failures:** Fixing one might fix others - investigate together first
|
|
127
|
+
**Need full context:** Understanding requires seeing entire system
|
|
128
|
+
**Exploratory debugging:** You don't know what's broken yet
|
|
129
|
+
**Shared state:** Agents would interfere (editing same files, using same resources)
|
|
130
|
+
|
|
131
|
+
## Real Example from Session
|
|
132
|
+
|
|
133
|
+
**Scenario:** 6 test failures across 3 files after major refactoring
|
|
134
|
+
|
|
135
|
+
**Failures:**
|
|
136
|
+
- agent-tool-abort.test.ts: 3 failures (timing issues)
|
|
137
|
+
- batch-completion-behavior.test.ts: 2 failures (tools not executing)
|
|
138
|
+
- tool-approval-race-conditions.test.ts: 1 failure (execution count = 0)
|
|
139
|
+
|
|
140
|
+
**Decision:** Independent domains - abort logic separate from batch completion separate from race conditions
|
|
141
|
+
|
|
142
|
+
**Dispatch:**
|
|
143
|
+
```
|
|
144
|
+
Agent 1 → Fix agent-tool-abort.test.ts
|
|
145
|
+
Agent 2 → Fix batch-completion-behavior.test.ts
|
|
146
|
+
Agent 3 → Fix tool-approval-race-conditions.test.ts
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
**Results:**
|
|
150
|
+
- Agent 1: Replaced timeouts with event-based waiting
|
|
151
|
+
- Agent 2: Fixed event structure bug (threadId in wrong place)
|
|
152
|
+
- Agent 3: Added wait for async tool execution to complete
|
|
153
|
+
|
|
154
|
+
**Integration:** All fixes independent, no conflicts, full suite green
|
|
155
|
+
|
|
156
|
+
**Time saved:** 3 problems solved in parallel vs sequentially
|
|
157
|
+
|
|
158
|
+
## Key Benefits
|
|
159
|
+
|
|
160
|
+
1. **Parallelization** - Multiple investigations happen simultaneously
|
|
161
|
+
2. **Focus** - Each agent has narrow scope, less context to track
|
|
162
|
+
3. **Independence** - Agents don't interfere with each other
|
|
163
|
+
4. **Speed** - 3 problems solved in time of 1
|
|
164
|
+
|
|
165
|
+
## Verification
|
|
166
|
+
|
|
167
|
+
After agents return:
|
|
168
|
+
1. **Review each summary** - Understand what changed
|
|
169
|
+
2. **Check for conflicts** - Did agents edit same code?
|
|
170
|
+
3. **Run full suite** - Verify all fixes work together
|
|
171
|
+
4. **Spot check** - Agents can make systematic errors
|
|
172
|
+
|
|
173
|
+
## Real-World Impact
|
|
174
|
+
|
|
175
|
+
From debugging session (2025-10-03):
|
|
176
|
+
- 6 failures across 3 files
|
|
177
|
+
- 3 agents dispatched in parallel
|
|
178
|
+
- All investigations completed concurrently
|
|
179
|
+
- All fixes integrated successfully
|
|
180
|
+
- Zero conflicts between agent changes
|