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.
Files changed (250) hide show
  1. package/.agent/ARCHITECTURE.md +99 -99
  2. package/.agent/GEMINI.md +52 -52
  3. package/.agent/agents/accessibility-reviewer.md +139 -86
  4. package/.agent/agents/ai-code-reviewer.md +160 -90
  5. package/.agent/agents/backend-specialist.md +164 -127
  6. package/.agent/agents/code-archaeologist.md +115 -73
  7. package/.agent/agents/database-architect.md +130 -110
  8. package/.agent/agents/debugger.md +137 -97
  9. package/.agent/agents/dependency-reviewer.md +78 -30
  10. package/.agent/agents/devops-engineer.md +161 -118
  11. package/.agent/agents/documentation-writer.md +151 -87
  12. package/.agent/agents/explorer-agent.md +117 -99
  13. package/.agent/agents/frontend-reviewer.md +127 -47
  14. package/.agent/agents/frontend-specialist.md +169 -109
  15. package/.agent/agents/game-developer.md +28 -164
  16. package/.agent/agents/logic-reviewer.md +87 -49
  17. package/.agent/agents/mobile-developer.md +151 -103
  18. package/.agent/agents/mobile-reviewer.md +133 -50
  19. package/.agent/agents/orchestrator.md +121 -110
  20. package/.agent/agents/penetration-tester.md +103 -77
  21. package/.agent/agents/performance-optimizer.md +136 -92
  22. package/.agent/agents/performance-reviewer.md +139 -69
  23. package/.agent/agents/product-manager.md +104 -70
  24. package/.agent/agents/product-owner.md +6 -25
  25. package/.agent/agents/project-planner.md +95 -95
  26. package/.agent/agents/qa-automation-engineer.md +174 -87
  27. package/.agent/agents/security-auditor.md +133 -129
  28. package/.agent/agents/seo-specialist.md +160 -99
  29. package/.agent/agents/sql-reviewer.md +132 -44
  30. package/.agent/agents/supervisor-agent.md +137 -109
  31. package/.agent/agents/swarm-worker-contracts.md +17 -17
  32. package/.agent/agents/swarm-worker-registry.md +46 -46
  33. package/.agent/agents/test-coverage-reviewer.md +132 -53
  34. package/.agent/agents/test-engineer.md +0 -21
  35. package/.agent/agents/type-safety-reviewer.md +143 -33
  36. package/.agent/patterns/generator.md +9 -9
  37. package/.agent/patterns/inversion.md +12 -12
  38. package/.agent/patterns/pipeline.md +9 -9
  39. package/.agent/patterns/reviewer.md +13 -13
  40. package/.agent/patterns/tool-wrapper.md +9 -9
  41. package/.agent/rules/GEMINI.md +63 -63
  42. package/.agent/scripts/__pycache__/auto_preview.cpython-311.pyc +0 -0
  43. package/.agent/scripts/__pycache__/bundle_analyzer.cpython-311.pyc +0 -0
  44. package/.agent/scripts/__pycache__/checklist.cpython-311.pyc +0 -0
  45. package/.agent/scripts/__pycache__/dependency_analyzer.cpython-311.pyc +0 -0
  46. package/.agent/scripts/__pycache__/security_scan.cpython-311.pyc +0 -0
  47. package/.agent/scripts/__pycache__/session_manager.cpython-311.pyc +0 -0
  48. package/.agent/scripts/__pycache__/skill_integrator.cpython-311.pyc +0 -0
  49. package/.agent/scripts/__pycache__/swarm_dispatcher.cpython-311.pyc +0 -0
  50. package/.agent/scripts/__pycache__/test_runner.cpython-311.pyc +0 -0
  51. package/.agent/scripts/__pycache__/verify_all.cpython-311.pyc +0 -0
  52. package/.agent/scripts/compress_skills.py +167 -0
  53. package/.agent/scripts/consolidate_skills.py +173 -0
  54. package/.agent/scripts/deep_compress.py +202 -0
  55. package/.agent/scripts/minify_context.py +80 -0
  56. package/.agent/scripts/security_scan.py +1 -1
  57. package/.agent/scripts/strip_tribunal.py +41 -0
  58. package/.agent/skills/agent-organizer/SKILL.md +60 -100
  59. package/.agent/skills/agentic-patterns/SKILL.md +0 -70
  60. package/.agent/skills/ai-prompt-injection-defense/SKILL.md +108 -53
  61. package/.agent/skills/api-patterns/SKILL.md +197 -257
  62. package/.agent/skills/api-security-auditor/SKILL.md +125 -57
  63. package/.agent/skills/app-builder/SKILL.md +326 -50
  64. package/.agent/skills/app-builder/templates/SKILL.md +13 -15
  65. package/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +16 -16
  66. package/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +22 -22
  67. package/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +18 -18
  68. package/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +20 -20
  69. package/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +17 -17
  70. package/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +18 -18
  71. package/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +21 -21
  72. package/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +19 -19
  73. package/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +26 -26
  74. package/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +26 -26
  75. package/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +19 -19
  76. package/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +18 -18
  77. package/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +20 -20
  78. package/.agent/skills/appflow-wireframe/SKILL.md +71 -98
  79. package/.agent/skills/architecture/SKILL.md +161 -200
  80. package/.agent/skills/authentication-best-practices/SKILL.md +121 -54
  81. package/.agent/skills/bash-linux/SKILL.md +71 -166
  82. package/.agent/skills/behavioral-modes/SKILL.md +8 -69
  83. package/.agent/skills/brainstorming/SKILL.md +345 -127
  84. package/.agent/skills/building-native-ui/SKILL.md +125 -57
  85. package/.agent/skills/clean-code/SKILL.md +266 -149
  86. package/.agent/skills/code-review-checklist/SKILL.md +0 -62
  87. package/.agent/skills/config-validator/SKILL.md +73 -131
  88. package/.agent/skills/csharp-developer/SKILL.md +434 -73
  89. package/.agent/skills/database-design/SKILL.md +190 -275
  90. package/.agent/skills/deployment-procedures/SKILL.md +81 -158
  91. package/.agent/skills/devops-engineer/SKILL.md +255 -94
  92. package/.agent/skills/devops-incident-responder/SKILL.md +50 -69
  93. package/.agent/skills/doc.md +5 -5
  94. package/.agent/skills/documentation-templates/SKILL.md +19 -63
  95. package/.agent/skills/edge-computing/SKILL.md +75 -165
  96. package/.agent/skills/extract-design-system/SKILL.md +84 -58
  97. package/.agent/skills/framer-motion-expert/SKILL.md +195 -0
  98. package/.agent/skills/frontend-design/SKILL.md +151 -499
  99. package/.agent/skills/game-design-expert/SKILL.md +71 -0
  100. package/.agent/skills/game-engineering-expert/SKILL.md +88 -0
  101. package/.agent/skills/geo-fundamentals/SKILL.md +52 -178
  102. package/.agent/skills/github-operations/SKILL.md +197 -272
  103. package/.agent/skills/gsap-expert/SKILL.md +194 -0
  104. package/.agent/skills/i18n-localization/SKILL.md +60 -172
  105. package/.agent/skills/intelligent-routing/SKILL.md +123 -103
  106. package/.agent/skills/lint-and-validate/SKILL.md +8 -52
  107. package/.agent/skills/llm-engineering/SKILL.md +281 -195
  108. package/.agent/skills/local-first/SKILL.md +76 -159
  109. package/.agent/skills/mcp-builder/SKILL.md +48 -188
  110. package/.agent/skills/mobile-design/SKILL.md +213 -219
  111. package/.agent/skills/motion-engineering/SKILL.md +184 -0
  112. package/.agent/skills/nextjs-react-expert/SKILL.md +184 -203
  113. package/.agent/skills/nodejs-best-practices/SKILL.md +403 -185
  114. package/.agent/skills/observability/SKILL.md +211 -203
  115. package/.agent/skills/parallel-agents/SKILL.md +53 -146
  116. package/.agent/skills/performance-profiling/SKILL.md +171 -151
  117. package/.agent/skills/plan-writing/SKILL.md +49 -153
  118. package/.agent/skills/platform-engineer/SKILL.md +57 -103
  119. package/.agent/skills/playwright-best-practices/SKILL.md +110 -63
  120. package/.agent/skills/powershell-windows/SKILL.md +61 -179
  121. package/.agent/skills/python-patterns/SKILL.md +7 -35
  122. package/.agent/skills/python-pro/SKILL.md +273 -114
  123. package/.agent/skills/react-specialist/SKILL.md +227 -108
  124. package/.agent/skills/readme-builder/SKILL.md +15 -85
  125. package/.agent/skills/realtime-patterns/SKILL.md +216 -243
  126. package/.agent/skills/red-team-tactics/SKILL.md +10 -51
  127. package/.agent/skills/rust-pro/SKILL.md +525 -142
  128. package/.agent/skills/seo-fundamentals/SKILL.md +92 -153
  129. package/.agent/skills/server-management/SKILL.md +110 -166
  130. package/.agent/skills/shadcn-ui-expert/SKILL.md +154 -55
  131. package/.agent/skills/skill-creator/SKILL.md +18 -58
  132. package/.agent/skills/sql-pro/SKILL.md +543 -68
  133. package/.agent/skills/supabase-postgres-best-practices/SKILL.md +28 -68
  134. package/.agent/skills/swiftui-expert/SKILL.md +124 -57
  135. package/.agent/skills/systematic-debugging/SKILL.md +49 -151
  136. package/.agent/skills/tailwind-patterns/SKILL.md +433 -149
  137. package/.agent/skills/tdd-workflow/SKILL.md +63 -169
  138. package/.agent/skills/test-result-analyzer/SKILL.md +33 -73
  139. package/.agent/skills/testing-patterns/SKILL.md +437 -130
  140. package/.agent/skills/trend-researcher/SKILL.md +30 -71
  141. package/.agent/skills/ui-ux-pro-max/SKILL.md +0 -41
  142. package/.agent/skills/ui-ux-researcher/SKILL.md +51 -91
  143. package/.agent/skills/vue-expert/SKILL.md +225 -119
  144. package/.agent/skills/vulnerability-scanner/SKILL.md +264 -226
  145. package/.agent/skills/web-accessibility-auditor/SKILL.md +141 -58
  146. package/.agent/skills/web-design-guidelines/SKILL.md +17 -61
  147. package/.agent/skills/webapp-testing/SKILL.md +71 -196
  148. package/.agent/skills/whimsy-injector/SKILL.md +58 -132
  149. package/.agent/skills/workflow-optimizer/SKILL.md +28 -68
  150. package/.agent/workflows/api-tester.md +96 -224
  151. package/.agent/workflows/audit.md +81 -122
  152. package/.agent/workflows/brainstorm.md +69 -105
  153. package/.agent/workflows/changelog.md +65 -97
  154. package/.agent/workflows/create.md +73 -88
  155. package/.agent/workflows/debug.md +80 -111
  156. package/.agent/workflows/deploy.md +119 -92
  157. package/.agent/workflows/enhance.md +80 -91
  158. package/.agent/workflows/fix.md +68 -97
  159. package/.agent/workflows/generate.md +165 -164
  160. package/.agent/workflows/migrate.md +106 -109
  161. package/.agent/workflows/orchestrate.md +103 -86
  162. package/.agent/workflows/performance-benchmarker.md +77 -268
  163. package/.agent/workflows/plan.md +120 -98
  164. package/.agent/workflows/preview.md +39 -96
  165. package/.agent/workflows/refactor.md +105 -97
  166. package/.agent/workflows/review-ai.md +63 -102
  167. package/.agent/workflows/review.md +71 -110
  168. package/.agent/workflows/session.md +53 -113
  169. package/.agent/workflows/status.md +42 -88
  170. package/.agent/workflows/strengthen-skills.md +90 -51
  171. package/.agent/workflows/swarm.md +114 -129
  172. package/.agent/workflows/test.md +125 -102
  173. package/.agent/workflows/tribunal-backend.md +60 -78
  174. package/.agent/workflows/tribunal-database.md +62 -100
  175. package/.agent/workflows/tribunal-frontend.md +62 -82
  176. package/.agent/workflows/tribunal-full.md +56 -100
  177. package/.agent/workflows/tribunal-mobile.md +65 -94
  178. package/.agent/workflows/tribunal-performance.md +62 -105
  179. package/.agent/workflows/ui-ux-pro-max.md +72 -121
  180. package/README.md +11 -15
  181. package/package.json +1 -1
  182. package/.agent/skills/api-patterns/api-style.md +0 -42
  183. package/.agent/skills/api-patterns/auth.md +0 -24
  184. package/.agent/skills/api-patterns/documentation.md +0 -26
  185. package/.agent/skills/api-patterns/graphql.md +0 -41
  186. package/.agent/skills/api-patterns/rate-limiting.md +0 -31
  187. package/.agent/skills/api-patterns/response.md +0 -37
  188. package/.agent/skills/api-patterns/rest.md +0 -40
  189. package/.agent/skills/api-patterns/security-testing.md +0 -122
  190. package/.agent/skills/api-patterns/trpc.md +0 -41
  191. package/.agent/skills/api-patterns/versioning.md +0 -22
  192. package/.agent/skills/app-builder/agent-coordination.md +0 -71
  193. package/.agent/skills/app-builder/feature-building.md +0 -53
  194. package/.agent/skills/app-builder/project-detection.md +0 -34
  195. package/.agent/skills/app-builder/scaffolding.md +0 -118
  196. package/.agent/skills/app-builder/tech-stack.md +0 -40
  197. package/.agent/skills/architecture/context-discovery.md +0 -43
  198. package/.agent/skills/architecture/examples.md +0 -94
  199. package/.agent/skills/architecture/pattern-selection.md +0 -68
  200. package/.agent/skills/architecture/patterns-reference.md +0 -50
  201. package/.agent/skills/architecture/trade-off-analysis.md +0 -77
  202. package/.agent/skills/brainstorming/dynamic-questioning.md +0 -360
  203. package/.agent/skills/database-design/database-selection.md +0 -43
  204. package/.agent/skills/database-design/indexing.md +0 -39
  205. package/.agent/skills/database-design/migrations.md +0 -48
  206. package/.agent/skills/database-design/optimization.md +0 -36
  207. package/.agent/skills/database-design/orm-selection.md +0 -30
  208. package/.agent/skills/database-design/schema-design.md +0 -56
  209. package/.agent/skills/dotnet-core-expert/SKILL.md +0 -103
  210. package/.agent/skills/framer-motion-animations/SKILL.md +0 -74
  211. package/.agent/skills/frontend-design/animation-guide.md +0 -331
  212. package/.agent/skills/frontend-design/color-system.md +0 -329
  213. package/.agent/skills/frontend-design/decision-trees.md +0 -418
  214. package/.agent/skills/frontend-design/motion-graphics.md +0 -306
  215. package/.agent/skills/frontend-design/typography-system.md +0 -363
  216. package/.agent/skills/frontend-design/ux-psychology.md +0 -1116
  217. package/.agent/skills/frontend-design/visual-effects.md +0 -383
  218. package/.agent/skills/game-development/2d-games/SKILL.md +0 -119
  219. package/.agent/skills/game-development/3d-games/SKILL.md +0 -135
  220. package/.agent/skills/game-development/SKILL.md +0 -236
  221. package/.agent/skills/game-development/game-art/SKILL.md +0 -185
  222. package/.agent/skills/game-development/game-audio/SKILL.md +0 -190
  223. package/.agent/skills/game-development/game-design/SKILL.md +0 -129
  224. package/.agent/skills/game-development/mobile-games/SKILL.md +0 -108
  225. package/.agent/skills/game-development/multiplayer/SKILL.md +0 -132
  226. package/.agent/skills/game-development/pc-games/SKILL.md +0 -144
  227. package/.agent/skills/game-development/vr-ar/SKILL.md +0 -123
  228. package/.agent/skills/game-development/web-games/SKILL.md +0 -150
  229. package/.agent/skills/intelligent-routing/router-manifest.md +0 -65
  230. package/.agent/skills/mobile-design/decision-trees.md +0 -516
  231. package/.agent/skills/mobile-design/mobile-backend.md +0 -491
  232. package/.agent/skills/mobile-design/mobile-color-system.md +0 -420
  233. package/.agent/skills/mobile-design/mobile-debugging.md +0 -122
  234. package/.agent/skills/mobile-design/mobile-design-thinking.md +0 -357
  235. package/.agent/skills/mobile-design/mobile-navigation.md +0 -458
  236. package/.agent/skills/mobile-design/mobile-performance.md +0 -767
  237. package/.agent/skills/mobile-design/mobile-testing.md +0 -356
  238. package/.agent/skills/mobile-design/mobile-typography.md +0 -433
  239. package/.agent/skills/mobile-design/platform-android.md +0 -666
  240. package/.agent/skills/mobile-design/platform-ios.md +0 -561
  241. package/.agent/skills/mobile-design/touch-psychology.md +0 -537
  242. package/.agent/skills/nextjs-react-expert/1-async-eliminating-waterfalls.md +0 -312
  243. package/.agent/skills/nextjs-react-expert/2-bundle-bundle-size-optimization.md +0 -240
  244. package/.agent/skills/nextjs-react-expert/3-server-server-side-performance.md +0 -490
  245. package/.agent/skills/nextjs-react-expert/4-client-client-side-data-fetching.md +0 -264
  246. package/.agent/skills/nextjs-react-expert/5-rerender-re-render-optimization.md +0 -581
  247. package/.agent/skills/nextjs-react-expert/6-rendering-rendering-performance.md +0 -432
  248. package/.agent/skills/nextjs-react-expert/7-js-javascript-performance.md +0 -684
  249. package/.agent/skills/nextjs-react-expert/8-advanced-advanced-patterns.md +0 -150
  250. package/.agent/skills/vulnerability-scanner/checklists.md +0 -121
@@ -1,203 +1,120 @@
1
1
  ---
2
2
  name: local-first
3
- description: Local-first software principles. Offline-capable apps, CRDTs, sync engines (ElectricSQL, Replicache, Zero), conflict resolution, and the migration path from REST-first to local-first architecture. Use when building apps that need offline support, fast UI, or collaborative editing.
3
+ description: Local-first software architecture mastery. CRDTs (Conflict-free Replicated Data Types), IndexedDB synchronization, sync engines (ElectricSQL, Replicache, PowerSync), offline-capable data fetching, optimistic UI, and SQLite in the browser (WASM). Use when building PWA offline capabilities, rapid UIs, or multiplayer collaborative tools.
4
4
  allowed-tools: Read, Write, Edit, Glob, Grep
5
- version: 1.0.0
6
- last-updated: 2026-03-12
5
+ version: 2.0.0
6
+ last-updated: 2026-04-02
7
7
  applies-to-model: gemini-2.5-pro, claude-3-7-sonnet
8
8
  ---
9
9
 
10
- # Local-First Software Principles
11
-
12
- > In a local-first app, the network is an enhancement, not a requirement.
13
- > The app works fully offline. Sync happens in the background when possible.
10
+ # Local-First Architecture — Offline-capable Mastery
14
11
 
15
12
  ---
16
13
 
17
- ## The Local-First Promise
14
+ ## 1. Core Principles of Local-First
18
15
 
19
- Local-first apps satisfy all of these simultaneously traditional web apps satisfy none:
16
+ In a Cloud-First app (REST/GraphQL), the UI waits for the server.
17
+ In a Local-First app, the UI talks *only* to a local database. A background engine syncs that database to the cloud when online.
20
18
 
21
- ```
22
- Fast UI — reads from local replica, never waits for network
23
- Offline use — full functionality without internet
24
- ✅ Collaboration — multiple users edit the same data
25
- ✅ Privacy — data lives on device by default
26
- ✅ Longevity — app works even if vendor servers go down
27
- ```
19
+ 1. **Fast by default**: Zero network latency because reads/writes happen locally.
20
+ 2. **Offline works flawlessly**: The app bounds to a local store (SQLite via WASM, IndexedDB).
21
+ 3. **Multi-device Sync**: Conflict resolution is handled natively (usually via CRDTs or central conflict ledgers).
28
22
 
29
23
  ---
30
24
 
31
- ## Architecture Spectrum
25
+ ## 2. Sync Engines vs traditional fetching
32
26
 
33
- ```
34
- REST-First (most apps today):
35
- Client → HTTP → Server → DB
36
- Offline: ❌ Speed: Network-bound Collaboration: Manual
27
+ Do not use React Query / SWR to build local-first. They are HTTP caching mechanisms.
37
28
 
38
- Optimistic UI (halfway):
39
- Client Local cache HTTP → Server → DB
40
- Offline: Partial Speed: Fast for reads Collaboration: Conflict-prone
29
+ ```typescript
30
+ // CLOUD-FIRST (React Query / Fetch)
31
+ // Fails when offline. Subject to UI latency.
32
+ const { data, isLoading } = useQuery({
33
+ queryKey: ['todos'],
34
+ queryFn: () => fetch('/api/todos').then(res => res.json())
35
+ })
41
36
 
42
- Local-First:
43
- Client Local replica (SQLite/CRDT) Sync engine Server → DB
44
- Offline: ✅ Speed: Instant Collaboration: via CRDTs
45
- ```
37
+ // ✅ LOCAL-FIRST (e.g. PowerSync / ElectricSQL / WatermelonDB)
38
+ // Resolves instantly. Data lives locally. Syncs silently in background.
39
+ import { useQuery } from '@powersync/react';
46
40
 
47
- ---
48
-
49
- ## Sync Engine Selection
41
+ const { data, isLoading } = useQuery('SELECT * FROM todos ORDER BY created_at DESC');
50
42
 
51
- Choose based on your database, team size, and product requirements:
52
-
53
- | Engine | Sync Model | Database | Best For |
54
- |---|---|---|---|
55
- | **ElectricSQL** | Postgres SQLite on client | PostgreSQL only | Postgres-native teams |
56
- | **Replicache** | Mutation log + pull | Any backend | Custom sync logic needed |
57
- | **Zero (Rocicorp)** | Reactive queries | PostgreSQL | Real-time apps, Figma-speed UIs |
58
- | **Liveblocks** | CRDT + storage API | Managed | Collaborative SaaS (no own server) |
59
- | **Yjs + y-indexeddb** | CRDT + local persistence | Any | Text editing, whiteboard |
43
+ // Writes are also local First
44
+ const addTodo = async (text: string) => {
45
+ // Written to the local SQLite WASM database instantly.
46
+ await localDb.execute('INSERT INTO todos (id, text) VALUES (uuid(), ?)', [text]);
47
+ // Background worker syncs to Postgres later.
48
+ }
49
+ ```
60
50
 
61
51
  ---
62
52
 
63
- ## CRDT Choices
64
-
65
- CRDTs (Conflict-free Replicated Data Types) resolve concurrent edits mathematically — no server arbitration needed:
53
+ ## 3. Conflict Resolution (CRDTs)
66
54
 
67
- | CRDT Type | Use For | Library |
68
- |---|---|---|
69
- | **LWW Register** | Scalar values (settings, status) | Built-in or custom |
70
- | **G-Counter** | Incrementing counters (likes, views) | Custom |
71
- | **OR-Set** | Sets that support add + remove | Yjs `Y.Array` |
72
- | **Y.Text** | Collaborative rich text | Yjs |
73
- | **Y.Map** | Shared key-value state | Yjs |
55
+ When two users edit the exact same document offline and then reconnect, how is it resolved?
74
56
 
75
- ```ts
76
- import * as Y from 'yjs';
77
- import { IndexeddbPersistence } from 'y-indexeddb';
57
+ **Conflict-free Replicated Data Types (CRDTs)** automatically merge data without requiring a central server to decide the "winner."
78
58
 
79
- const doc = new Y.Doc();
59
+ ```typescript
60
+ // Yjs - The leading CRDT library for collaborative text/state
61
+ import * as Y from 'yjs'
62
+ import { WebsocketProvider } from 'y-websocket'
80
63
 
81
- // Persist to IndexedDB — survives page reload, works offline
82
- new IndexeddbPersistence('my-doc-id', doc);
64
+ const ydoc = new Y.Doc()
65
+ const provider = new WebsocketProvider('wss://sync.example.com', 'room-1', ydoc)
83
66
 
84
- // Shared text — any concurrent edits from any user auto-merge
85
- const text = doc.getText('content');
86
- text.insert(0, 'Hello '); // User A
87
- text.insert(6, 'World'); // User B — concurrent, no conflict
88
- // Result: "Hello World" — always correct, always the same
89
- ```
90
-
91
- ---
67
+ // Shared state array
68
+ const yarray = ydoc.getArray('todos')
92
69
 
93
- ## Optimistic UI Patterns
70
+ // Observe changes (Fires locally and when peers sync)
71
+ yarray.observe(event => {
72
+ console.log("State updated natively without conflict:", yarray.toArray())
73
+ })
94
74
 
95
- Before full local-first, optimistic UI gives most of the speed benefit:
96
-
97
- ```ts
98
- // ❌ Pessimistic — user waits for server response before any UI update
99
- async function likePost(postId: string) {
100
- const updated = await api.likePost(postId); // 200ms wait → UI freezes
101
- setPost(updated);
102
- }
103
-
104
- // ✅ Optimistic — update UI immediately, sync in background
105
- async function likePost(postId: string) {
106
- // 1. Instant UI update
107
- setPost(prev => ({ ...prev, likes: prev.likes + 1, liked: true }));
108
-
109
- try {
110
- // 2. Sync to server in background
111
- await api.likePost(postId);
112
- } catch {
113
- // 3. Rollback on failure
114
- setPost(prev => ({ ...prev, likes: prev.likes - 1, liked: false }));
115
- toast.error('Failed to like post');
116
- }
117
- }
75
+ // Insert data (Instantly merges cleanly with remote peers)
76
+ yarray.insert(0, ['Buy milk'])
118
77
  ```
119
78
 
120
79
  ---
121
80
 
122
- ## Conflict Resolution Strategies
81
+ ## 4. In-Browser Databases
123
82
 
124
- When two users edit the same data offline and then sync:
83
+ Storing megabytes of relational data in `localStorage` will crash the browser.
125
84
 
126
- | Strategy | When to Use | Downside |
127
- |---|---|---|
128
- | **Last-Write-Wins (LWW)** | Settings, preferences | Concurrent edits silently overwrite each other |
129
- | **First-Write-Wins** | Booking/reservation slots | Rejecters unhappy, complex UX |
130
- | **CRDT merge** | Text, lists, collaborative state | Complex to implement from scratch — use Yjs |
131
- | **3-way merge** | Code files, configs | Requires common ancestor to compute diff |
132
- | **User-prompted resolution** | Critical data (contracts) | Adds friction but preserves intent |
85
+ |Technology|Use Case|Pros|Cons|
86
+ |:---|:---|:---|:---|
87
+ |**IndexedDB**|Key-Value|Native to browser|Hideous callback API, weak querying|
88
+ |**Dexie.js**|Key-Value|Wraps IndexedDB with clean Promises|Not relational|
89
+ |**SQLite WASM (OPFS)**|Relational|True SQL in browser|Setup complexity (Origin Private File System)|
90
+ |**RxDB**|NoSQL Offline|Reactive UI out-of-the-box|Requires learning RxJS/Observables|
91
+ |**WatermelonDB**|Relational|Built for React Native & Web|Requires native module setup on mobile|
133
92
 
134
- ---
135
-
136
- ## Migration Path: REST Local-First
137
-
138
- Don't try to go from REST to full local-first in one step:
93
+ ```typescript
94
+ // Clean IndexedDB Wrapper Example (Dexie)
95
+ import Dexie, { type EntityTable } from 'dexie';
139
96
 
140
- ```
141
- Phase 1: Optimistic UI
142
- Client mutates locally, syncs async
143
- → Easy win: 200ms → 0ms perceived latency
144
- → Risk: conflicts on concurrent updates
145
-
146
- Phase 2: Offline Detection + Queue
147
- → Queue mutations when offline
148
- → Apply queue on reconnect
149
- → Risk: conflict ordering
150
-
151
- Phase 3: CRDT-backed Shared State
152
- → Replace mutable shared data with CRDTs
153
- → Full offline + collaboration
154
- → No more conflicts
155
- ```
97
+ interface Friend {
98
+ id: number;
99
+ name: string;
100
+ age: number;
101
+ }
156
102
 
157
- ---
103
+ const db = new Dexie('FriendsDatabase') as Dexie & {
104
+ friends: EntityTable<Friend, 'id'>;
105
+ };
158
106
 
159
- ## Output Format
107
+ // Schema configuration
108
+ db.version(1).stores({
109
+ friends: '++id, name, age' // Primary key and indexed props
110
+ });
160
111
 
161
- When this skill produces or reviews code, structure your output as follows:
112
+ // Write to DB instantly
113
+ await db.friends.add({ name: 'Alice', age: 25 });
162
114
 
115
+ // Live query natively drives React state without network calls
116
+ import { useLiveQuery } from "dexie-react-hooks";
117
+ const friends = useLiveQuery(() => db.friends.where('age').above(21).toArray());
163
118
  ```
164
- ━━━ Local First Report ━━━━━━━━━━━━━━━━━━━━━━━━
165
- Skill: Local First
166
- Language: [detected language / framework]
167
- Scope: [N files · N functions]
168
- ─────────────────────────────────────────────────
169
- ✅ Passed: [checks that passed, or "All clean"]
170
- ⚠️ Warnings: [non-blocking issues, or "None"]
171
- ❌ Blocked: [blocking issues requiring fix, or "None"]
172
- ─────────────────────────────────────────────────
173
- VBC status: PENDING → VERIFIED
174
- Evidence: [test output / lint pass / compile success]
175
- ```
176
-
177
- **VBC (Verification-Before-Completion) is mandatory.**
178
- Do not mark status as VERIFIED until concrete terminal evidence is provided.
179
-
180
119
 
181
120
  ---
182
-
183
- ## 🏛️ Tribunal Integration (Anti-Hallucination)
184
-
185
- **Slash command: `/tribunal-backend`**
186
- **Active reviewers: `logic` · `security`**
187
-
188
- ### ❌ Forbidden AI Tropes in Local-First
189
-
190
- 1. **Treating CRDTs as magic** — CRDTs solve concurrent edits to shared state, not schema migrations or access control.
191
- 2. **Inventing CRDT libraries** — `crdt-js`, `conflict-free`, `local-sync` are not real packages. Yjs, Automerge, and Loro are the real libraries.
192
- 3. **Skipping conflict detection in LWW** — Last-Write-Wins silently drops data. Always make the conflict resolution strategy explicit and communicate it to the user.
193
- 4. **Local storage for everything** — `localStorage` is synchronous, has a 5MB limit, and is not available in workers. Use IndexedDB via Dexie or Origin Private File System.
194
-
195
- ### ✅ Pre-Flight Self-Audit
196
-
197
- ```
198
- ✅ Is the conflict resolution strategy explicit and documented?
199
- ✅ Are only real CRDT libraries used (Yjs, Automerge, Loro)?
200
- ✅ Is offline state persisted to IndexedDB, not localStorage?
201
- ✅ Is the sync queue replay idempotent (safe to process the same mutation twice)?
202
- ✅ Does the UI clearly communicate offline/syncing/synced state to the user?
203
- ```
@@ -1,224 +1,84 @@
1
1
  ---
2
2
  name: mcp-builder
3
- description: MCP (Model Context Protocol) server building principles. Tool design, resource patterns, best practices.
3
+ description: Model Context Protocol (MCP) server integration mastery. Building custom MCP servers, standardizing tool exposes, managing standardized communication between large language models and localized datasets, securing boundary contexts, and architecting resource schemas. Use when modifying, extending, or building custom toolsets for AI platforms relying on the MCP standard.
4
4
  allowed-tools: Read, Write, Edit, Glob, Grep
5
- version: 1.0.0
6
- last-updated: 2026-03-12
5
+ version: 2.0.0
6
+ last-updated: 2026-04-02
7
7
  applies-to-model: gemini-2.5-pro, claude-3-7-sonnet
8
8
  ---
9
9
 
10
- # MCP Server Development
11
-
12
- > An MCP server exposes capabilities to AI assistants.
13
- > Design tools the way you design a good API: clear contracts, predictable behavior, honest errors.
14
-
15
- ---
16
-
17
- ## What MCP Servers Do
18
-
19
- An MCP (Model Context Protocol) server gives an AI assistant structured access to:
20
-
21
- - **Tools** — actions the AI can invoke (run a query, send a message, fetch data)
22
- - **Resources** — data the AI can read (files, database records, API responses)
23
- - **Prompts** — reusable prompt templates with parameters
24
-
25
- ---
26
-
27
- ## Tool Design Principles
28
-
29
- ### 1. One tool, one responsibility
30
-
31
- A tool that does two things is a tool that confuses the model. Split tools when they serve different goals.
32
-
33
- ```ts
34
- // ❌ Ambiguous — does it list AND filter?
35
- { name: "get_users", description: "Get users, optionally filtered by role" }
36
-
37
- // ✅ Separate concerns
38
- { name: "list_users", description: "List all users with pagination" }
39
- { name: "find_users_by_role", description: "Find users matching a specific role" }
40
- ```
41
-
42
- ### 2. Descriptions are the interface
43
-
44
- The AI reads descriptions to decide which tool to call. Write them for the AI, not for humans.
45
-
46
- - State exactly what the tool does in plain terms
47
- - State what the tool returns
48
- - State when NOT to use it if there's common confusion
49
-
50
- ```ts
51
- {
52
- name: "search_products",
53
- description: "Search products by keyword. Returns an array of matching product records " +
54
- "with id, name, price, and stock. Use this for keyword search, not for fetching a " +
55
- "specific product by ID — use get_product_by_id for that."
56
- }
57
- ```
58
-
59
- ### 3. Input schemas are contracts
60
-
61
- Every tool input must have a JSON Schema definition with:
62
- - Required vs. optional fields clearly marked
63
- - Descriptions on each field
64
- - Sensible defaults on optional fields
65
-
66
- ```ts
67
- inputSchema: {
68
- type: "object",
69
- required: ["query"],
70
- properties: {
71
- query: {
72
- type: "string",
73
- description: "Search keyword. Minimum 2 characters."
74
- },
75
- limit: {
76
- type: "number",
77
- description: "Maximum results to return. Default: 10. Max: 100.",
78
- default: 10
79
- }
80
- }
81
- }
82
- ```
83
-
84
- ### 4. Errors must be informative
85
-
86
- When a tool fails, the AI needs to understand what went wrong and whether to retry.
87
-
88
- ```ts
89
- // ❌ Useless error
90
- throw new Error("Failed");
91
-
92
- // ✅ Actionable error
93
- return {
94
- isError: true,
95
- content: [{
96
- type: "text",
97
- text: "Product search failed: the search index is temporarily unavailable. " +
98
- "Try again in a few seconds or use list_products for unfiltered results."
99
- }]
100
- };
101
- ```
10
+ # MCP Builder — Context Protocol Mastery
102
11
 
103
12
  ---
104
13
 
105
- ## Resource Design
14
+ ## 1. The Anatomy of an MCP Server
106
15
 
107
- Resources give the AI read-only access to data. Use them for content the AI needs to understand context, not for actions.
16
+ The Model Context Protocol (MCP) standardizes how AI agents fetch local data and execute tools.
17
+ A robust MCP server exposes exactly 3 primary concepts:
18
+ 1. **Resources:** Read-only data payloads (Logs, local files, database dumps).
19
+ 2. **Prompts:** Reusable injected context scaffolding (e.g., "Summarize this log with strict parameters").
20
+ 3. **Tools:** Actionable executed capabilities (e.g., "Run Postgres Query", "Restart Server").
108
21
 
109
- ```ts
110
- server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
111
- const uri = request.params.uri;
22
+ ```typescript
23
+ // Standardize exposing a Tool securely via an MCP Server Wrapper
24
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
25
+ import { z } from "zod";
112
26
 
113
- if (uri.startsWith("product://")) {
114
- const id = uri.replace("product://", "");
115
- const product = await db.products.findById(id);
27
+ const server = new McpServer({
28
+ name: "internal-database-auditor",
29
+ version: "1.0.0",
30
+ });
116
31
 
32
+ // Defining a rigorous tool parameter boundary
33
+ server.tool(
34
+ "query_production_database",
35
+ "Executes a read-only sanitized query against the production analytical replica.",
36
+ {
37
+ table: z.enum(["users", "transactions", "audit_logs"]).describe("The specific table to analyze"),
38
+ limit: z.number().max(100).default(10).describe("Maximum row returns to prevent context bloat"),
39
+ },
40
+ async ({ table, limit }) => {
41
+ // Execution logic
42
+ const data = await secureDatabaseClient.query(`SELECT * FROM ${table} LIMIT ${limit}`);
117
43
  return {
118
- contents: [{
119
- uri,
120
- mimeType: "application/json",
121
- text: JSON.stringify(product, null, 2)
122
- }]
44
+ content: [{ type: "text", text: JSON.stringify(data) }]
123
45
  };
124
46
  }
125
- });
47
+ );
126
48
  ```
127
49
 
128
50
  ---
129
51
 
130
- ## Security Rules
52
+ ## 2. Resource Management vs Tool Management
131
53
 
132
- MCP servers execute with user-level permissions and may have access to sensitive systems:
54
+ Do not use a `Tool` to read static data. Do not use a `Resource` to invoke remote actions.
133
55
 
134
- - **Never trust tool arguments without validation** the AI can be prompted to send malicious input
135
- - **Parameterize all database queries** treat tool input as untrusted user input
136
- - **Scope API keys narrowly** — the MCP server should have the minimum permissions needed
137
- - **Log tool invocations** — especially for tools that write data or delete records
138
- - **Rate limit tool calls** — prevent runaway AI loops from hammering backends
56
+ - **Resources (URI based):** Act identically to local files. Exposed explicitly so the AI context manager can read them *before* invoking tools. Use for things like `file:///app/config.json` or `db://schema/users`.
57
+ - **Tools:** Use exclusively when parameterized execution is required dynamically. Tools MUST be accompanied by extremely literal, explicit descriptions, because the LLM uses the description text to map Intent to the Tool execution.
139
58
 
140
59
  ---
141
60
 
142
- ## Configuration Template
143
-
144
- ```json
145
- {
146
- "mcpServers": {
147
- "your-server": {
148
- "command": "npx",
149
- "args": ["-y", "your-mcp-package"],
150
- "env": {
151
- "API_KEY": "${YOUR_API_KEY}"
152
- }
153
- }
154
- }
155
- }
156
- ```
157
-
158
- Place in `~/.cursor/mcp.json` (Cursor) or `~/.gemini/antigravity/mcp_config.json` (Antigravity).
159
-
160
- ---
61
+ ## 3. Structuring Tool Descriptions (The LLM Gateway)
161
62
 
162
- ## Output Format
63
+ The LLM decides to fire your tool based entirely on the Description schema.
64
+ If your description is vague, the LLM will hallucinate executions unpredictably.
163
65
 
164
- When this skill produces or reviews code, structure your output as follows:
66
+ ```typescript
67
+ // ❌ VAGUE (The LLM will guess when to use this, often incorrectly)
68
+ description: "Changes the system status."
165
69
 
70
+ // ✅ DETERMINISTIC (The LLM knows the exact boundaries and consequences)
71
+ description: "Transitions the payment processing gateway between 'ACTIVE' and 'MAINTENANCE' modes. Use this ONLY after verifying traffic logs to halt impending queue flooding. Requires Admin clearance."
166
72
  ```
167
- ━━━ Mcp Builder Report ━━━━━━━━━━━━━━━━━━━━━━━━
168
- Skill: Mcp Builder
169
- Language: [detected language / framework]
170
- Scope: [N files · N functions]
171
- ─────────────────────────────────────────────────
172
- ✅ Passed: [checks that passed, or "All clean"]
173
- ⚠️ Warnings: [non-blocking issues, or "None"]
174
- ❌ Blocked: [blocking issues requiring fix, or "None"]
175
- ─────────────────────────────────────────────────
176
- VBC status: PENDING → VERIFIED
177
- Evidence: [test output / lint pass / compile success]
178
- ```
179
-
180
- **VBC (Verification-Before-Completion) is mandatory.**
181
- Do not mark status as VERIFIED until concrete terminal evidence is provided.
182
-
183
-
184
73
 
185
74
  ---
186
75
 
187
- ## 🤖 LLM-Specific Traps
76
+ ## 4. MCP Security Boundaries
188
77
 
189
- AI coding assistants often fall into specific bad habits when dealing with this domain. These are strictly forbidden:
78
+ An MCP Server gives an external AI execution capability over your shell or database.
190
79
 
191
- 1. **Over-engineering:** Proposing complex abstractions or distributed systems when a simpler approach suffices.
192
- 2. **Hallucinated Libraries/Methods:** Using non-existent methods or packages. Always `// VERIFY` or check `package.json` / `requirements.txt`.
193
- 3. **Skipping Edge Cases:** Writing the "happy path" and ignoring error handling, timeouts, or data validation.
194
- 4. **Context Amnesia:** Forgetting the user's constraints and offering generic advice instead of tailored solutions.
195
- 5. **Silent Degradation:** Catching and suppressing errors without logging or re-raising.
80
+ - **Never Expose Raw Shells Natively:** Unless deliberately building a high-trust local desktop agent. Expose mapped commands (`execute_npm_build`) instead of raw terminals (`bash_command`).
81
+ - **Enforce Read-Only Defaults:** If creating a database tool, create `query_select_only` separate from `execute_mutation`. Give the AI read-only access.
82
+ - **Context Size Truncation:** If a tool queries a 5GB text log, the AI context window will instantly overflow and crash the session. The MCP logic MUST forcibly truncate outputs before returning.
196
83
 
197
84
  ---
198
-
199
- ## 🏛️ Tribunal Integration (Anti-Hallucination)
200
-
201
- **Slash command: `/review` or `/tribunal-full`**
202
- **Active reviewers: `logic-reviewer` · `security-auditor`**
203
-
204
- ### ❌ Forbidden AI Tropes
205
-
206
- 1. **Blind Assumptions:** Never make an assumption without documenting it clearly with `// VERIFY: [reason]`.
207
- 2. **Silent Degradation:** Catching and suppressing errors without logging or handling.
208
- 3. **Context Amnesia:** Forgetting the user's constraints and offering generic advice instead of tailored solutions.
209
-
210
- ### ✅ Pre-Flight Self-Audit
211
-
212
- Review these questions before confirming output:
213
- ```
214
- ✅ Did I rely ONLY on real, verified tools and methods?
215
- ✅ Is this solution appropriately scoped to the user's constraints?
216
- ✅ Did I handle potential failure modes and edge cases?
217
- ✅ Have I avoided generic boilerplate that doesn't add value?
218
- ```
219
-
220
- ### 🛑 Verification-Before-Completion (VBC) Protocol
221
-
222
- **CRITICAL:** You must follow a strict "evidence-based closeout" state machine.
223
- - ❌ **Forbidden:** Declaring a task complete because the output "looks correct."
224
- - ✅ **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.