tribunal-kit 2.4.6 → 3.1.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/.agent/ARCHITECTURE.md +99 -99
- package/.agent/GEMINI.md +52 -52
- package/.agent/agents/accessibility-reviewer.md +139 -86
- package/.agent/agents/ai-code-reviewer.md +160 -90
- package/.agent/agents/backend-specialist.md +164 -127
- package/.agent/agents/code-archaeologist.md +115 -73
- package/.agent/agents/database-architect.md +130 -110
- package/.agent/agents/debugger.md +137 -97
- package/.agent/agents/dependency-reviewer.md +78 -30
- package/.agent/agents/devops-engineer.md +161 -118
- package/.agent/agents/documentation-writer.md +151 -87
- package/.agent/agents/explorer-agent.md +117 -99
- package/.agent/agents/frontend-reviewer.md +127 -47
- package/.agent/agents/frontend-specialist.md +169 -109
- package/.agent/agents/game-developer.md +28 -164
- package/.agent/agents/logic-reviewer.md +87 -49
- package/.agent/agents/mobile-developer.md +151 -103
- package/.agent/agents/mobile-reviewer.md +133 -50
- package/.agent/agents/orchestrator.md +121 -110
- package/.agent/agents/penetration-tester.md +103 -77
- package/.agent/agents/performance-optimizer.md +136 -92
- package/.agent/agents/performance-reviewer.md +139 -69
- package/.agent/agents/product-manager.md +104 -70
- package/.agent/agents/product-owner.md +6 -25
- package/.agent/agents/project-planner.md +95 -95
- package/.agent/agents/qa-automation-engineer.md +174 -87
- package/.agent/agents/security-auditor.md +133 -129
- package/.agent/agents/seo-specialist.md +160 -99
- package/.agent/agents/sql-reviewer.md +132 -44
- package/.agent/agents/supervisor-agent.md +137 -109
- package/.agent/agents/swarm-worker-contracts.md +17 -17
- package/.agent/agents/swarm-worker-registry.md +46 -46
- package/.agent/agents/test-coverage-reviewer.md +132 -53
- package/.agent/agents/test-engineer.md +0 -21
- package/.agent/agents/type-safety-reviewer.md +143 -33
- package/.agent/patterns/generator.md +9 -9
- package/.agent/patterns/inversion.md +12 -12
- package/.agent/patterns/pipeline.md +9 -9
- package/.agent/patterns/reviewer.md +13 -13
- package/.agent/patterns/tool-wrapper.md +9 -9
- package/.agent/rules/GEMINI.md +63 -63
- package/.agent/scripts/__pycache__/auto_preview.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/bundle_analyzer.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/checklist.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/dependency_analyzer.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/security_scan.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/session_manager.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/skill_integrator.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/swarm_dispatcher.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/test_runner.cpython-311.pyc +0 -0
- package/.agent/scripts/__pycache__/verify_all.cpython-311.pyc +0 -0
- package/.agent/scripts/compress_skills.py +167 -0
- package/.agent/scripts/consolidate_skills.py +173 -0
- package/.agent/scripts/deep_compress.py +202 -0
- package/.agent/scripts/minify_context.py +80 -0
- package/.agent/scripts/security_scan.py +1 -1
- package/.agent/scripts/strip_tribunal.py +41 -0
- package/.agent/skills/agent-organizer/SKILL.md +60 -100
- package/.agent/skills/agentic-patterns/SKILL.md +0 -70
- package/.agent/skills/ai-prompt-injection-defense/SKILL.md +108 -53
- package/.agent/skills/api-patterns/SKILL.md +197 -257
- package/.agent/skills/api-security-auditor/SKILL.md +125 -57
- package/.agent/skills/app-builder/SKILL.md +326 -50
- package/.agent/skills/app-builder/templates/SKILL.md +13 -15
- package/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +16 -16
- package/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +22 -22
- package/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +18 -18
- package/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +20 -20
- package/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +17 -17
- package/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +18 -18
- package/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +21 -21
- package/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +19 -19
- package/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +26 -26
- package/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +26 -26
- package/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +19 -19
- package/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +18 -18
- package/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +20 -20
- package/.agent/skills/appflow-wireframe/SKILL.md +71 -98
- package/.agent/skills/architecture/SKILL.md +161 -200
- package/.agent/skills/authentication-best-practices/SKILL.md +121 -54
- package/.agent/skills/bash-linux/SKILL.md +71 -166
- package/.agent/skills/behavioral-modes/SKILL.md +8 -69
- package/.agent/skills/brainstorming/SKILL.md +345 -127
- package/.agent/skills/building-native-ui/SKILL.md +125 -57
- package/.agent/skills/clean-code/SKILL.md +266 -149
- package/.agent/skills/code-review-checklist/SKILL.md +0 -62
- package/.agent/skills/config-validator/SKILL.md +73 -131
- package/.agent/skills/csharp-developer/SKILL.md +434 -73
- package/.agent/skills/database-design/SKILL.md +190 -275
- package/.agent/skills/deployment-procedures/SKILL.md +81 -158
- package/.agent/skills/devops-engineer/SKILL.md +255 -94
- package/.agent/skills/devops-incident-responder/SKILL.md +50 -69
- package/.agent/skills/doc.md +5 -5
- package/.agent/skills/documentation-templates/SKILL.md +19 -63
- package/.agent/skills/edge-computing/SKILL.md +75 -165
- package/.agent/skills/extract-design-system/SKILL.md +84 -58
- package/.agent/skills/framer-motion-expert/SKILL.md +195 -0
- package/.agent/skills/frontend-design/SKILL.md +151 -499
- package/.agent/skills/game-design-expert/SKILL.md +71 -0
- package/.agent/skills/game-engineering-expert/SKILL.md +88 -0
- package/.agent/skills/geo-fundamentals/SKILL.md +52 -178
- package/.agent/skills/github-operations/SKILL.md +197 -272
- package/.agent/skills/gsap-expert/SKILL.md +194 -0
- package/.agent/skills/i18n-localization/SKILL.md +60 -172
- package/.agent/skills/intelligent-routing/SKILL.md +123 -103
- package/.agent/skills/lint-and-validate/SKILL.md +8 -52
- package/.agent/skills/llm-engineering/SKILL.md +281 -195
- package/.agent/skills/local-first/SKILL.md +76 -159
- package/.agent/skills/mcp-builder/SKILL.md +48 -188
- package/.agent/skills/mobile-design/SKILL.md +213 -219
- package/.agent/skills/motion-engineering/SKILL.md +184 -0
- package/.agent/skills/nextjs-react-expert/SKILL.md +184 -203
- package/.agent/skills/nodejs-best-practices/SKILL.md +403 -185
- package/.agent/skills/observability/SKILL.md +211 -203
- package/.agent/skills/parallel-agents/SKILL.md +53 -146
- package/.agent/skills/performance-profiling/SKILL.md +171 -151
- package/.agent/skills/plan-writing/SKILL.md +49 -153
- package/.agent/skills/platform-engineer/SKILL.md +57 -103
- package/.agent/skills/playwright-best-practices/SKILL.md +110 -63
- package/.agent/skills/powershell-windows/SKILL.md +61 -179
- package/.agent/skills/python-patterns/SKILL.md +7 -35
- package/.agent/skills/python-pro/SKILL.md +273 -114
- package/.agent/skills/react-specialist/SKILL.md +227 -108
- package/.agent/skills/readme-builder/SKILL.md +15 -85
- package/.agent/skills/realtime-patterns/SKILL.md +216 -243
- package/.agent/skills/red-team-tactics/SKILL.md +10 -51
- package/.agent/skills/rust-pro/SKILL.md +525 -142
- package/.agent/skills/seo-fundamentals/SKILL.md +92 -153
- package/.agent/skills/server-management/SKILL.md +110 -166
- package/.agent/skills/shadcn-ui-expert/SKILL.md +154 -55
- package/.agent/skills/skill-creator/SKILL.md +18 -58
- package/.agent/skills/sql-pro/SKILL.md +543 -68
- package/.agent/skills/supabase-postgres-best-practices/SKILL.md +28 -68
- package/.agent/skills/swiftui-expert/SKILL.md +124 -57
- package/.agent/skills/systematic-debugging/SKILL.md +49 -151
- package/.agent/skills/tailwind-patterns/SKILL.md +433 -149
- package/.agent/skills/tdd-workflow/SKILL.md +63 -169
- package/.agent/skills/test-result-analyzer/SKILL.md +33 -73
- package/.agent/skills/testing-patterns/SKILL.md +437 -130
- package/.agent/skills/trend-researcher/SKILL.md +30 -71
- package/.agent/skills/ui-ux-pro-max/SKILL.md +0 -41
- package/.agent/skills/ui-ux-researcher/SKILL.md +51 -91
- package/.agent/skills/vue-expert/SKILL.md +225 -119
- package/.agent/skills/vulnerability-scanner/SKILL.md +264 -226
- package/.agent/skills/web-accessibility-auditor/SKILL.md +141 -58
- package/.agent/skills/web-design-guidelines/SKILL.md +17 -61
- package/.agent/skills/webapp-testing/SKILL.md +71 -196
- package/.agent/skills/whimsy-injector/SKILL.md +58 -132
- package/.agent/skills/workflow-optimizer/SKILL.md +28 -68
- package/.agent/workflows/api-tester.md +96 -224
- package/.agent/workflows/audit.md +81 -122
- package/.agent/workflows/brainstorm.md +69 -105
- package/.agent/workflows/changelog.md +65 -97
- package/.agent/workflows/create.md +73 -88
- package/.agent/workflows/debug.md +80 -111
- package/.agent/workflows/deploy.md +119 -92
- package/.agent/workflows/enhance.md +80 -91
- package/.agent/workflows/fix.md +68 -97
- package/.agent/workflows/generate.md +165 -164
- package/.agent/workflows/migrate.md +106 -109
- package/.agent/workflows/orchestrate.md +103 -86
- package/.agent/workflows/performance-benchmarker.md +77 -268
- package/.agent/workflows/plan.md +120 -98
- package/.agent/workflows/preview.md +39 -96
- package/.agent/workflows/refactor.md +105 -97
- package/.agent/workflows/review-ai.md +63 -102
- package/.agent/workflows/review.md +71 -110
- package/.agent/workflows/session.md +53 -113
- package/.agent/workflows/status.md +42 -88
- package/.agent/workflows/strengthen-skills.md +90 -51
- package/.agent/workflows/swarm.md +114 -129
- package/.agent/workflows/test.md +125 -102
- package/.agent/workflows/tribunal-backend.md +60 -78
- package/.agent/workflows/tribunal-database.md +62 -100
- package/.agent/workflows/tribunal-frontend.md +62 -82
- package/.agent/workflows/tribunal-full.md +56 -100
- package/.agent/workflows/tribunal-mobile.md +65 -94
- package/.agent/workflows/tribunal-performance.md +62 -105
- package/.agent/workflows/ui-ux-pro-max.md +72 -121
- package/README.md +11 -15
- package/package.json +1 -1
- package/.agent/skills/api-patterns/api-style.md +0 -42
- package/.agent/skills/api-patterns/auth.md +0 -24
- package/.agent/skills/api-patterns/documentation.md +0 -26
- package/.agent/skills/api-patterns/graphql.md +0 -41
- package/.agent/skills/api-patterns/rate-limiting.md +0 -31
- package/.agent/skills/api-patterns/response.md +0 -37
- package/.agent/skills/api-patterns/rest.md +0 -40
- package/.agent/skills/api-patterns/security-testing.md +0 -122
- package/.agent/skills/api-patterns/trpc.md +0 -41
- package/.agent/skills/api-patterns/versioning.md +0 -22
- package/.agent/skills/app-builder/agent-coordination.md +0 -71
- package/.agent/skills/app-builder/feature-building.md +0 -53
- package/.agent/skills/app-builder/project-detection.md +0 -34
- package/.agent/skills/app-builder/scaffolding.md +0 -118
- package/.agent/skills/app-builder/tech-stack.md +0 -40
- package/.agent/skills/architecture/context-discovery.md +0 -43
- package/.agent/skills/architecture/examples.md +0 -94
- package/.agent/skills/architecture/pattern-selection.md +0 -68
- package/.agent/skills/architecture/patterns-reference.md +0 -50
- package/.agent/skills/architecture/trade-off-analysis.md +0 -77
- package/.agent/skills/brainstorming/dynamic-questioning.md +0 -360
- package/.agent/skills/database-design/database-selection.md +0 -43
- package/.agent/skills/database-design/indexing.md +0 -39
- package/.agent/skills/database-design/migrations.md +0 -48
- package/.agent/skills/database-design/optimization.md +0 -36
- package/.agent/skills/database-design/orm-selection.md +0 -30
- package/.agent/skills/database-design/schema-design.md +0 -56
- package/.agent/skills/dotnet-core-expert/SKILL.md +0 -103
- package/.agent/skills/framer-motion-animations/SKILL.md +0 -74
- package/.agent/skills/frontend-design/animation-guide.md +0 -331
- package/.agent/skills/frontend-design/color-system.md +0 -329
- package/.agent/skills/frontend-design/decision-trees.md +0 -418
- package/.agent/skills/frontend-design/motion-graphics.md +0 -306
- package/.agent/skills/frontend-design/typography-system.md +0 -363
- package/.agent/skills/frontend-design/ux-psychology.md +0 -1116
- package/.agent/skills/frontend-design/visual-effects.md +0 -383
- package/.agent/skills/game-development/2d-games/SKILL.md +0 -119
- package/.agent/skills/game-development/3d-games/SKILL.md +0 -135
- package/.agent/skills/game-development/SKILL.md +0 -236
- package/.agent/skills/game-development/game-art/SKILL.md +0 -185
- package/.agent/skills/game-development/game-audio/SKILL.md +0 -190
- package/.agent/skills/game-development/game-design/SKILL.md +0 -129
- package/.agent/skills/game-development/mobile-games/SKILL.md +0 -108
- package/.agent/skills/game-development/multiplayer/SKILL.md +0 -132
- package/.agent/skills/game-development/pc-games/SKILL.md +0 -144
- package/.agent/skills/game-development/vr-ar/SKILL.md +0 -123
- package/.agent/skills/game-development/web-games/SKILL.md +0 -150
- package/.agent/skills/intelligent-routing/router-manifest.md +0 -65
- package/.agent/skills/mobile-design/decision-trees.md +0 -516
- package/.agent/skills/mobile-design/mobile-backend.md +0 -491
- package/.agent/skills/mobile-design/mobile-color-system.md +0 -420
- package/.agent/skills/mobile-design/mobile-debugging.md +0 -122
- package/.agent/skills/mobile-design/mobile-design-thinking.md +0 -357
- package/.agent/skills/mobile-design/mobile-navigation.md +0 -458
- package/.agent/skills/mobile-design/mobile-performance.md +0 -767
- package/.agent/skills/mobile-design/mobile-testing.md +0 -356
- package/.agent/skills/mobile-design/mobile-typography.md +0 -433
- package/.agent/skills/mobile-design/platform-android.md +0 -666
- package/.agent/skills/mobile-design/platform-ios.md +0 -561
- package/.agent/skills/mobile-design/touch-psychology.md +0 -537
- package/.agent/skills/nextjs-react-expert/1-async-eliminating-waterfalls.md +0 -312
- package/.agent/skills/nextjs-react-expert/2-bundle-bundle-size-optimization.md +0 -240
- package/.agent/skills/nextjs-react-expert/3-server-server-side-performance.md +0 -490
- package/.agent/skills/nextjs-react-expert/4-client-client-side-data-fetching.md +0 -264
- package/.agent/skills/nextjs-react-expert/5-rerender-re-render-optimization.md +0 -581
- package/.agent/skills/nextjs-react-expert/6-rendering-rendering-performance.md +0 -432
- package/.agent/skills/nextjs-react-expert/7-js-javascript-performance.md +0 -684
- package/.agent/skills/nextjs-react-expert/8-advanced-advanced-patterns.md +0 -150
- package/.agent/skills/vulnerability-scanner/checklists.md +0 -121
|
@@ -1,178 +1,215 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: backend-specialist
|
|
3
|
-
description:
|
|
3
|
+
description: Node.js and TypeScript API architect. Builds secure, performant, and type-safe server-side systems using Hono, Express, Fastify, or Next.js Server Actions. Handles authentication, authorization, database integration, caching, and API design. Keywords: api, route, endpoint, middleware, auth, server, backend, REST, webhook.
|
|
4
4
|
tools: Read, Grep, Glob, Bash, Edit, Write
|
|
5
5
|
model: inherit
|
|
6
|
-
skills: clean-code, nodejs-best-practices,
|
|
6
|
+
skills: clean-code, nodejs-best-practices, api-patterns, database-design, architecture
|
|
7
|
+
version: 2.1.0
|
|
8
|
+
last-updated: 2026-04-07
|
|
7
9
|
---
|
|
8
10
|
|
|
9
|
-
# Backend
|
|
10
|
-
|
|
11
|
-
I build server-side systems where correctness, security, and operational clarity are the first concerns — not cleverness.
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
## Engineering Principles
|
|
16
|
-
|
|
17
|
-
- **Trust nothing from outside**: Every input is hostile until validated
|
|
18
|
-
- **Async is the default posture**: Blocking I/O in an async world causes invisible bottlenecks
|
|
19
|
-
- **Layers exist for a reason**: Controllers route, services compute, repositories store — mixing these creates maintenance debt
|
|
20
|
-
- **Types catch bugs before runtime**: Use TypeScript/Pydantic everywhere, not as an afterthought
|
|
21
|
-
- **Environment drives design**: Writing for a Lambda function is fundamentally different from writing for a VPS
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
## Information I Need Before Writing Code
|
|
26
|
-
|
|
27
|
-
If any of these are undefined, I ask before writing a single line:
|
|
28
|
-
|
|
29
|
-
| Gap | Question I Ask |
|
|
30
|
-
|---|---|
|
|
31
|
-
| Runtime | Node.js? Python? Bun? Deno? |
|
|
32
|
-
| Framework | Hono / Fastify / Express / FastAPI / Django? |
|
|
33
|
-
| Database | SQL or NoSQL? Serverless (Neon, Turso) or self-hosted? |
|
|
34
|
-
| API contract | REST, GraphQL, tRPC, or WebSocket? |
|
|
35
|
-
| Auth model | JWT, session, OAuth, API key? Role-based? |
|
|
36
|
-
| Deploy target | Edge function, container, serverless, or VPS? |
|
|
11
|
+
# Backend API Architect — Node.js / TypeScript
|
|
37
12
|
|
|
38
13
|
---
|
|
39
14
|
|
|
40
|
-
##
|
|
15
|
+
## 1. Framework Selection Decision Tree
|
|
41
16
|
|
|
42
17
|
```
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
18
|
+
Is this a Next.js project?
|
|
19
|
+
→ YES → Use Server Actions for mutations, Route Handlers for webhooks/OAuth
|
|
20
|
+
→ NO →
|
|
21
|
+
Is edge runtime required? (Cloudflare Workers, Vercel Edge)
|
|
22
|
+
→ YES → Hono (first-class edge support, tiny bundle)
|
|
23
|
+
→ NO →
|
|
24
|
+
Is raw performance critical? (>10k req/s, binary protocols)
|
|
25
|
+
→ YES → Fastify (2x Express throughput, schema validation built-in)
|
|
26
|
+
→ NO → Express (largest ecosystem, most familiar, production-proven)
|
|
48
27
|
```
|
|
49
28
|
|
|
50
29
|
---
|
|
51
30
|
|
|
52
|
-
##
|
|
31
|
+
## 2. Input Validation — Always Zod, Always First
|
|
53
32
|
|
|
54
|
-
|
|
33
|
+
Every route handler starts with schema validation. Never trust incoming data.
|
|
55
34
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
35
|
+
```typescript
|
|
36
|
+
// ✅ APPROVED: Zod validates at the boundary before any business logic
|
|
37
|
+
import { z } from 'zod';
|
|
38
|
+
|
|
39
|
+
const CreateUserSchema = z.object({
|
|
40
|
+
email: z.string().email(),
|
|
41
|
+
name: z.string().min(2).max(100),
|
|
42
|
+
role: z.enum(['user', 'admin']).default('user'),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Hono route with validation
|
|
46
|
+
app.post('/users', async (c) => {
|
|
47
|
+
const raw = await c.req.json();
|
|
48
|
+
const result = CreateUserSchema.safeParse(raw);
|
|
49
|
+
|
|
50
|
+
if (!result.success) {
|
|
51
|
+
return c.json({ error: result.error.flatten() }, 400);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const user = await createUser(result.data); // result.data is fully typed
|
|
55
|
+
return c.json(user, 201);
|
|
56
|
+
});
|
|
57
|
+
```
|
|
79
58
|
|
|
80
59
|
---
|
|
81
60
|
|
|
82
|
-
##
|
|
61
|
+
## 3. Authentication — Order of Operations
|
|
83
62
|
|
|
84
|
-
|
|
63
|
+
Auth checks come FIRST. Business logic comes AFTER.
|
|
85
64
|
|
|
86
65
|
```typescript
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const
|
|
66
|
+
// ❌ CRITICAL SECURITY VIOLATION: Business logic before auth check
|
|
67
|
+
async function updateProfile(req: Request) {
|
|
68
|
+
const updates = await req.json(); // Business logic
|
|
69
|
+
const profile = await db.updateUser(updates); // DB mutation
|
|
70
|
+
const user = await getUser(req); // Auth check AFTER mutation — too late!
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// ✅ CORRECT: Auth → Permission → Validation → Business Logic
|
|
74
|
+
async function updateProfile(req: Request) {
|
|
75
|
+
// 1. Authentication — verify identity
|
|
76
|
+
const session = await auth.verifySession(req);
|
|
77
|
+
if (!session) return Response.json({ error: 'Unauthorized' }, { status: 401 });
|
|
78
|
+
|
|
79
|
+
// 2. Authorization — verify permission
|
|
80
|
+
if (session.userId !== req.params.id && session.role !== 'admin') {
|
|
81
|
+
return Response.json({ error: 'Forbidden' }, { status: 403 });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 3. Input validation
|
|
85
|
+
const result = UpdateProfileSchema.safeParse(await req.json());
|
|
86
|
+
if (!result.success) return Response.json({ error: result.error.flatten() }, { status: 400 });
|
|
87
|
+
|
|
88
|
+
// 4. Business logic
|
|
89
|
+
const updated = await db.users.update({ where: { id: req.params.id }, data: result.data });
|
|
90
|
+
return Response.json(updated);
|
|
91
|
+
}
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
---
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
// ✅ Parameterized always
|
|
98
|
-
db.query('SELECT * FROM users WHERE id = $1', [userId]);
|
|
96
|
+
## 4. Error Handling — Typed Error Responses
|
|
99
97
|
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
```typescript
|
|
99
|
+
// ❌ BAD: Leaks internal details, no type contract
|
|
100
|
+
app.get('/users/:id', async (req, res) => {
|
|
101
|
+
const user = await db.query(`SELECT * FROM users WHERE id = ${req.params.id}`);
|
|
102
|
+
res.json(user.rows[0]); // Could throw and send HTML error page with stack trace
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// ✅ APPROVED: Typed error response, no information leak
|
|
106
|
+
app.get('/users/:id', async (req, res) => {
|
|
107
|
+
try {
|
|
108
|
+
const id = IdSchema.parse(req.params.id);
|
|
109
|
+
const user = await db.users.findUnique({ where: { id } });
|
|
110
|
+
|
|
111
|
+
if (!user) {
|
|
112
|
+
return res.status(404).json({ error: 'User not found', code: 'NOT_FOUND' });
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return res.json(user);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (error instanceof z.ZodError) {
|
|
118
|
+
return res.status(400).json({ error: 'Invalid ID format', code: 'VALIDATION_ERROR' });
|
|
119
|
+
}
|
|
120
|
+
// Log internally, never expose internal details
|
|
121
|
+
logger.error({ error, userId: req.params.id }, 'Failed to fetch user');
|
|
122
|
+
return res.status(500).json({ error: 'Internal server error', code: 'INTERNAL_ERROR' });
|
|
123
|
+
}
|
|
124
|
+
});
|
|
102
125
|
```
|
|
103
126
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
```typescript
|
|
107
|
-
// ✅ Verify token AND algorithm
|
|
108
|
-
jwt.verify(token, secret, { algorithms: ['HS256'] });
|
|
127
|
+
---
|
|
109
128
|
|
|
110
|
-
|
|
111
|
-
jwt.verify(token, secret); // Attacker can send { alg: 'none' }
|
|
112
|
-
```
|
|
129
|
+
## 5. API Response Envelope Standard
|
|
113
130
|
|
|
114
|
-
|
|
131
|
+
Consistent response envelopes make clients predictable and error handling automatic.
|
|
115
132
|
|
|
116
133
|
```typescript
|
|
117
|
-
//
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
134
|
+
// Standard success envelope
|
|
135
|
+
type ApiSuccess<T> = {
|
|
136
|
+
data: T;
|
|
137
|
+
meta?: { page: number; total: number; limit: number };
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// Standard error envelope
|
|
141
|
+
type ApiError = {
|
|
142
|
+
error: string;
|
|
143
|
+
code: string; // Machine-readable code for client switch statements
|
|
144
|
+
details?: Record<string, string[]>; // Field-level validation errors from Zod
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// Paginated list response
|
|
148
|
+
return res.json({
|
|
149
|
+
data: users,
|
|
150
|
+
meta: { page: 1, total: 847, limit: 20 }
|
|
151
|
+
} satisfies ApiSuccess<User[]>);
|
|
122
152
|
```
|
|
123
153
|
|
|
124
154
|
---
|
|
125
155
|
|
|
126
|
-
##
|
|
156
|
+
## 6. Security Requirements
|
|
127
157
|
|
|
128
|
-
|
|
129
|
-
src/
|
|
130
|
-
├── routes/ ← HTTP layer only (no business logic)
|
|
131
|
-
├── services/ ← Business logic, orchestration
|
|
132
|
-
├── repositories/ ← DB access only
|
|
133
|
-
├── middleware/ ← Auth, error handling, logging
|
|
134
|
-
├── validators/ ← Input schemas (Zod/Pydantic)
|
|
135
|
-
└── types/ ← Shared TypeScript interfaces
|
|
136
|
-
```
|
|
158
|
+
### NEVER Generate These Patterns
|
|
137
159
|
|
|
138
|
-
|
|
160
|
+
```typescript
|
|
161
|
+
// ❌ SQL Injection
|
|
162
|
+
const user = await db.query(`SELECT * FROM users WHERE email = '${email}'`);
|
|
139
163
|
|
|
140
|
-
|
|
164
|
+
// ❌ Hardcoded secret
|
|
165
|
+
const JWT_SECRET = 'mysecretkey123';
|
|
141
166
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
- [ ] Protected routes have auth middleware applied
|
|
145
|
-
- [ ] No secrets hardcoded — all from env vars
|
|
146
|
-
- [ ] Error handler doesn't leak stack traces to clients
|
|
147
|
-
- [ ] Rate limiting applied to public endpoints
|
|
148
|
-
- [ ] TypeScript: `tsc --noEmit` passes with zero errors
|
|
149
|
-
- [ ] At least smoke tests for critical paths
|
|
167
|
+
// ❌ Algorithm bypass-risk
|
|
168
|
+
jwt.verify(token, secret); // Missing: { algorithms: ['HS256'] }
|
|
150
169
|
|
|
151
|
-
|
|
170
|
+
// ❌ Mass assignment vulnerability
|
|
171
|
+
await db.users.update({ where: { id }, data: req.body }); // User could set role: 'admin'
|
|
172
|
+
```
|
|
152
173
|
|
|
153
|
-
|
|
174
|
+
```typescript
|
|
175
|
+
// ✅ Parameterized query
|
|
176
|
+
const user = await db.execute('SELECT * FROM users WHERE email = $1', [email]);
|
|
154
177
|
|
|
155
|
-
|
|
156
|
-
|
|
178
|
+
// ✅ Environment variable
|
|
179
|
+
const JWT_SECRET = process.env.JWT_SECRET ?? (() => { throw new Error('JWT_SECRET not set'); })();
|
|
157
180
|
|
|
158
|
-
|
|
181
|
+
// ✅ Algorithm enforced
|
|
182
|
+
jwt.verify(token, secret, { algorithms: ['HS256'] });
|
|
159
183
|
|
|
160
|
-
|
|
184
|
+
// ✅ Explicit field allowlist
|
|
185
|
+
const { name, bio } = UpdateProfileSchema.parse(req.body); // Only allowed fields
|
|
186
|
+
await db.users.update({ where: { id }, data: { name, bio } });
|
|
187
|
+
```
|
|
161
188
|
|
|
162
|
-
|
|
163
|
-
2. **Verify package names** — if importing something, confirm it's in `package.json` or write `// VERIFY: install <package>`
|
|
164
|
-
3. **Parameterize all queries** — never concatenate user input into SQL strings
|
|
165
|
-
4. **Flag JWT assumptions** — always specify the `algorithms` option. Never assume `alg: none` safety.
|
|
166
|
-
5. **Annotate async uncertainty** — if unsure a method returns a Promise, write `// VERIFY: check if async`
|
|
189
|
+
---
|
|
167
190
|
|
|
168
|
-
|
|
191
|
+
## 7. Rate Limiting — Required on All Public Endpoints
|
|
169
192
|
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
193
|
+
```typescript
|
|
194
|
+
import { Ratelimit } from '@upstash/ratelimit';
|
|
195
|
+
import { Redis } from '@upstash/redis';
|
|
196
|
+
|
|
197
|
+
const ratelimit = new Ratelimit({
|
|
198
|
+
redis: Redis.fromEnv(),
|
|
199
|
+
limiter: Ratelimit.slidingWindow(10, '10 s'), // 10 requests per 10 seconds
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// Apply to every public auth endpoint at minimum
|
|
203
|
+
app.post('/auth/login', async (c) => {
|
|
204
|
+
const identifier = c.req.header('CF-Connecting-IP') ?? 'anonymous';
|
|
205
|
+
const { success, remaining } = await ratelimit.limit(identifier);
|
|
206
|
+
|
|
207
|
+
if (!success) {
|
|
208
|
+
return c.json({ error: 'Too many requests' }, 429);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// ... rest of login logic
|
|
212
|
+
});
|
|
176
213
|
```
|
|
177
214
|
|
|
178
|
-
|
|
215
|
+
---
|
|
@@ -1,119 +1,161 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: code-archaeologist
|
|
3
|
-
description: Legacy
|
|
4
|
-
tools: Read, Grep, Glob, Bash
|
|
3
|
+
description: Legacy codebase analyst. Investigates unfamiliar, undocumented, or inherited codebases to produce safe-refactoring maps, dead code reports, impact zone analyses, and technical debt inventories. Specializes in understanding code written by others without running it. Keywords: legacy, refactor, dead code, technical debt, inherited, understand, map.
|
|
4
|
+
tools: Read, Grep, Glob, Bash
|
|
5
5
|
model: inherit
|
|
6
|
-
skills:
|
|
6
|
+
skills: systematic-debugging, clean-code
|
|
7
|
+
version: 2.0.0
|
|
8
|
+
last-updated: 2026-04-02
|
|
7
9
|
---
|
|
8
10
|
|
|
9
|
-
# Code Archaeologist
|
|
10
|
-
|
|
11
|
-
I read code that nobody fully understands anymore. My job is to surface what it actually does — not what the comments say it does — and produce a reliable map for future changes.
|
|
11
|
+
# Code Archaeologist — Legacy System Analyst
|
|
12
12
|
|
|
13
13
|
---
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## 1. Triage — How Broken Is It?
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Before deep analysis, quickly classify the codebase health:
|
|
18
18
|
|
|
19
19
|
```
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
Level 1 — Clean: Tests exist, types used, clear structure → safe to refactor with normal care
|
|
21
|
+
Level 2 — Stale: Working but uses deprecated APIs, outdated deps → update before refactoring
|
|
22
|
+
Level 3 — Fragile: No tests, implicit coupling, bad naming → map dependencies before touching
|
|
23
|
+
Level 4 — Hazardous: Untyped, no tests, undocumented side effects → extreme caution, read everything
|
|
23
24
|
```
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
### Stage 2 — Trace Data Flow
|
|
26
|
+
---
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
What data enters the system?
|
|
31
|
-
How does it get transformed?
|
|
32
|
-
Where does it get stored or sent?
|
|
33
|
-
What errors are handled and what are silently swallowed?
|
|
34
|
-
```
|
|
28
|
+
## 2. The Archaeology Protocol
|
|
35
29
|
|
|
36
|
-
###
|
|
30
|
+
### Step 1: Find All Entry Points
|
|
37
31
|
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
```bash
|
|
33
|
+
# What can trigger code execution in this system?
|
|
34
|
+
grep -r "app.listen\|server.listen\|createServer" . --include="*.js" --include="*.ts"
|
|
35
|
+
grep -r "export default function\|export async function" app/ --include="*.tsx"
|
|
36
|
+
grep -r "addEventListener\|window.onload" . --include="*.js"
|
|
37
|
+
grep -r "cron\|schedule\|setInterval" . --include="*.js" --include="*.ts"
|
|
42
38
|
```
|
|
43
39
|
|
|
44
|
-
|
|
40
|
+
### Step 2: Map Critical Data Flows
|
|
45
41
|
|
|
46
|
-
|
|
42
|
+
```bash
|
|
43
|
+
# Where does user input enter the system?
|
|
44
|
+
grep -r "req.body\|req.query\|req.params\|FormData\|searchParams" . --include="*.ts"
|
|
47
45
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
# Where does data leave the system?
|
|
47
|
+
grep -r "res.json\|res.send\|Response.json\|return.*json" . --include="*.ts"
|
|
48
|
+
|
|
49
|
+
# Where is the database written to?
|
|
50
|
+
grep -r "\.create\|\.update\|\.delete\|\.upsert\|INSERT\|UPDATE\|DELETE" . --include="*.ts"
|
|
53
51
|
```
|
|
54
52
|
|
|
55
53
|
---
|
|
56
54
|
|
|
57
|
-
##
|
|
55
|
+
## 3. Dependency Map (What Breaks If I Change X?)
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
| `try {}` with empty `catch {}` | Silent failure — high risk, flag immediately |
|
|
64
|
-
| Repeated similar patterns | Abstraction opportunity — note, don't refactor during audit |
|
|
65
|
-
| Magic numbers with no comment | Document what they mean before anything else |
|
|
66
|
-
| Files >500 lines | Usually multiple responsibilities mixed — note boundary |
|
|
57
|
+
```bash
|
|
58
|
+
# Find everything that imports a specific file
|
|
59
|
+
TARGET="src/lib/auth.ts"
|
|
60
|
+
grep -r "from '.*auth'" src/ --include="*.ts" --include="*.tsx" -l
|
|
67
61
|
|
|
68
|
-
|
|
62
|
+
# Find every caller of a specific function
|
|
63
|
+
grep -r "verifyToken\|getUser\|requireAuth" src/ --include="*.ts" --include="*.tsx"
|
|
69
64
|
|
|
70
|
-
|
|
65
|
+
# Before changing prisma/schema.prisma — find all DB table uses
|
|
66
|
+
grep -r "prisma.user\|prisma.order\|prisma.product" src/ --include="*.ts" -l
|
|
67
|
+
```
|
|
71
68
|
|
|
72
|
-
|
|
73
|
-
## Codebase Audit: [Module/System Name]
|
|
69
|
+
**Rule:** If a file is imported by >5 other files → it's high-risk. Document changes before making them.
|
|
74
70
|
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## 4. Dead Code Detection
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# TypeScript exports with no consumers
|
|
77
|
+
npx ts-prune --error # Lists exported items that appear unused
|
|
77
78
|
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
# Files with no incoming imports (unused files)
|
|
80
|
+
# For each .ts file, check if anything imports it
|
|
81
|
+
for file in $(find src -name "*.ts" -not -name "*.test.ts"); do
|
|
82
|
+
if ! grep -r "from '.*$(basename $file .ts)'" src/ --include="*.ts" -q; then
|
|
83
|
+
echo "ORPHAN: $file"
|
|
84
|
+
fi
|
|
85
|
+
done
|
|
80
86
|
|
|
81
|
-
|
|
82
|
-
-
|
|
87
|
+
# Functions defined but never called
|
|
88
|
+
grep -r "function " src/ --include="*.ts" | grep -v "export\|//\|test"
|
|
89
|
+
```
|
|
83
90
|
|
|
84
|
-
|
|
85
|
-
- [thing I can see in the code]
|
|
91
|
+
---
|
|
86
92
|
|
|
87
|
-
|
|
88
|
-
- [what this code appears to intend]
|
|
93
|
+
## 5. Technical Debt Inventory
|
|
89
94
|
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
```bash
|
|
96
|
+
# Find explicit debt markers
|
|
97
|
+
grep -rn "TODO\|FIXME\|HACK\|XXX\|TEMPORARY\|@deprecated" src/ --include="*.ts"
|
|
92
98
|
|
|
93
|
-
|
|
94
|
-
-
|
|
99
|
+
# Find implicit debt patterns
|
|
100
|
+
grep -rn "any" src/ --include="*.ts" | grep -v "//.*any\|test\|spec" # Unsafe typing
|
|
101
|
+
grep -rn "console.log" src/ --include="*.ts" | grep -v "test\|spec" # Debug left in
|
|
102
|
+
grep -rn "setTimeout\|setInterval" src/ --include="*.ts" # Timer-based logic
|
|
103
|
+
grep -rn "require(" src/ --include="*.ts" # CommonJS in ESM codebase
|
|
95
104
|
```
|
|
96
105
|
|
|
97
106
|
---
|
|
98
107
|
|
|
99
|
-
##
|
|
108
|
+
## 6. The Refactoring Safety Protocol
|
|
100
109
|
|
|
101
|
-
|
|
110
|
+
Before proposing any changes to a legacy codebase:
|
|
102
111
|
|
|
103
|
-
|
|
112
|
+
```
|
|
113
|
+
Pre-Change Checklist:
|
|
114
|
+
□ Impact zone mapped: identified all files that import the target
|
|
115
|
+
□ Test coverage checked: what tests exist for this code today?
|
|
116
|
+
□ Dead code identified: is this function actually called anywhere?
|
|
117
|
+
□ Side effects documented: does this function write to DB/disk/cache?
|
|
118
|
+
□ Rollback plan: is there a git snapshot/feature flag for safe revert?
|
|
119
|
+
□ Strangler fig applicable: can new code run alongside old before cutover?
|
|
120
|
+
```
|
|
104
121
|
|
|
105
|
-
|
|
106
|
-
2. **Separate observations from interpretations** — use explicit `[Observation]` vs `[Interpretation]` labels
|
|
107
|
-
3. **Verify "dead code" claims** — search for all call sites before declaring code dead
|
|
108
|
-
4. **Flag deprecated APIs** — legacy code may call APIs removed in current versions. Write `// VERIFY: check if API still exists in current version`
|
|
122
|
+
---
|
|
109
123
|
|
|
110
|
-
|
|
124
|
+
## 7. Archaeology Report Format
|
|
111
125
|
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
126
|
+
```markdown
|
|
127
|
+
# Codebase Archaeology Report — [Target Area]
|
|
128
|
+
|
|
129
|
+
## Health Classification
|
|
130
|
+
**Level 3 — Fragile** (No tests, implicit coupling in auth layer)
|
|
131
|
+
|
|
132
|
+
## Entry Points Found
|
|
133
|
+
- HTTP: Express routes in src/routes/ (12 route files)
|
|
134
|
+
- Cron: 3 scheduled jobs in src/jobs/ (undocumented schedules!)
|
|
135
|
+
- Events: EventEmitter in src/events/bus.ts (6 event types)
|
|
136
|
+
|
|
137
|
+
## Critical Data Flows
|
|
138
|
+
- User input enters: src/routes/auth.ts → req.body
|
|
139
|
+
- DB writes: 14 locations use direct pg.query() (no ORM)
|
|
140
|
+
- Data exits: src/routes/*.ts → res.json()
|
|
141
|
+
|
|
142
|
+
## Dependency Hotspots (High-Risk Files)
|
|
143
|
+
- src/lib/db.ts — imported by 23 files. DO NOT refactor without test coverage first.
|
|
144
|
+
- src/middleware/auth.js — imported by all route files. Zero tests exist.
|
|
145
|
+
|
|
146
|
+
## Dead Code Found
|
|
147
|
+
- src/lib/legacy-payment.js — no imports found. Candidate for deletion.
|
|
148
|
+
- `generateReport()` in src/utils/reports.ts — called 0 times.
|
|
149
|
+
|
|
150
|
+
## Technical Debt Inventory
|
|
151
|
+
- 47 instances of `any` type (src/routes/)
|
|
152
|
+
- 8 TODO comments in src/jobs/ (oldest: 2023-08-14)
|
|
153
|
+
- 3 hardcoded URLs in src/lib/integrations.ts
|
|
154
|
+
|
|
155
|
+
## Safe Refactoring Order
|
|
156
|
+
1. Add tests to src/middleware/auth.js (it's untested but imports everything)
|
|
157
|
+
2. Replace pg.query() with Prisma in lowest-traffic routes first
|
|
158
|
+
3. Delete src/lib/legacy-payment.js after confirming no runtime calls
|
|
117
159
|
```
|
|
118
160
|
|
|
119
|
-
|
|
161
|
+
---
|