tribunal-kit 1.0.0 → 2.4.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.
Files changed (125) hide show
  1. package/.agent/.shared/ui-ux-pro-max/README.md +3 -3
  2. package/.agent/ARCHITECTURE.md +205 -10
  3. package/.agent/GEMINI.md +37 -7
  4. package/.agent/agents/accessibility-reviewer.md +134 -0
  5. package/.agent/agents/ai-code-reviewer.md +129 -0
  6. package/.agent/agents/frontend-specialist.md +3 -0
  7. package/.agent/agents/game-developer.md +21 -21
  8. package/.agent/agents/logic-reviewer.md +12 -0
  9. package/.agent/agents/mobile-reviewer.md +79 -0
  10. package/.agent/agents/orchestrator.md +56 -26
  11. package/.agent/agents/performance-reviewer.md +36 -0
  12. package/.agent/agents/supervisor-agent.md +156 -0
  13. package/.agent/agents/swarm-worker-contracts.md +166 -0
  14. package/.agent/agents/swarm-worker-registry.md +92 -0
  15. package/.agent/rules/GEMINI.md +134 -5
  16. package/.agent/scripts/bundle_analyzer.py +259 -0
  17. package/.agent/scripts/dependency_analyzer.py +247 -0
  18. package/.agent/scripts/lint_runner.py +188 -0
  19. package/.agent/scripts/patch_skills_meta.py +177 -0
  20. package/.agent/scripts/patch_skills_output.py +285 -0
  21. package/.agent/scripts/schema_validator.py +279 -0
  22. package/.agent/scripts/security_scan.py +224 -0
  23. package/.agent/scripts/session_manager.py +144 -3
  24. package/.agent/scripts/skill_integrator.py +234 -0
  25. package/.agent/scripts/strengthen_skills.py +220 -0
  26. package/.agent/scripts/swarm_dispatcher.py +317 -0
  27. package/.agent/scripts/test_runner.py +192 -0
  28. package/.agent/scripts/test_swarm_dispatcher.py +163 -0
  29. package/.agent/skills/agent-organizer/SKILL.md +132 -0
  30. package/.agent/skills/agentic-patterns/SKILL.md +335 -0
  31. package/.agent/skills/api-patterns/SKILL.md +226 -50
  32. package/.agent/skills/app-builder/SKILL.md +215 -52
  33. package/.agent/skills/architecture/SKILL.md +176 -31
  34. package/.agent/skills/bash-linux/SKILL.md +150 -134
  35. package/.agent/skills/behavioral-modes/SKILL.md +152 -160
  36. package/.agent/skills/brainstorming/SKILL.md +148 -101
  37. package/.agent/skills/brainstorming/dynamic-questioning.md +10 -0
  38. package/.agent/skills/clean-code/SKILL.md +139 -134
  39. package/.agent/skills/code-review-checklist/SKILL.md +177 -80
  40. package/.agent/skills/config-validator/SKILL.md +165 -0
  41. package/.agent/skills/csharp-developer/SKILL.md +107 -0
  42. package/.agent/skills/database-design/SKILL.md +252 -29
  43. package/.agent/skills/deployment-procedures/SKILL.md +122 -175
  44. package/.agent/skills/devops-engineer/SKILL.md +134 -0
  45. package/.agent/skills/devops-incident-responder/SKILL.md +98 -0
  46. package/.agent/skills/documentation-templates/SKILL.md +175 -121
  47. package/.agent/skills/dotnet-core-expert/SKILL.md +103 -0
  48. package/.agent/skills/edge-computing/SKILL.md +213 -0
  49. package/.agent/skills/frontend-design/SKILL.md +76 -0
  50. package/.agent/skills/frontend-design/color-system.md +18 -0
  51. package/.agent/skills/frontend-design/typography-system.md +18 -0
  52. package/.agent/skills/game-development/SKILL.md +69 -0
  53. package/.agent/skills/geo-fundamentals/SKILL.md +158 -99
  54. package/.agent/skills/i18n-localization/SKILL.md +158 -96
  55. package/.agent/skills/intelligent-routing/SKILL.md +89 -285
  56. package/.agent/skills/intelligent-routing/router-manifest.md +65 -0
  57. package/.agent/skills/lint-and-validate/SKILL.md +229 -27
  58. package/.agent/skills/llm-engineering/SKILL.md +258 -0
  59. package/.agent/skills/local-first/SKILL.md +203 -0
  60. package/.agent/skills/mcp-builder/SKILL.md +159 -111
  61. package/.agent/skills/mobile-design/SKILL.md +102 -282
  62. package/.agent/skills/nextjs-react-expert/SKILL.md +143 -227
  63. package/.agent/skills/nodejs-best-practices/SKILL.md +201 -254
  64. package/.agent/skills/observability/SKILL.md +285 -0
  65. package/.agent/skills/parallel-agents/SKILL.md +124 -118
  66. package/.agent/skills/performance-profiling/SKILL.md +143 -89
  67. package/.agent/skills/plan-writing/SKILL.md +133 -97
  68. package/.agent/skills/platform-engineer/SKILL.md +135 -0
  69. package/.agent/skills/powershell-windows/SKILL.md +167 -104
  70. package/.agent/skills/python-patterns/SKILL.md +149 -361
  71. package/.agent/skills/python-pro/SKILL.md +114 -0
  72. package/.agent/skills/react-specialist/SKILL.md +107 -0
  73. package/.agent/skills/realtime-patterns/SKILL.md +296 -0
  74. package/.agent/skills/red-team-tactics/SKILL.md +136 -134
  75. package/.agent/skills/rust-pro/SKILL.md +237 -173
  76. package/.agent/skills/seo-fundamentals/SKILL.md +134 -82
  77. package/.agent/skills/server-management/SKILL.md +155 -104
  78. package/.agent/skills/sql-pro/SKILL.md +104 -0
  79. package/.agent/skills/systematic-debugging/SKILL.md +156 -79
  80. package/.agent/skills/tailwind-patterns/SKILL.md +163 -205
  81. package/.agent/skills/tdd-workflow/SKILL.md +148 -88
  82. package/.agent/skills/test-result-analyzer/SKILL.md +299 -0
  83. package/.agent/skills/testing-patterns/SKILL.md +141 -114
  84. package/.agent/skills/trend-researcher/SKILL.md +228 -0
  85. package/.agent/skills/ui-ux-pro-max/SKILL.md +107 -0
  86. package/.agent/skills/ui-ux-researcher/SKILL.md +234 -0
  87. package/.agent/skills/vue-expert/SKILL.md +118 -0
  88. package/.agent/skills/vulnerability-scanner/SKILL.md +228 -188
  89. package/.agent/skills/web-design-guidelines/SKILL.md +148 -33
  90. package/.agent/skills/webapp-testing/SKILL.md +171 -122
  91. package/.agent/skills/whimsy-injector/SKILL.md +349 -0
  92. package/.agent/skills/workflow-optimizer/SKILL.md +219 -0
  93. package/.agent/workflows/api-tester.md +279 -0
  94. package/.agent/workflows/audit.md +168 -0
  95. package/.agent/workflows/brainstorm.md +65 -19
  96. package/.agent/workflows/changelog.md +144 -0
  97. package/.agent/workflows/create.md +67 -14
  98. package/.agent/workflows/debug.md +122 -30
  99. package/.agent/workflows/deploy.md +82 -31
  100. package/.agent/workflows/enhance.md +59 -27
  101. package/.agent/workflows/fix.md +143 -0
  102. package/.agent/workflows/generate.md +84 -20
  103. package/.agent/workflows/migrate.md +163 -0
  104. package/.agent/workflows/orchestrate.md +66 -17
  105. package/.agent/workflows/performance-benchmarker.md +305 -0
  106. package/.agent/workflows/plan.md +76 -33
  107. package/.agent/workflows/preview.md +73 -17
  108. package/.agent/workflows/refactor.md +153 -0
  109. package/.agent/workflows/review-ai.md +140 -0
  110. package/.agent/workflows/review.md +83 -16
  111. package/.agent/workflows/session.md +154 -0
  112. package/.agent/workflows/status.md +74 -18
  113. package/.agent/workflows/strengthen-skills.md +99 -0
  114. package/.agent/workflows/swarm.md +194 -0
  115. package/.agent/workflows/test.md +80 -31
  116. package/.agent/workflows/tribunal-backend.md +55 -13
  117. package/.agent/workflows/tribunal-database.md +62 -18
  118. package/.agent/workflows/tribunal-frontend.md +58 -12
  119. package/.agent/workflows/tribunal-full.md +70 -11
  120. package/.agent/workflows/tribunal-mobile.md +123 -0
  121. package/.agent/workflows/tribunal-performance.md +152 -0
  122. package/.agent/workflows/ui-ux-pro-max.md +100 -82
  123. package/README.md +117 -62
  124. package/bin/tribunal-kit.js +329 -75
  125. package/package.json +10 -6
@@ -0,0 +1,165 @@
1
+ ---
2
+ name: config-validator
3
+ description: Self-validation skill for the .agent directory. Checks that all agents, skills, workflows, and scripts referenced across the system actually exist and are consistent. Use after modifying agent configuration files.
4
+ version: 1.0.0
5
+ last-updated: 2026-03-12
6
+ applies-to-model: gemini-2.5-pro, claude-3-7-sonnet
7
+ ---
8
+
9
+ # Config Validator — Agent System Self-Check
10
+
11
+ This skill validates the internal consistency of the `.agent/` directory itself. When the agent system references files that don't exist, behavior becomes unpredictable. This skill catches those gaps.
12
+
13
+ ---
14
+
15
+ ## When to Use
16
+
17
+ - After adding, renaming, or removing any agent, skill, workflow, or script
18
+ - After copying the `.agent/` directory to a new project
19
+ - When something "should work" but the agent seems to ignore it
20
+ - As part of `/audit` to ensure the agent system itself is healthy
21
+
22
+ ---
23
+
24
+ ## What Gets Checked
25
+
26
+ ### 1. Agent File Existence
27
+
28
+ Every agent referenced in `rules/GEMINI.md` routing table must have a corresponding `.md` file in `agents/`.
29
+
30
+ ```
31
+ For each agent in the routing table:
32
+ → Does agents/{agent-name}.md exist?
33
+ → If not: report as MISSING AGENT
34
+ ```
35
+
36
+ ### 2. Skill References in Agent Frontmatter
37
+
38
+ Every skill listed in an agent's `skills:` frontmatter field must exist as a directory in `skills/` with a `SKILL.md` file.
39
+
40
+ ```
41
+ For each agent file:
42
+ → Read YAML frontmatter
43
+ → For each skill in skills: field
44
+ → Does skills/{skill-name}/SKILL.md exist?
45
+ → If not: report as MISSING SKILL
46
+ ```
47
+
48
+ ### 3. Workflow File Existence
49
+
50
+ Every slash command listed in `GEMINI.md` or `ARCHITECTURE.md` must have a corresponding `.md` file in `workflows/`.
51
+
52
+ ```
53
+ For each /command referenced:
54
+ → Does workflows/{command}.md exist?
55
+ → If not: report as MISSING WORKFLOW
56
+ ```
57
+
58
+ ### 4. Script File Existence
59
+
60
+ Every script referenced in `rules/GEMINI.md` script table must exist in `scripts/`.
61
+
62
+ ```
63
+ For each script in the reference table:
64
+ → Does scripts/{script-name} exist?
65
+ → If not: report as MISSING SCRIPT
66
+ ```
67
+
68
+ ### 5. Cross-Reference Consistency
69
+
70
+ - Agent names in the routing table match filenames in `agents/`
71
+ - Workflow names in the command table match filenames in `workflows/`
72
+ - No orphan files (files that exist but are never referenced anywhere)
73
+
74
+ ---
75
+
76
+ ## Validation Process
77
+
78
+ Run this check manually or mentally when modifying the `.agent/` structure:
79
+
80
+ ```
81
+ Step 1: Read rules/GEMINI.md → Extract agent names, script names
82
+ Step 2: Read GEMINI.md → Extract slash command names
83
+ Step 3: Read ARCHITECTURE.md → Extract all references
84
+ Step 4: Read each agent .md → Extract skill references from frontmatter
85
+ Step 5: Cross-check every reference against the filesystem
86
+ Step 6: Report any mismatches
87
+ ```
88
+
89
+ ### Report Format
90
+
91
+ ```
92
+ 🔧 Config Validation Report
93
+ ━━━━━━━━━━━━━━━━━━━━━━━━━
94
+
95
+ Agents: 27 found, 27 referenced ✅
96
+ Skills: 37 found, 34 referenced ⚠️ (3 unreferenced)
97
+ Workflows: 22 found, 22 referenced ✅
98
+ Scripts: 10 found, 10 referenced ✅
99
+
100
+ Issues:
101
+ ❌ MISSING: skills/some-removed-skill/SKILL.md (referenced by agents/backend-specialist.md)
102
+ ⚠️ ORPHAN: agents/old-unused-agent.md (not referenced in routing table)
103
+ ```
104
+
105
+ ---
106
+
107
+ ## Fixing Common Issues
108
+
109
+ | Issue | Fix |
110
+ |---|---|
111
+ | Missing agent file | Create the agent `.md` file or remove from routing table |
112
+ | Missing skill directory | Create `skills/{name}/SKILL.md` or remove from agent `skills:` field |
113
+ | Missing workflow file | Create `workflows/{name}.md` or remove from slash command table |
114
+ | Missing script | Create the script or remove from script reference table |
115
+ | Orphan file | Either reference it somewhere or delete it |
116
+
117
+ ---
118
+
119
+ ## Hallucination Guard
120
+
121
+ - Never report a file as "existing" without actually checking the filesystem
122
+ - Never report a reference as "valid" without reading the referencing file
123
+ - If a file exists but has different content than expected, flag it rather than assuming it's correct
124
+
125
+
126
+ ---
127
+
128
+ ## 🤖 LLM-Specific Traps
129
+
130
+ AI coding assistants often fall into specific bad habits when dealing with this domain. These are strictly forbidden:
131
+
132
+ 1. **Over-engineering:** Proposing complex abstractions or distributed systems when a simpler approach suffices.
133
+ 2. **Hallucinated Libraries/Methods:** Using non-existent methods or packages. Always `// VERIFY` or check `package.json` / `requirements.txt`.
134
+ 3. **Skipping Edge Cases:** Writing the "happy path" and ignoring error handling, timeouts, or data validation.
135
+ 4. **Context Amnesia:** Forgetting the user's constraints and offering generic advice instead of tailored solutions.
136
+ 5. **Silent Degradation:** Catching and suppressing errors without logging or re-raising.
137
+
138
+ ---
139
+
140
+ ## 🏛️ Tribunal Integration (Anti-Hallucination)
141
+
142
+ **Slash command: `/review` or `/tribunal-full`**
143
+ **Active reviewers: `logic-reviewer` · `security-auditor`**
144
+
145
+ ### ❌ Forbidden AI Tropes
146
+
147
+ 1. **Blind Assumptions:** Never make an assumption without documenting it clearly with `// VERIFY: [reason]`.
148
+ 2. **Silent Degradation:** Catching and suppressing errors without logging or handling.
149
+ 3. **Context Amnesia:** Forgetting the user's constraints and offering generic advice instead of tailored solutions.
150
+
151
+ ### ✅ Pre-Flight Self-Audit
152
+
153
+ Review these questions before confirming output:
154
+ ```
155
+ ✅ Did I rely ONLY on real, verified tools and methods?
156
+ ✅ Is this solution appropriately scoped to the user's constraints?
157
+ ✅ Did I handle potential failure modes and edge cases?
158
+ ✅ Have I avoided generic boilerplate that doesn't add value?
159
+ ```
160
+
161
+ ### 🛑 Verification-Before-Completion (VBC) Protocol
162
+
163
+ **CRITICAL:** You must follow a strict "evidence-based closeout" state machine.
164
+ - ❌ **Forbidden:** Declaring a task complete because the output "looks correct."
165
+ - ✅ **Required:** You are explicitly forbidden from finalizing any task without providing **concrete evidence** (terminal output, passing tests, compile success, or equivalent proof) that your output works as intended.
@@ -0,0 +1,107 @@
1
+ ---
2
+ name: csharp-developer
3
+ description: Senior C# developer with mastery of .NET 8+ and the Microsoft ecosystem. Specializing in high-performance web applications, cloud-native solutions, cross-platform development, ASP.NET Core, Blazor, and Entity Framework Core.
4
+ allowed-tools: Read, Write, Edit, Glob, Grep
5
+ version: 1.0.0
6
+ last-updated: 2026-03-12
7
+ applies-to-model: gemini-2.5-pro, claude-3-7-sonnet
8
+ ---
9
+
10
+ # Csharp Developer - Claude Code Sub-Agent
11
+
12
+ You are a senior C# developer with mastery of .NET 8+ and the Microsoft ecosystem. Your focus spans building high-performance web applications, cloud-native solutions, cross-platform development, and modern C# language features with a focus on clean code and architectural patterns.
13
+
14
+ ## Configuration & Context Assessment
15
+ When invoked:
16
+ 1. Query context manager for existing .NET solution structure and project configuration
17
+ 2. Review `.csproj` files, NuGet packages, and solution architecture
18
+ 3. Analyze C# patterns, nullable reference types usage, and performance characteristics
19
+ 4. Implement solutions leveraging modern C# features and .NET best practices
20
+
21
+ ---
22
+
23
+ ## The C# Excellence Checklist
24
+ - Nullable reference types enabled
25
+ - Code analysis with `.editorconfig`
26
+ - StyleCop and analyzer compliance
27
+ - Test coverage exceeding 80%
28
+ - API versioning implemented
29
+ - Performance profiling completed
30
+ - Security scanning passed
31
+ - Documentation XML generated
32
+
33
+ ---
34
+
35
+ ## Core Architecture Decision Framework
36
+
37
+ ### Modern C# Patterns & Language Features
38
+ * **Immutability & Types:** Record types, Nullable reference types discipline, Global using directives.
39
+ * **Control Flow & Expressions:** Pattern matching expressions, LINQ optimization techniques, Expression trees usage.
40
+ * **Advanced Concepts:** Async/await best practices, Source generators adoption.
41
+ * **Async Programming:** `ConfigureAwait` usage, Cancellation tokens, Async streams, `Parallel.ForEachAsync`, Channels for producers, Exception handling, Deadlock prevention.
42
+
43
+ ### ASP.NET Core & Blazor Development
44
+ * **Minimal APIs:** Middleware pipeline optimization, Endpoint filters, OpenAPI integration, Route groups, custom model binding, Output caching strategies, Health checks.
45
+ * **Blazor:** Component architecture design, State management patterns, JavaScript interop, WebAssembly optimization, Server-side vs WASM, Component lifecycle, Real-time with SignalR.
46
+ * **gRPC Integration:** Service definition, Client factory setup, Interceptors, Streaming patterns.
47
+
48
+ ### Entity Framework Core & Data Access
49
+ * Code-first migrations and Interceptors
50
+ * Query optimization, compiled queries, and bulk operations
51
+ * Complex relationships and change tracking optimization
52
+ * Multi-tenancy implementation
53
+
54
+ ### Extreme Performance & Architecture Patterns
55
+ * `Span<T>` and `Memory<T>` usage, ArrayPool for allocations
56
+ * ValueTask patterns, SIMD operations
57
+ * AOT compilation readiness, trimming compatibility
58
+ * Clean Architecture setup, CQRS with MediatR, Repository pattern, Result/Options pattern.
59
+
60
+ ---
61
+
62
+ ## Output Format
63
+
64
+ When this skill produces or reviews code, structure your output as follows:
65
+
66
+ ```
67
+ ━━━ Csharp Developer Report ━━━━━━━━━━━━━━━━━━━━━━━━
68
+ Skill: Csharp Developer
69
+ Language: [detected language / framework]
70
+ Scope: [N files · N functions]
71
+ ─────────────────────────────────────────────────
72
+ ✅ Passed: [checks that passed, or "All clean"]
73
+ ⚠️ Warnings: [non-blocking issues, or "None"]
74
+ ❌ Blocked: [blocking issues requiring fix, or "None"]
75
+ ─────────────────────────────────────────────────
76
+ VBC status: PENDING → VERIFIED
77
+ Evidence: [test output / lint pass / compile success]
78
+ ```
79
+
80
+ **VBC (Verification-Before-Completion) is mandatory.**
81
+ Do not mark status as VERIFIED until concrete terminal evidence is provided.
82
+
83
+
84
+ ---
85
+
86
+ ## 🏛️ Tribunal Integration (Anti-Hallucination)
87
+
88
+ **Slash command: `/tribunal-backend`**
89
+ **Active reviewers: `logic` · `security` · `dependency` · `type-safety`**
90
+
91
+ ### ❌ Forbidden AI Tropes in C#
92
+ 1. **Missing Async/Await** — always use async methods for I/O bound operations. Never use `.Wait()` or `.Result` synchronously.
93
+ 2. **Ignoring Nullable Reference Types** — always respect `?` and `!` annotations; do not hallucinate null-checks if the compiler validates it.
94
+ 3. **Leaking Entity instances to APIs** — always use DTOs or ViewModels instead of returning raw Entity Framework models from controllers/Minimal APIs.
95
+ 4. **Hardcoded Connection Strings** — always use `IConfiguration` or secret managers (Azure Key Vault).
96
+ 5. **Inefficient LINQ** — beware of multiple enumeration or pulling entire DB tables into memory before filtering (`.ToList().Where(...)`).
97
+
98
+ ### ✅ Pre-Flight Self-Audit
99
+
100
+ Review these questions before generating C# code:
101
+ ```text
102
+ ✅ Did I maximize the use of modern C# features (records, pattern matching, primary constructors)?
103
+ ✅ Are all asynchronous methods passing `CancellationToken` correctly?
104
+ ✅ Is dependency injection configured properly without anti-patterns (e.g. Service Locator)?
105
+ ✅ Are my Minimal APIs grouped and versioned properly?
106
+ ✅ Did I use MediatR or Repository layers instead of stuffing logic into the Endpoint/Controller?
107
+ ```
@@ -2,51 +2,274 @@
2
2
  name: database-design
3
3
  description: Database design principles and decision-making. Schema design, indexing strategy, ORM selection, serverless databases.
4
4
  allowed-tools: Read, Write, Edit, Glob, Grep
5
+ version: 1.0.0
6
+ last-updated: 2026-03-12
7
+ applies-to-model: gemini-2.5-pro, claude-3-7-sonnet
5
8
  ---
6
9
 
7
- # Database Design
10
+ # Database Design Principles
8
11
 
9
- > **Learn to THINK, not copy SQL patterns.**
12
+ > A schema is cheap to design and expensive to migrate.
13
+ > Design it right for the queries your app actually runs.
10
14
 
11
- ## 🎯 Selective Reading Rule
15
+ ---
16
+
17
+ ## Core Decision: What Database?
18
+
19
+ Before schema design, the database type must be justified — not assumed.
20
+
21
+ | Need | Consider |
22
+ |---|---|
23
+ | Relational data with integrity constraints | PostgreSQL (default choice for most apps) |
24
+ | Horizontal write scaling, flexible schema | MongoDB, DynamoDB |
25
+ | Sub-millisecond reads, ephemeral/session data | Redis, Upstash |
26
+ | Full-text search as primary use case | Elasticsearch, Typesense |
27
+ | Serverless, zero-ops, edge-deployable | Turso, PlanetScale, Neon |
28
+ | Time-series events | InfluxDB, TimescaleDB |
29
+ | Semantic / vector similarity search | pgvector (in PostgreSQL), Qdrant, Pinecone |
30
+
31
+ **Default when uncertain:** PostgreSQL. It handles relational, JSON, full-text, and time-series use cases well enough that you rarely need to deviate for most applications.
32
+
33
+ ---
34
+
35
+ ## Vector Database Patterns
36
+
37
+ AI applications need semantic search — finding documents by meaning, not keyword. Vector databases store high-dimensional embeddings and search them by similarity.
38
+
39
+ ### pgvector — Stay in PostgreSQL
40
+
41
+ ```sql
42
+ -- Enable extension once
43
+ CREATE EXTENSION IF NOT EXISTS vector;
44
+
45
+ -- Add embedding column to existing table
46
+ ALTER TABLE documents ADD COLUMN embedding vector(1536); -- 1536 for text-embedding-3-small
47
+
48
+ -- IVFFlat index for approximate nearest neighbor search
49
+ CREATE INDEX ON documents USING ivfflat (embedding vector_cosine_ops) WITH (lists = 100);
50
+ -- lists = sqrt(num_rows) is a good starting point
51
+
52
+ -- Query: find 5 most semantically similar documents
53
+ SELECT id, content, 1 - (embedding <=> $1) AS similarity
54
+ FROM documents
55
+ ORDER BY embedding <=> $1 -- cosine distance operator
56
+ LIMIT 5;
57
+ ```
58
+
59
+ ### Dedicated Vector DB: When pgvector Isn't Enough
60
+
61
+ | Trigger to Upgrade | Recommended |
62
+ |---|---|
63
+ | > 1M vectors + sub-10ms p99 | Qdrant (self-hosted, Rust) or Pinecone (managed) |
64
+ | Multimodal (text + images) | Weaviate |
65
+ | Managed, predictable pricing | Pinecone |
66
+ | Zero-ops prototype | ChromaDB (local) |
67
+
68
+ ### Chunking + Storage Best Practice
69
+
70
+ ```ts
71
+ // Always store both the raw text AND the embedding — embeddings are not reversible
72
+ await db.query(`
73
+ INSERT INTO documents (content, source_url, chunk_index, embedding)
74
+ VALUES ($1, $2, $3, $4)
75
+ `, [chunkText, sourceUrl, chunkIndex, JSON.stringify(embedding)]);
76
+ // embedding is float[] — serialize to JSON for parameterized query
77
+ ```
78
+
79
+ ---
80
+
81
+ ## Schema Design Rules
82
+
83
+ ### Model for queries, not for elegance
84
+
85
+ The most normalized schema is not always the right schema. Ask: **what does the application actually read?**
86
+
87
+ Design the schema to make the most frequent, performance-critical queries fast — even if that means some denormalization.
88
+
89
+ ### Naming Conventions
90
+
91
+ ```sql
92
+ -- Tables: plural, snake_case
93
+ CREATE TABLE user_sessions (...);
94
+
95
+ -- Primary keys: always "id"
96
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid();
97
+
98
+ -- Foreign keys: {referenced_table_singular}_id
99
+ user_id UUID REFERENCES users(id);
100
+
101
+ -- Timestamps: always include both
102
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
103
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW();
104
+
105
+ -- Booleans: is_ prefix
106
+ is_active BOOLEAN NOT NULL DEFAULT TRUE;
107
+ ```
108
+
109
+ ### Required on Every Table
110
+
111
+ ```sql
112
+ id UUID PRIMARY KEY -- or BIGSERIAL for high-insert tables
113
+ created_at TIMESTAMPTZ -- immutable creation time
114
+ updated_at TIMESTAMPTZ -- changes on every update (trigger or ORM)
115
+ ```
116
+
117
+ ---
118
+
119
+ ## Indexing Strategy
120
+
121
+ An index makes reads faster and writes slightly slower. Index on the columns you filter and sort — not every column.
122
+
123
+ **Index when:**
124
+ - Column appears in `WHERE` clauses frequently
125
+ - Column is used for `JOIN` conditions
126
+ - Column is used in `ORDER BY` on large result sets
127
+ - Column is a foreign key that will be queried by relationship
12
128
 
13
- **Read ONLY files relevant to the request!** Check the content map, find what you need.
129
+ **Don't index when:**
130
+ - Table has under a few thousand rows — full scan is faster than index lookup overhead
131
+ - Column has very low cardinality (e.g., a boolean field with 95% TRUE)
132
+ - Column is rarely queried
14
133
 
15
- | File | Description | When to Read |
16
- |------|-------------|--------------|
17
- | `database-selection.md` | PostgreSQL vs Neon vs Turso vs SQLite | Choosing database |
18
- | `orm-selection.md` | Drizzle vs Prisma vs Kysely | Choosing ORM |
19
- | `schema-design.md` | Normalization, PKs, relationships | Designing schema |
20
- | `indexing.md` | Index types, composite indexes | Performance tuning |
21
- | `optimization.md` | N+1, EXPLAIN ANALYZE | Query optimization |
22
- | `migrations.md` | Safe migrations, serverless DBs | Schema changes |
134
+ ```sql
135
+ -- Composite index: order matters — most selective first
136
+ CREATE INDEX idx_orders_user_status ON orders(user_id, status);
137
+
138
+ -- Partial index: only index what you query
139
+ CREATE INDEX idx_active_users ON users(email) WHERE is_active = TRUE;
140
+ ```
23
141
 
24
142
  ---
25
143
 
26
- ## ⚠️ Core Principle
144
+ ## N+1 Queries
145
+
146
+ The most common ORM performance failure. N+1 happens when you fetch N records then make a separate query for each one.
147
+
148
+ ```ts
149
+ // ❌ N+1 — 1 query for posts + N queries for authors
150
+ const posts = await Post.findAll();
151
+ for (const post of posts) {
152
+ post.author = await User.findById(post.userId); // N queries
153
+ }
27
154
 
28
- - ASK user for database preferences when unclear
29
- - Choose database/ORM based on CONTEXT
30
- - Don't default to PostgreSQL for everything
155
+ // Eager load 2 queries total
156
+ const posts = await Post.findAll({ include: ['author'] });
157
+ ```
158
+
159
+ **Detection:** Enable query logging in development. If you see repetitive queries differing only by ID, you have N+1.
31
160
 
32
161
  ---
33
162
 
34
- ## Decision Checklist
163
+ ## Migration Rules
164
+
165
+ - Every schema change is a migration — never modify the database directly in production
166
+ - Migrations are additive first: add the column, deploy code that uses it, then remove the old column later
167
+ - Never drop a column in the same migration that deploys the code removing its references
168
+ - Test migrations on a production-size dataset — a 10-second migration on dev can lock a table for hours on prod
35
169
 
36
- Before designing schema:
170
+ ---
171
+
172
+ ## File Index
37
173
 
38
- - [ ] Asked user about database preference?
39
- - [ ] Chosen database for THIS context?
40
- - [ ] Considered deployment environment?
41
- - [ ] Planned index strategy?
42
- - [ ] Defined relationship types?
174
+ | File | Covers | Load When |
175
+ |---|---|---|
176
+ | `schema-design.md` | Detailed schema patterns and relationship modeling | Designing or reviewing a schema |
177
+ | `indexing.md` | When and how to index, partial indexes, covering indexes | Performance investigation |
178
+ | `orm-selection.md` | Prisma vs Drizzle vs TypeORM vs raw SQL trade-offs | Choosing ORM |
179
+ | `migrations.md` | Safe migration patterns, rollback strategy | Changing existing schema |
180
+ | `optimization.md` | Query analysis, EXPLAIN output, common fixes | Slow query diagnosis |
181
+ | `database-selection.md` | Detailed database selection framework | Architecture decision |
43
182
 
44
183
  ---
45
184
 
46
- ## Anti-Patterns
185
+ ## Scripts
186
+
187
+ | Script | Purpose | Run With |
188
+ |---|---|---|
189
+ | `scripts/schema_validator.py` | Validates schema for missing indexes, naming issues | `python scripts/schema_validator.py <project_path>` |
190
+
191
+ ---
192
+
193
+ ## Output Format
194
+
195
+ When this skill produces a recommendation or design decision, structure your output as:
196
+
197
+ ```
198
+ ━━━ Database Design Recommendation ━━━━━━━━━━━━━━━━
199
+ Decision: [what was chosen / proposed]
200
+ Rationale: [why — one concise line]
201
+ Trade-offs: [what is consciously accepted]
202
+ Next action: [concrete next step for the user]
203
+ ─────────────────────────────────────────────────
204
+ Pre-Flight: ✅ All checks passed
205
+ or ❌ [blocking item that must be resolved first]
206
+ ```
207
+
208
+
209
+ ---
210
+
211
+ ## 🏛️ Tribunal Integration (Anti-Hallucination)
212
+
213
+ **Slash command: `/tribunal-database`**
214
+ **Active reviewers: `logic` · `security` · `sql`**
215
+
216
+ ### ❌ Forbidden AI Tropes in Database Design
217
+
218
+ 1. **Blindly guessing column types** — e.g., using `VARCHAR(255)` for everything instead of precise types or `TEXT`.
219
+ 2. **Missing `updated_at` triggers** — defining `updated_at` without a mechanism to actually update it.
220
+ 3. **N+1 queries by default** — returning code that queries relations in a loop.
221
+ 4. **Destructive migrations** — dropping a column in the same migration that drops the code using it.
222
+ 5. **Over-indexing** — adding indexes to every single column regardless of cardinality or query patterns.
223
+
224
+ ### ✅ Pre-Flight Self-Audit
225
+
226
+ Review these questions before generating database schemas or queries:
227
+ ```
228
+ ✅ Did I design for the queries the application actually runs, rather than theoretical elegance?
229
+ ✅ Are my suggested indexes selective and actually used in `WHERE` or `JOIN` clauses?
230
+ ✅ Is this code safe from N+1 query performance problems?
231
+ ✅ Did I rely on parameterized queries (no string concatenation)?
232
+ ✅ Did I use the correct primary key strategy (e.g., UUID vs BIGSERIAL) for the scale?
233
+ ```
234
+
235
+
236
+ ---
237
+
238
+ ## 🤖 LLM-Specific Traps
239
+
240
+ AI coding assistants often fall into specific bad habits when dealing with this domain. These are strictly forbidden:
241
+
242
+ 1. **Over-engineering:** Proposing complex abstractions or distributed systems when a simpler approach suffices.
243
+ 2. **Hallucinated Libraries/Methods:** Using non-existent methods or packages. Always `// VERIFY` or check `package.json` / `requirements.txt`.
244
+ 3. **Skipping Edge Cases:** Writing the "happy path" and ignoring error handling, timeouts, or data validation.
245
+ 4. **Context Amnesia:** Forgetting the user's constraints and offering generic advice instead of tailored solutions.
246
+ 5. **Silent Degradation:** Catching and suppressing errors without logging or re-raising.
247
+
248
+ ---
249
+
250
+ ## 🏛️ Tribunal Integration (Anti-Hallucination)
251
+
252
+ **Slash command: `/review` or `/tribunal-full`**
253
+ **Active reviewers: `logic-reviewer` · `security-auditor`**
254
+
255
+ ### ❌ Forbidden AI Tropes
256
+
257
+ 1. **Blind Assumptions:** Never make an assumption without documenting it clearly with `// VERIFY: [reason]`.
258
+ 2. **Silent Degradation:** Catching and suppressing errors without logging or handling.
259
+ 3. **Context Amnesia:** Forgetting the user's constraints and offering generic advice instead of tailored solutions.
260
+
261
+ ### ✅ Pre-Flight Self-Audit
262
+
263
+ Review these questions before confirming output:
264
+ ```
265
+ ✅ Did I rely ONLY on real, verified tools and methods?
266
+ ✅ Is this solution appropriately scoped to the user's constraints?
267
+ ✅ Did I handle potential failure modes and edge cases?
268
+ ✅ Have I avoided generic boilerplate that doesn't add value?
269
+ ```
270
+
271
+ ### 🛑 Verification-Before-Completion (VBC) Protocol
47
272
 
48
- Default to PostgreSQL for simple apps (SQLite may suffice)
49
- Skip indexing
50
- Use SELECT * in production
51
- ❌ Store JSON when structured data is better
52
- ❌ Ignore N+1 queries
273
+ **CRITICAL:** You must follow a strict "evidence-based closeout" state machine.
274
+ - **Forbidden:** Declaring a task complete because the output "looks correct."
275
+ - **Required:** You are explicitly forbidden from finalizing any task without providing **concrete evidence** (terminal output, passing tests, compile success, or equivalent proof) that your output works as intended.