contextos-agents 1.6.1 → 2.0.0-beta.2

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 (323) hide show
  1. package/.agents/AGENTS.md +6 -1
  2. package/.agents/adapters/aider/export.js +117 -97
  3. package/.agents/adapters/claude/export.js +68 -26
  4. package/.agents/adapters/copilot/export.js +90 -51
  5. package/.agents/adapters/cursor/export.js +83 -68
  6. package/.agents/adapters/drift-detector.js +196 -0
  7. package/.agents/adapters/gemini/export.js +76 -45
  8. package/.agents/adapters/pure-compiler.js +443 -0
  9. package/.agents/adapters/zed/export.js +109 -62
  10. package/.agents/compiled/registry.v2.json +504 -0
  11. package/.agents/compiled/registry.v2.sha256 +1 -0
  12. package/.agents/compiler/manifest-compiler.js +963 -0
  13. package/.agents/compiler/vendor/yaml.LICENSE.txt +13 -0
  14. package/.agents/compiler/vendor/yaml.SBOM.json +6 -0
  15. package/.agents/compiler/vendor/yaml.js +139 -0
  16. package/.agents/core/profiles/init.yaml +25 -0
  17. package/.agents/core/skills/context-manager/references/context-rules.md +59 -0
  18. package/.agents/core/skills/context-manager/skill.yaml +10 -5
  19. package/.agents/core/skills/context-os/SKILL.md +3 -6
  20. package/.agents/core/skills/context-os/skill.yaml +14 -8
  21. package/.agents/core/skills/engineering-workflow/SKILL.md +1 -1
  22. package/.agents/core/skills/engineering-workflow/skill.yaml +7 -7
  23. package/.agents/core/skills/gemini-precision/SKILL.md +4 -0
  24. package/.agents/core/skills/gemini-precision/skill.yaml +5 -6
  25. package/.agents/core/skills/gstack-roles/SKILL.md +3 -1
  26. package/.agents/core/skills/gstack-roles/skill.yaml +9 -6
  27. package/.agents/core/skills/ponytail-mindset/skill.yaml +7 -7
  28. package/.agents/core/skills/security/skill.yaml +21 -2
  29. package/.agents/ctx.js +587 -111
  30. package/.agents/customization-dx.js +282 -0
  31. package/.agents/doctor.js +877 -33
  32. package/.agents/filesystem/index.js +71 -0
  33. package/.agents/filesystem/journaled-transaction.js +451 -0
  34. package/.agents/filesystem/lockfile-v2.js +275 -0
  35. package/.agents/filesystem/platform-hardening.js +222 -0
  36. package/.agents/filesystem/project-lock.js +218 -0
  37. package/.agents/filesystem/safe-path.js +256 -0
  38. package/.agents/generated/claude/skills/context-os/SKILL.md +1 -1
  39. package/.agents/generated/claude/skills/engineering-workflow/SKILL.md +1 -1
  40. package/.agents/generated/claude/skills/gemini-precision/SKILL.md +4 -0
  41. package/.agents/generated/claude/skills/gstack-roles/SKILL.md +3 -1
  42. package/.agents/generated/gemini/skills/context-os/SKILL.md +2 -2
  43. package/.agents/generated/gemini/skills/engineering-workflow/SKILL.md +1 -1
  44. package/.agents/generated/gemini/skills/gemini-precision/SKILL.md +4 -0
  45. package/.agents/generated/gemini/skills/gstack-roles/SKILL.md +3 -1
  46. package/.agents/plugins/contextos/hooks.json +25 -0
  47. package/.agents/plugins/contextos/plugin.json +19 -0
  48. package/.agents/plugins.js +432 -73
  49. package/.agents/profiles.js +507 -46
  50. package/.agents/resolver.js +50 -414
  51. package/.agents/schemas/attestation.review.v1.json +111 -0
  52. package/.agents/schemas/attestation.verification.v1.json +85 -0
  53. package/.agents/schemas/lockfile.v2.schema.json +134 -0
  54. package/.agents/schemas/profile.v2.schema.json +114 -0
  55. package/.agents/schemas/runtime.thread.v1.json +192 -0
  56. package/.agents/schemas/skill.manifest.v2.json +177 -0
  57. package/.agents/schemas/verification.spec.v1.json +39 -0
  58. package/.agents/schemas/workspace.graph.schema.json +106 -0
  59. package/.agents/stats.js +22 -9
  60. package/.agents/transaction-core/event-store.js +288 -0
  61. package/.agents/transaction-core/idempotency.js +129 -0
  62. package/.agents/transaction-core/ipc-lock.js +311 -0
  63. package/.agents/transaction-core/plugin-supply-chain-bundle.js +436 -0
  64. package/.agents/validate.js +143 -14
  65. package/.agents/watch.js +354 -102
  66. package/.agents/workspace/workspace-graph.js +778 -0
  67. package/README.md +59 -387
  68. package/benchmarks/v2/analysis/statistics.js +140 -0
  69. package/benchmarks/v2/analysis/stats.js +69 -0
  70. package/benchmarks/v2/arms/arm-definitions.js +79 -0
  71. package/benchmarks/v2/dataset.schema.json +34 -0
  72. package/benchmarks/v2/evaluators/index.js +25 -0
  73. package/benchmarks/v2/evaluators/verified-success.js +116 -0
  74. package/benchmarks/v2/harness/runner.js +88 -0
  75. package/benchmarks/v2/pilot-tasks.json +392 -0
  76. package/bin/commands/recover.js +88 -0
  77. package/bin/commands/uninstall.js +207 -0
  78. package/bin/commands/update.js +325 -0
  79. package/bin/commands.js +342 -0
  80. package/bin/index.js +326 -149
  81. package/bin/lib/detector.js +106 -0
  82. package/bin/lib/lockfile.js +253 -0
  83. package/bin/lib/safe-writer.js +290 -0
  84. package/package.json +85 -73
  85. package/registry.json +15 -7
  86. package/registry.schema.json +3 -1
  87. package/registry.v2.schema.json +86 -0
  88. package/.agents/core/profiles/backend.yaml +0 -47
  89. package/.agents/core/profiles/enterprise.yaml +0 -46
  90. package/.agents/core/profiles/frontend.yaml +0 -46
  91. package/.agents/core/profiles/hackathon.yaml +0 -45
  92. package/.agents/core/profiles/mvp.yaml +0 -44
  93. package/.agents/core/profiles/startup.yaml +0 -48
  94. package/.agents/core/skills/adapters/EXAMPLES.md +0 -19
  95. package/.agents/core/skills/adapters/SKILL.md +0 -105
  96. package/.agents/core/skills/adapters/TROUBLESHOOTING.md +0 -7
  97. package/.agents/core/skills/adapters/VALIDATION.json +0 -12
  98. package/.agents/core/skills/adapters/skill.yaml +0 -10
  99. package/.agents/core/skills/architecture-diagrams/SKILL.md +0 -108
  100. package/.agents/core/skills/architecture-diagrams/VALIDATION.json +0 -12
  101. package/.agents/core/skills/architecture-diagrams/skill.yaml +0 -8
  102. package/.agents/core/skills/brutalist-design/SKILL.md +0 -150
  103. package/.agents/core/skills/brutalist-design/VALIDATION.json +0 -12
  104. package/.agents/core/skills/brutalist-design/skill.yaml +0 -8
  105. package/.agents/core/skills/database/EXAMPLES.md +0 -74
  106. package/.agents/core/skills/database/SKILL.md +0 -101
  107. package/.agents/core/skills/database/TROUBLESHOOTING.md +0 -18
  108. package/.agents/core/skills/database/VALIDATION.json +0 -11
  109. package/.agents/core/skills/database/skill.yaml +0 -25
  110. package/.agents/core/skills/ddd/EXAMPLES.md +0 -42
  111. package/.agents/core/skills/ddd/SKILL.md +0 -247
  112. package/.agents/core/skills/ddd/TROUBLESHOOTING.md +0 -19
  113. package/.agents/core/skills/ddd/VALIDATION.json +0 -12
  114. package/.agents/core/skills/ddd/ddd.md +0 -178
  115. package/.agents/core/skills/ddd/skill.yaml +0 -10
  116. package/.agents/core/skills/decisions/EXAMPLES.md +0 -35
  117. package/.agents/core/skills/decisions/SKILL.md +0 -90
  118. package/.agents/core/skills/decisions/TROUBLESHOOTING.md +0 -13
  119. package/.agents/core/skills/decisions/VALIDATION.json +0 -12
  120. package/.agents/core/skills/decisions/skill.yaml +0 -10
  121. package/.agents/core/skills/docker/EXAMPLES.md +0 -56
  122. package/.agents/core/skills/docker/SKILL.md +0 -63
  123. package/.agents/core/skills/docker/TROUBLESHOOTING.md +0 -18
  124. package/.agents/core/skills/docker/VALIDATION.json +0 -11
  125. package/.agents/core/skills/docker/skill.yaml +0 -23
  126. package/.agents/core/skills/fastapi/EXAMPLES.md +0 -36
  127. package/.agents/core/skills/fastapi/SKILL.md +0 -148
  128. package/.agents/core/skills/fastapi/TROUBLESHOOTING.md +0 -19
  129. package/.agents/core/skills/fastapi/VALIDATION.json +0 -12
  130. package/.agents/core/skills/fastapi/fastapi.md +0 -112
  131. package/.agents/core/skills/fastapi/skill.yaml +0 -10
  132. package/.agents/core/skills/generators/EXAMPLES.md +0 -19
  133. package/.agents/core/skills/generators/SKILL.md +0 -112
  134. package/.agents/core/skills/generators/TROUBLESHOOTING.md +0 -7
  135. package/.agents/core/skills/generators/VALIDATION.json +0 -12
  136. package/.agents/core/skills/generators/skill.yaml +0 -10
  137. package/.agents/core/skills/generators/templates/API.md +0 -77
  138. package/.agents/core/skills/generators/templates/ARCHITECTURE.md +0 -70
  139. package/.agents/core/skills/generators/templates/DATABASE.md +0 -42
  140. package/.agents/core/skills/generators/templates/DECISION.md +0 -46
  141. package/.agents/core/skills/generators/templates/PRD.md +0 -67
  142. package/.agents/core/skills/generators/templates/PROJECT_GRAPH.md +0 -56
  143. package/.agents/core/skills/generators/templates/ROADMAP.md +0 -51
  144. package/.agents/core/skills/generators/templates/TASKS.md +0 -43
  145. package/.agents/core/skills/generators/templates/UI.md +0 -73
  146. package/.agents/core/skills/graphify/EXAMPLES.md +0 -73
  147. package/.agents/core/skills/graphify/SKILL.md +0 -130
  148. package/.agents/core/skills/graphify/VALIDATION.json +0 -12
  149. package/.agents/core/skills/graphify/skill.yaml +0 -13
  150. package/.agents/core/skills/impeccable-design/EXAMPLES.md +0 -26
  151. package/.agents/core/skills/impeccable-design/SKILL.md +0 -201
  152. package/.agents/core/skills/impeccable-design/TROUBLESHOOTING.md +0 -19
  153. package/.agents/core/skills/impeccable-design/VALIDATION.json +0 -12
  154. package/.agents/core/skills/impeccable-design/skill.yaml +0 -14
  155. package/.agents/core/skills/interview-me/SKILL.md +0 -97
  156. package/.agents/core/skills/interview-me/VALIDATION.json +0 -12
  157. package/.agents/core/skills/interview-me/skill.yaml +0 -8
  158. package/.agents/core/skills/microservices/EXAMPLES.md +0 -38
  159. package/.agents/core/skills/microservices/SKILL.md +0 -164
  160. package/.agents/core/skills/microservices/TROUBLESHOOTING.md +0 -19
  161. package/.agents/core/skills/microservices/VALIDATION.json +0 -12
  162. package/.agents/core/skills/microservices/microservices.md +0 -119
  163. package/.agents/core/skills/microservices/skill.yaml +0 -10
  164. package/.agents/core/skills/minimalist-design/SKILL.md +0 -113
  165. package/.agents/core/skills/minimalist-design/VALIDATION.json +0 -12
  166. package/.agents/core/skills/minimalist-design/skill.yaml +0 -8
  167. package/.agents/core/skills/nestjs/EXAMPLES.md +0 -40
  168. package/.agents/core/skills/nestjs/SKILL.md +0 -139
  169. package/.agents/core/skills/nestjs/TROUBLESHOOTING.md +0 -19
  170. package/.agents/core/skills/nestjs/VALIDATION.json +0 -12
  171. package/.agents/core/skills/nestjs/nestjs.md +0 -103
  172. package/.agents/core/skills/nestjs/skill.yaml +0 -10
  173. package/.agents/core/skills/nextjs/EXAMPLES.md +0 -40
  174. package/.agents/core/skills/nextjs/SKILL.md +0 -163
  175. package/.agents/core/skills/nextjs/TROUBLESHOOTING.md +0 -19
  176. package/.agents/core/skills/nextjs/VALIDATION.json +0 -12
  177. package/.agents/core/skills/nextjs/nextjs.md +0 -67
  178. package/.agents/core/skills/nextjs/skill.yaml +0 -10
  179. package/.agents/core/skills/node/EXAMPLES.md +0 -80
  180. package/.agents/core/skills/node/SKILL.md +0 -128
  181. package/.agents/core/skills/node/TROUBLESHOOTING.md +0 -19
  182. package/.agents/core/skills/node/VALIDATION.json +0 -12
  183. package/.agents/core/skills/node/node.md +0 -87
  184. package/.agents/core/skills/node/skill.yaml +0 -10
  185. package/.agents/core/skills/performance/EXAMPLES.md +0 -30
  186. package/.agents/core/skills/performance/SKILL.md +0 -75
  187. package/.agents/core/skills/performance/TROUBLESHOOTING.md +0 -19
  188. package/.agents/core/skills/performance/VALIDATION.json +0 -12
  189. package/.agents/core/skills/performance/performance.md +0 -52
  190. package/.agents/core/skills/performance/skill.yaml +0 -10
  191. package/.agents/core/skills/react/EXAMPLES.md +0 -79
  192. package/.agents/core/skills/react/SKILL.md +0 -132
  193. package/.agents/core/skills/react/TROUBLESHOOTING.md +0 -19
  194. package/.agents/core/skills/react/VALIDATION.json +0 -12
  195. package/.agents/core/skills/react/react.md +0 -93
  196. package/.agents/core/skills/react/skill.yaml +0 -10
  197. package/.agents/core/skills/react-best-practices/SKILL.md +0 -155
  198. package/.agents/core/skills/react-best-practices/VALIDATION.json +0 -12
  199. package/.agents/core/skills/react-best-practices/skill.yaml +0 -10
  200. package/.agents/core/skills/redesign-audit/SKILL.md +0 -117
  201. package/.agents/core/skills/redesign-audit/VALIDATION.json +0 -12
  202. package/.agents/core/skills/redesign-audit/skill.yaml +0 -8
  203. package/.agents/core/skills/soft-design/SKILL.md +0 -108
  204. package/.agents/core/skills/soft-design/VALIDATION.json +0 -12
  205. package/.agents/core/skills/soft-design/skill.yaml +0 -8
  206. package/.agents/core/skills/state-management/EXAMPLES.md +0 -56
  207. package/.agents/core/skills/state-management/SKILL.md +0 -48
  208. package/.agents/core/skills/state-management/TROUBLESHOOTING.md +0 -18
  209. package/.agents/core/skills/state-management/VALIDATION.json +0 -11
  210. package/.agents/core/skills/state-management/skill.yaml +0 -22
  211. package/.agents/core/skills/subagent-orchestrator/SKILL.md +0 -100
  212. package/.agents/core/skills/subagent-orchestrator/VALIDATION.json +0 -12
  213. package/.agents/core/skills/subagent-orchestrator/skill.yaml +0 -8
  214. package/.agents/core/skills/system-design/EXAMPLES.md +0 -75
  215. package/.agents/core/skills/system-design/SKILL.md +0 -419
  216. package/.agents/core/skills/system-design/TROUBLESHOOTING.md +0 -19
  217. package/.agents/core/skills/system-design/VALIDATION.json +0 -12
  218. package/.agents/core/skills/system-design/skill.yaml +0 -13
  219. package/.agents/core/skills/system-design/system-design.md +0 -112
  220. package/.agents/core/skills/testing/EXAMPLES.md +0 -71
  221. package/.agents/core/skills/testing/SKILL.md +0 -70
  222. package/.agents/core/skills/testing/TROUBLESHOOTING.md +0 -18
  223. package/.agents/core/skills/testing/VALIDATION.json +0 -11
  224. package/.agents/core/skills/testing/skill.yaml +0 -26
  225. package/.agents/core/skills/typescript/EXAMPLES.md +0 -64
  226. package/.agents/core/skills/typescript/SKILL.md +0 -112
  227. package/.agents/core/skills/typescript/TROUBLESHOOTING.md +0 -19
  228. package/.agents/core/skills/typescript/VALIDATION.json +0 -12
  229. package/.agents/core/skills/typescript/skill.yaml +0 -10
  230. package/.agents/core/skills/typescript/typescript.md +0 -71
  231. package/.agents/core/skills/ui-design/EXAMPLES.md +0 -21
  232. package/.agents/core/skills/ui-design/SKILL.md +0 -124
  233. package/.agents/core/skills/ui-design/TROUBLESHOOTING.md +0 -19
  234. package/.agents/core/skills/ui-design/VALIDATION.json +0 -12
  235. package/.agents/core/skills/ui-design/skill.yaml +0 -10
  236. package/.agents/core/skills/ui-design/ui.md +0 -88
  237. package/.agents/core/skills/ui-ux-pro/EXAMPLES.md +0 -62
  238. package/.agents/core/skills/ui-ux-pro/SKILL.md +0 -375
  239. package/.agents/core/skills/ui-ux-pro/TROUBLESHOOTING.md +0 -19
  240. package/.agents/core/skills/ui-ux-pro/VALIDATION.json +0 -12
  241. package/.agents/core/skills/ui-ux-pro/skill.yaml +0 -13
  242. package/.agents/core/skills/ux-design/EXAMPLES.md +0 -36
  243. package/.agents/core/skills/ux-design/SKILL.md +0 -116
  244. package/.agents/core/skills/ux-design/TROUBLESHOOTING.md +0 -19
  245. package/.agents/core/skills/ux-design/VALIDATION.json +0 -12
  246. package/.agents/core/skills/ux-design/skill.yaml +0 -10
  247. package/.agents/core/skills/ux-design/ux.md +0 -80
  248. package/.agents/core/skills/vercel-optimize/SKILL.md +0 -83
  249. package/.agents/core/skills/vercel-optimize/VALIDATION.json +0 -12
  250. package/.agents/core/skills/vercel-optimize/skill.yaml +0 -10
  251. package/.agents/core/skills/web-accessibility/EXAMPLES.md +0 -39
  252. package/.agents/core/skills/web-accessibility/SKILL.md +0 -170
  253. package/.agents/core/skills/web-accessibility/TROUBLESHOOTING.md +0 -19
  254. package/.agents/core/skills/web-accessibility/VALIDATION.json +0 -12
  255. package/.agents/core/skills/web-accessibility/accessibility.md +0 -63
  256. package/.agents/core/skills/web-accessibility/skill.yaml +0 -10
  257. package/.agents/generated/claude/skills/adapters/SKILL.md +0 -126
  258. package/.agents/generated/claude/skills/architecture-diagrams/SKILL.md +0 -101
  259. package/.agents/generated/claude/skills/brutalist-design/SKILL.md +0 -145
  260. package/.agents/generated/claude/skills/database/SKILL.md +0 -191
  261. package/.agents/generated/claude/skills/ddd/SKILL.md +0 -305
  262. package/.agents/generated/claude/skills/decisions/SKILL.md +0 -134
  263. package/.agents/generated/claude/skills/docker/SKILL.md +0 -135
  264. package/.agents/generated/claude/skills/fastapi/SKILL.md +0 -200
  265. package/.agents/generated/claude/skills/generators/SKILL.md +0 -133
  266. package/.agents/generated/claude/skills/graphify/SKILL.md +0 -198
  267. package/.agents/generated/claude/skills/impeccable-design/SKILL.md +0 -241
  268. package/.agents/generated/claude/skills/interview-me/SKILL.md +0 -90
  269. package/.agents/generated/claude/skills/microservices/SKILL.md +0 -218
  270. package/.agents/generated/claude/skills/minimalist-design/SKILL.md +0 -108
  271. package/.agents/generated/claude/skills/nestjs/SKILL.md +0 -195
  272. package/.agents/generated/claude/skills/nextjs/SKILL.md +0 -219
  273. package/.agents/generated/claude/skills/node/SKILL.md +0 -224
  274. package/.agents/generated/claude/skills/performance/SKILL.md +0 -121
  275. package/.agents/generated/claude/skills/react/SKILL.md +0 -227
  276. package/.agents/generated/claude/skills/react-best-practices/SKILL.md +0 -146
  277. package/.agents/generated/claude/skills/redesign-audit/SKILL.md +0 -112
  278. package/.agents/generated/claude/skills/soft-design/SKILL.md +0 -103
  279. package/.agents/generated/claude/skills/state-management/SKILL.md +0 -120
  280. package/.agents/generated/claude/skills/subagent-orchestrator/SKILL.md +0 -93
  281. package/.agents/generated/claude/skills/system-design/SKILL.md +0 -507
  282. package/.agents/generated/claude/skills/testing/SKILL.md +0 -157
  283. package/.agents/generated/claude/skills/typescript/SKILL.md +0 -192
  284. package/.agents/generated/claude/skills/ui-design/SKILL.md +0 -161
  285. package/.agents/generated/claude/skills/ui-ux-pro/SKILL.md +0 -451
  286. package/.agents/generated/claude/skills/ux-design/SKILL.md +0 -168
  287. package/.agents/generated/claude/skills/vercel-optimize/SKILL.md +0 -76
  288. package/.agents/generated/claude/skills/web-accessibility/SKILL.md +0 -225
  289. package/.agents/generated/gemini/skills/adapters/SKILL.md +0 -135
  290. package/.agents/generated/gemini/skills/architecture-diagrams/SKILL.md +0 -107
  291. package/.agents/generated/gemini/skills/brutalist-design/SKILL.md +0 -151
  292. package/.agents/generated/gemini/skills/database/SKILL.md +0 -200
  293. package/.agents/generated/gemini/skills/ddd/SKILL.md +0 -314
  294. package/.agents/generated/gemini/skills/decisions/SKILL.md +0 -143
  295. package/.agents/generated/gemini/skills/docker/SKILL.md +0 -144
  296. package/.agents/generated/gemini/skills/fastapi/SKILL.md +0 -209
  297. package/.agents/generated/gemini/skills/generators/SKILL.md +0 -142
  298. package/.agents/generated/gemini/skills/graphify/SKILL.md +0 -205
  299. package/.agents/generated/gemini/skills/impeccable-design/SKILL.md +0 -250
  300. package/.agents/generated/gemini/skills/interview-me/SKILL.md +0 -96
  301. package/.agents/generated/gemini/skills/microservices/SKILL.md +0 -227
  302. package/.agents/generated/gemini/skills/minimalist-design/SKILL.md +0 -114
  303. package/.agents/generated/gemini/skills/nestjs/SKILL.md +0 -204
  304. package/.agents/generated/gemini/skills/nextjs/SKILL.md +0 -298
  305. package/.agents/generated/gemini/skills/node/SKILL.md +0 -323
  306. package/.agents/generated/gemini/skills/performance/SKILL.md +0 -185
  307. package/.agents/generated/gemini/skills/react/SKILL.md +0 -332
  308. package/.agents/generated/gemini/skills/react-best-practices/SKILL.md +0 -152
  309. package/.agents/generated/gemini/skills/redesign-audit/SKILL.md +0 -118
  310. package/.agents/generated/gemini/skills/soft-design/SKILL.md +0 -109
  311. package/.agents/generated/gemini/skills/state-management/SKILL.md +0 -129
  312. package/.agents/generated/gemini/skills/subagent-orchestrator/SKILL.md +0 -99
  313. package/.agents/generated/gemini/skills/system-design/SKILL.md +0 -631
  314. package/.agents/generated/gemini/skills/testing/SKILL.md +0 -166
  315. package/.agents/generated/gemini/skills/typescript/SKILL.md +0 -275
  316. package/.agents/generated/gemini/skills/ui-design/SKILL.md +0 -170
  317. package/.agents/generated/gemini/skills/ui-ux-pro/SKILL.md +0 -460
  318. package/.agents/generated/gemini/skills/ux-design/SKILL.md +0 -177
  319. package/.agents/generated/gemini/skills/vercel-optimize/SKILL.md +0 -82
  320. package/.agents/generated/gemini/skills/web-accessibility/SKILL.md +0 -300
  321. package/.agents/mcp/runtime.py +0 -470
  322. package/.agents/mcp/server.mjs +0 -189271
  323. package/benchmarks/gemini-issues.js +0 -533
@@ -1,63 +0,0 @@
1
- # Web Accessibility — WCAG 2.1 Compliance
2
-
3
- ## Principles (POUR)
4
-
5
- 1. **Perceivable** — content can be perceived by all users
6
- 2. **Operable** — interface can be operated by all users
7
- 3. **Understandable** — content and interface are understandable
8
- 4. **Robust** — content works across assistive technologies
9
-
10
- ## Keyboard Navigation
11
-
12
- - All interactive elements must be reachable with Tab
13
- - Focus order must be logical (DOM order)
14
- - Custom widgets need keyboard handlers (Enter, Space, Escape, Arrow keys)
15
- - Visible focus indicator on all interactive elements (never `outline: none` without replacement)
16
- - Skip navigation link for repeated content
17
-
18
- ## Semantic HTML
19
-
20
- - Use `<button>` not `<div onClick>` for actions
21
- - Use `<a href>` for navigation
22
- - Use heading hierarchy (`<h1>` → `<h2>` → `<h3>`)
23
- - Use `<nav>`, `<main>`, `<article>`, `<aside>` landmarks
24
- - Use `<label>` with every form input
25
-
26
- ## ARIA (when HTML alone isn't enough)
27
-
28
- - `aria-label` — label for screen readers when no visible text
29
- - `aria-labelledby` — reference to existing visible text
30
- - `aria-describedby` — additional description
31
- - `aria-live="polite"` — announce dynamic changes
32
- - `aria-expanded` — for collapsible sections
33
- - `aria-hidden="true"` — hide decorative elements
34
-
35
- **Rule: no ARIA is better than bad ARIA.** Use semantic HTML first.
36
-
37
- ## Color and Contrast
38
-
39
- - Text contrast: 4.5:1 minimum (AA), 7:1 (AAA)
40
- - Large text (18px+ bold, 24px+ regular): 3:1 minimum
41
- - Never use color alone to convey information
42
- - Test with grayscale filter
43
-
44
- ## Images
45
-
46
- - All images need `alt` text
47
- - Decorative images: `alt=""`
48
- - Complex images: `aria-describedby` with longer description
49
- - SVG icons: `role="img"` + `aria-label`
50
-
51
- ## Forms
52
-
53
- - Every input needs a visible `<label>`
54
- - Error messages linked with `aria-describedby`
55
- - Required fields marked with `aria-required="true"`
56
- - Group related fields with `<fieldset>` + `<legend>`
57
-
58
- ## Testing
59
-
60
- - Automated: axe-core, Lighthouse accessibility audit
61
- - Manual: keyboard-only navigation test
62
- - Screen reader: test with NVDA (Windows), VoiceOver (Mac)
63
- - Zoom: test at 200% and 400% zoom
@@ -1,10 +0,0 @@
1
- id: web-accessibility
2
- name: Web Accessibility
3
- category: frontend
4
- tags: [frontend, a11y, wcag, aria, accessibility]
5
- requires: []
6
- optional: [react, nextjs]
7
- conflicts: []
8
- weight: 7
9
- documents:
10
- - accessibility.md
@@ -1,126 +0,0 @@
1
- # agent-adapters
2
-
3
- ## Overview
4
-
5
- Unified cross-agent configuration engine. Translates single ContextOS source rules into optimized native formats for Claude Code (CLAUDE.md), Gemini (.agents/skills), Cursor (.cursorrules, .cursor/rules/*.mdc), GitHub Copilot, Zed, Aider, and Continue.
6
-
7
- ## When to Use
8
-
9
- Activate when configuring, synchronizing, or exporting agent rules and skills across multiple IDEs and AI programming assistants.
10
-
11
- ## Rules & Patterns
12
-
13
- ContextOS is agent-agnostic. This skill generates the right config format for any AI agent.
14
-
15
- ## Supported Agents
16
-
17
- | Agent | Config File | Format |
18
- | --- | --- | --- |
19
- | **Gemini** | `.agents/AGENTS.md` + `.agents/skills/` | Markdown + YAML skills |
20
- | **Claude Code** | `CLAUDE.md` | Single markdown file |
21
- | **GitHub Copilot / Codex** | `AGENTS.md` (root) | Markdown |
22
- | **Cursor** | `.cursorrules` | Plain text rules |
23
- | **Aider** | `.aider.conf.yml` | YAML config |
24
- | **Continue** | `.continuerules` | Markdown rules |
25
- | **OpenHands** | `openhands.json` | JSON config |
26
- | **Roo Code** | `.roo/` | Directory with rules |
27
- | **Windsurf** | `.windsurfrules` | Plain text rules |
28
-
29
- ## Generation Command
30
-
31
- `ctx adapt [agent]` — Generate config for a specific agent.
32
-
33
- `ctx adapt all` — Generate configs for all supported agents.
34
-
35
- ## Adapter Logic
36
-
37
- ### For Claude Code (`CLAUDE.md`)
38
-
39
- Compile into a single markdown file:
40
-
41
- 1. Project overview from `docs/PRD.md` (summary only)
42
- 2. Architecture summary from `docs/ARCHITECTURE.md`
43
- 3. Coding rules from loaded skills
44
- 4. Active Decision Records
45
- 5. Current tasks from `docs/TASKS.md`
46
-
47
- ### For Gemini (`.agents/AGENTS.md`)
48
-
49
- Already native format. Just ensure:
50
-
51
- 1. `AGENTS.md` references the skill directory
52
- 2. Skills have proper SKILL.md with frontmatter
53
- 3. Context Manager rules are in AGENTS.md
54
-
55
- ### For Cursor (`.cursorrules`)
56
-
57
- Compile into a flat text file:
58
-
59
- 1. Project context (condensed)
60
- 2. Coding style rules
61
- 3. Framework-specific instructions
62
- 4. Anti-patterns to avoid
63
-
64
- ### For Aider (`.aider.conf.yml`)
65
-
66
- ```yaml
67
- read:
68
- - docs/ARCHITECTURE.md
69
- - docs/API.md
70
- - docs/PROJECT_GRAPH.md
71
- conventions:
72
- - {{coding rules from skills}}
73
- ```
74
-
75
- ## Sync Rules
76
-
77
- - Adapters read from the canonical ContextOS documents
78
- - Never edit adapter output files directly
79
- - Re-run `ctx adapt` after any document change
80
- - Each adapter file includes a header: `# Generated by ContextOS — do not edit directly`
81
-
82
-
83
- ## Code Examples
84
-
85
- See `EXAMPLES.md` for detailed code examples.
86
-
87
- ## Validation Checklist
88
-
89
- What to verify during the review phase before completing the task.
90
-
91
- ## Common Mistakes
92
-
93
- Anti-patterns and things to explicitly avoid. See `TROUBLESHOOTING.md`.
94
-
95
- ## Integration Notes
96
-
97
- How this skill interacts with other skills.
98
-
99
-
100
- # adapters Examples — Anti-patterns vs ContextOS Standard
101
-
102
- ## Example 1: Multi-Agent Configuration
103
-
104
- ### Anti-pattern: Manually Syncing 6 Different Rule Files
105
-
106
- ```text
107
- Editing .cursorrules, then forgetting to update CLAUDE.md, then editing copilot-instructions.md.
108
- Rules diverge across teammates using different IDEs.
109
- ```
110
-
111
- ### Best practice: ContextOS Standard (Single Source of Truth)
112
-
113
- ```bash
114
- # Edit skills once in .agents/core/skills/
115
- # Compile to all agents with one command:
116
- node .agents/ctx.js export all
117
- # Automatically updates .cursorrules, CLAUDE.md, copilot-instructions.md, .aider, .zed
118
- ```
119
-
120
- # adapters Troubleshooting & Common Mistakes
121
-
122
- ## 1. Overwriting Custom Configs
123
-
124
- - **Symptom**: Custom non-ContextOS rules wiped out during export.
125
- - **Root Cause**: Running export with force flags over unmanaged files.
126
- - **Fix**: Keep custom project overrides in dedicated config files or use plugin skills.
@@ -1,101 +0,0 @@
1
- # architecture-diagrams
2
-
3
- ## Overview
4
-
5
- Visual architecture engineering skill inspired by [tt-a1i/archify](https://github.com/tt-a1i/archify). Replaces static ASCII art and rigid default diagrams with crisp, self-contained SVG and responsive HTML diagrams featuring modern dark-mode palettes, pulse animations for event flows, and strict C4-model component boundaries.
6
-
7
- ## When to Use
8
-
9
- Activate whenever:
10
-
11
- - Designing or explaining distributed systems, microservices, or full-stack architectures.
12
- - Visualizing complex auth flows (OAuth2, PKCE), multi-step payment sagas, or CDC outbox data pipelines.
13
- - User requests an architecture diagram, flow chart, sequence diagram, or visual system design.
14
-
15
- ## Rules & Patterns
16
-
17
- ### 1. Diagram Types Supported
18
-
19
- 1. **System Landscape / C4 Container Diagram**:
20
- - Clients (Web, Mobile, Third-party) → API Gateway / CDN → Microservices / Serverless → Storage / Event Brokers.
21
- 2. **Sequence Flow Diagram**:
22
- - Step-by-step lifecycles with synchronous requests, asynchronous pub/sub events, and compensating transactions.
23
- 3. **Data Pipeline & Event-Driven Topology**:
24
- - Primary DB → Transactional Outbox → CDC (Debezium) → Kafka Topic → Consumers → Materialized Views.
25
-
26
- ### 2. Aesthetic & Visual Invariants
27
-
28
- - **Dark Theme by Default**: Surface `#0B0F19`, containers `#1E293B`, borders `#334155`, text `#F8FAFC`.
29
- - **Semantic Component Accents**:
30
- - Client / Frontend: Sky Blue (`#38BDF8`)
31
- - API Gateway / Router: Indigo (`#818CF8`)
32
- - Business Services: Emerald Green (`#34D399`)
33
- - Databases / Storage: Amber / Orange (`#F59E0B`)
34
- - Message Brokers / Event Buses: Purple (`#A855F7`)
35
- - **Active Data-Flow Motion**: Use subtle CSS `@keyframes` on SVG stroke dashes (`stroke-dasharray`, `stroke-dashoffset`) to show active direction of messages and data streams.
36
-
37
- ---
38
-
39
- ## Code Examples
40
-
41
- ### Standalone Animated SVG Data-Flow Pattern
42
-
43
- ```html
44
- <svg viewBox="0 0 800 200" xmlns="http://www.w3.org/2000/svg" class="bg-slate-950 rounded-xl p-4 w-full">
45
- <defs>
46
- <style>
47
- .flow-line { stroke: #38BDF8; stroke-width: 2; stroke-dasharray: 6,6; animation: flow 1.5s linear infinite; }
48
- @keyframes flow { to { stroke-dashoffset: -12; } }
49
- .box { fill: #1E293B; stroke: #334155; stroke-width: 1.5; rx: 8; }
50
- .text-title { fill: #F8FAFC; font-family: sans-serif; font-size: 14px; font-weight: 600; }
51
- .text-sub { fill: #94A3B8; font-family: monospace; font-size: 11px; }
52
- </style>
53
- </defs>
54
-
55
- <!-- Client Node -->
56
- <rect x="30" y="70" width="160" height="60" class="box" />
57
- <text x="110" y="96" text-anchor="middle" class="text-title">Next.js Client</text>
58
- <text x="110" y="114" text-anchor="middle" class="text-sub">React 19 / RSC</text>
59
-
60
- <!-- Data Flow -->
61
- <line x1="190" y1="100" x2="330" y2="100" class="flow-line" />
62
-
63
- <!-- API Gateway -->
64
- <rect x="330" y="70" width="160" height="60" class="box" />
65
- <text x="410" y="96" text-anchor="middle" class="text-title">API Gateway</text>
66
- <text x="410" y="114" text-anchor="middle" class="text-sub">Auth & Rate Limiting</text>
67
-
68
- <!-- Flow to Database -->
69
- <line x1="490" y1="100" x2="630" y2="100" class="flow-line" />
70
-
71
- <!-- Database -->
72
- <rect x="630" y="70" width="140" height="60" class="box" />
73
- <text x="700" y="96" text-anchor="middle" class="text-title">PostgreSQL</text>
74
- <text x="700" y="114" text-anchor="middle" class="text-sub">Prisma / Outbox</text>
75
- </svg>
76
- ```
77
-
78
- ---
79
-
80
- ## Validation Checklist
81
-
82
- - [ ] Diagram clearly identifies all component boundaries, ports, and protocols.
83
- - [ ] Visual hierarchy is unambiguous (clients on left/top, storage on right/bottom).
84
- - [ ] Motion/animation is purposeful and lightweight (no heavy canvas frameworks).
85
- - [ ] Accessible: nodes include semantic labels and readable color contrast.
86
-
87
- ---
88
-
89
- ## Common Mistakes
90
-
91
- - **Messy cross-overs**: Laying out 20 boxes with overlapping lines instead of grouping into clean C4 layers.
92
- - **Unlabeled connections**: Lines without protocol (HTTPS, gRPC, WSS) or event payload descriptions.
93
- - **Overwhelming detail**: Drawing internal class diagrams when the user asked for a system-level overview.
94
-
95
- ---
96
-
97
- ## Integration Notes
98
-
99
- - Triggers during `system-design` and `microservices` planning phases.
100
- - Used to generate visual architecture artifacts in Markdown walkthroughs and specs.
101
- - Pairs with `ui-ux-pro` for consistent aesthetic styling.
@@ -1,145 +0,0 @@
1
- # SKILL: Industrial Brutalism & Tactical Telemetry UI
2
-
3
- ## Overview
4
-
5
- Advanced proficiency in architecting web interfaces that synthesize mid-century Swiss Typographic design, industrial manufacturing manuals, and retro-futuristic aerospace/military terminal interfaces. This discipline requires absolute mastery over rigid modular grids, extreme typographic scale contrast, purely utilitarian color palettes, and the programmatic simulation of analog degradation (halftones, CRT scanlines, bitmap dithering). The objective is to construct digital environments that project raw functionality, mechanical precision, and high data density, deliberately discarding conventional consumer UI patterns.
6
-
7
- ## When to Use
8
-
9
- - When building data-heavy telemetry dashboards, analytics monitors, trading systems, or developer command centers.
10
- - When creating editorial portfolios, archival indexes, or technical documentation sites requiring an industrial blueprint aesthetic.
11
- - When explicitly prompted for "brutalist", "tactical", "terminal", "Swiss print", or "mechanical" aesthetics.
12
-
13
- ## Rules & Patterns
14
-
15
- ### 1. Visual Archetypes
16
-
17
- Pick ONE per project and commit to it. Do not alternate or mix both modes within the same interface.
18
-
19
- #### 1.1 Swiss Industrial Print
20
-
21
- Derived from 1960s corporate identity systems and heavy machinery blueprints.
22
-
23
- - **Characteristics:** High-contrast light modes (newsprint/off-white substrates). Reliance on monolithic, heavy sans-serif typography. Unforgiving structural grids outlined by visible dividing lines. Aggressive, asymmetric use of negative space punctuated by oversized, viewport-bleeding numerals or letterforms. Heavy use of primary red as an alert/accent color.
24
-
25
- #### 1.2 Tactical Telemetry & CRT Terminal
26
-
27
- Derived from classified military databases, legacy mainframes, and aerospace Heads-Up Displays (HUDs).
28
-
29
- - **Characteristics:** Dark mode exclusivity. High-density tabular data presentation. Absolute dominance of monospaced typography. Integration of technical framing devices (ASCII brackets, crosshairs). Application of simulated hardware limitations (phosphor glow, scanlines, low bit-depth rendering).
30
-
31
- ### 2. Typographic Architecture
32
-
33
- Typography is the primary structural and decorative infrastructure. Imagery is secondary. The system demands extreme variance in scale, weight, and spacing.
34
-
35
- #### 2.1 Macro-Typography (Structural Headers)
36
-
37
- - **Classification:** Neo-Grotesque / Heavy Sans-Serif.
38
- - **Optimal Web Fonts:** Neue Haas Grotesk (Black), Inter (Extra Bold/Black), Archivo Black, Roboto Flex (Heavy), Monument Extended.
39
- - **Scale:** Deployed at massive scales using fluid typography (e.g., `clamp(4rem, 10vw, 15rem)`).
40
- - **Tracking (Letter-spacing):** Extremely tight, often negative (`-0.03em` to `-0.06em`), forcing glyphs to form solid architectural blocks.
41
- - **Leading (Line-height):** Highly compressed (`0.85` to `0.95`).
42
- - **Casing:** Exclusively uppercase for structural impact.
43
-
44
- #### 2.2 Micro-Typography (Data & Telemetry)
45
-
46
- - **Classification:** Monospace / Technical Sans.
47
- - **Optimal Web Fonts:** JetBrains Mono, IBM Plex Mono, Space Mono, VT323, Courier Prime.
48
- - **Scale:** Fixed and small (`10px` to `14px` / `0.7rem` to `0.875rem`).
49
- - **Tracking:** Generous (`0.05em` to `0.1em`) to simulate mechanical typewriter spacing or terminal matrices.
50
- - **Leading:** Standard to tight (`1.2` to `1.4`).
51
- - **Casing:** Exclusively uppercase. Used for all metadata, navigation, unit IDs, and coordinates.
52
-
53
- #### 2.3 Textural Contrast (Artistic Disruption)
54
-
55
- - **Classification:** High-Contrast Serif.
56
- - **Optimal Web Fonts:** Playfair Display, EB Garamond, Times New Roman.
57
- - **Implementation Parameters:** Used exceedingly sparingly. Must be subjected to heavy post-processing (halftone filters, 1-bit dithering) to degrade vector perfection and create textural juxtaposition against the clean sans-serifs.
58
-
59
- ### 3. Color System
60
-
61
- The color architecture is uncompromising. Gradients, soft drop shadows, and modern translucency are strictly prohibited. Colors simulate physical media or primitive emissive displays.
62
-
63
- **CRITICAL: Choose ONE substrate palette per project and use it consistently. Never mix light and dark substrates within the same interface.**
64
-
65
- #### Swiss Industrial Print Light Substrate
66
-
67
- - **Background:** `#F4F4F0` or `#EAE8E3` (Matte, unbleached documentation paper).
68
- - **Foreground:** `#050505` to `#111111` (Carbon Ink).
69
- - **Accent:** `#E61919` or `#FF2A2A` (Aviation/Hazard Red). This is the ONLY accent color. Used for strike-throughs, thick structural dividing lines, or vital data highlights.
70
-
71
- #### Tactical Telemetry Dark Substrate
72
-
73
- - **Background:** `#0A0A0A` or `#121212` (Deactivated CRT. Avoid pure `#000000`).
74
- - **Foreground:** `#EAEAEA` (White phosphor). This is the primary text color.
75
- - **Accent:** `#E61919` or `#FF2A2A` (Aviation/Hazard Red). Same red, same rules.
76
- - **Terminal Green (`#4AF626`):** Optional. Use ONLY for a single specific UI element (e.g., one status indicator or one data readout) — never as a general text color. If it doesn't serve a clear purpose, omit it entirely.
77
-
78
- ### 4. Layout and Spatial Engineering
79
-
80
- - **The Blueprint Grid:** Strict adherence to CSS Grid architectures. Elements do not float; they are anchored precisely to grid tracks and intersections.
81
- - **Visible Compartmentalization:** Extensive utilization of solid borders (`1px` or `2px solid`) to delineate distinct zones of information. Horizontal rules (`<hr>`) frequently span the entire container width to segregate operational units.
82
- - **Bimodal Density:** Layouts oscillate between extreme data density (tightly packed monospace metadata clustered together) and vast expanses of calculated negative space framing macro-typography.
83
- - **Geometry:** Absolute rejection of `border-radius`. All corners must be exactly 90 degrees to enforce mechanical rigidity.
84
-
85
- ### 5. UI Components and Symbology
86
-
87
- - **Syntax Decoration:** Utilization of ASCII characters to frame data points (`[ DELIVERY SYSTEMS ]`, `< RE-IND >`, `>>>`, `///`).
88
- - **Industrial Markers:** Prominent integration of registration (`®`), copyright (`©`), and trademark (`™`) symbols functioning as structural geometric elements rather than legal text.
89
- - **Technical Assets:** Integration of crosshairs (`+`) at grid intersections, repeating vertical lines (barcodes), thick horizontal warning stripes, and randomized string data (`REV 2.6`, `UNIT / D-01`) to simulate active mechanical processes.
90
-
91
- ### 6. Textural and Post-Processing Effects
92
-
93
- - **Halftone and 1-Bit Dithering:** Dot-matrix effects via `mix-blend-mode: multiply` overlays combined with SVG radial dot patterns.
94
- - **CRT Scanlines:** `repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,0.1) 2px, rgba(0,0,0,0.1) 4px)` on terminal backgrounds.
95
- - **Mechanical Noise:** Low-opacity SVG static filter on the DOM root to introduce physical grain.
96
-
97
- ### 7. Web Engineering Directives
98
-
99
- 1. **Grid Determinism:** Utilize `display: grid; gap: 1px;` with contrasting parent/child background colors to generate mathematically perfect, razor-thin dividing lines without complex border declarations.
100
- 2. **Semantic Rigidity:** Construct the DOM using precise semantic tags (`<data>`, `<samp>`, `<kbd>`, `<output>`, `<dl>`) to accurately reflect the technical nature of the telemetry.
101
- 3. **Typography Clamping:** Implement CSS `clamp()` functions exclusively for macro-typography to ensure massive text scales aggressively while maintaining structural integrity across viewports.
102
-
103
- ## Code Examples
104
-
105
- ```tsx
106
- export function TelemetryModule({ unitId, status, metrics }: { unitId: string; status: string; metrics: { label: string; val: string }[] }) {
107
- return (
108
- <div className="border-2 border-black dark:border-white bg-[#F4F4F0] dark:bg-[#0A0A0A] font-mono p-4 rounded-none">
109
- <div className="flex justify-between border-b border-black/30 dark:border-white/30 pb-2 mb-4 text-xs tracking-widest uppercase">
110
- <span>[ UNIT // {unitId} ]</span>
111
- <span className="text-[#E61919] font-bold">&lt; STATUS: {status} &gt;</span>
112
- </div>
113
- <div className="grid grid-cols-2 gap-px bg-black/20 dark:bg-white/20">
114
- {metrics.map(m => (
115
- <div key={m.label} className="bg-[#F4F4F0] dark:bg-[#0A0A0A] p-2">
116
- <div className="text-[10px] text-black/60 dark:text-white/60 tracking-wider">{m.label}</div>
117
- <div className="text-sm font-bold tracking-tight">{m.val}</div>
118
- </div>
119
- ))}
120
- </div>
121
- </div>
122
- );
123
- }
124
- ```
125
-
126
- ## Validation Checklist
127
-
128
- - [ ] Strict rejection of `border-radius` (all corners 0px / 90 degrees).
129
- - [ ] Substrate consistency: 100% committed to either Swiss Light or Tactical CRT Dark.
130
- - [ ] Pure black (`#000000`) avoided for backgrounds.
131
- - [ ] Monospace typography used for all telemetry, coordinates, and metadata labels.
132
- - [ ] Dividing lines engineered using solid borders or 1px grid track gaps.
133
- - [ ] No soft gradients, standard drop shadows, or floating cards.
134
-
135
- ## Common Mistakes
136
-
137
- - Mixing Swiss Industrial Print and Tactical Telemetry substrates within the same view.
138
- - Introducing rounded corners (`rounded-md`, `rounded-full`) or pill buttons.
139
- - Using generic body typefaces without tracking adjustments.
140
- - Applying subtle pastel colors instead of raw carbon ink, off-white, and hazard red.
141
-
142
- ## Integration Notes
143
-
144
- - Complements `impeccable-design` for QA checks on contrast and typography.
145
- - Pairs with `web-accessibility` to guarantee high-contrast readability (AAA ratio).
@@ -1,191 +0,0 @@
1
- # database
2
-
3
- ## Overview
4
-
5
- Relational database design, query optimization, migration safety, connection pooling in serverless environments, and ORM usage across PostgreSQL, Prisma, and Drizzle.
6
-
7
- ## When to Use
8
-
9
- Activate for tasks involving database schema design, migrations, indexing, relational models, ORM queries, transactions, or query performance tuning.
10
-
11
- ## Rules & Patterns
12
-
13
- ### Negative Constraints (What NOT to Do)
14
-
15
- 1. **NEVER do `SELECT *` in production**: Always select explicit columns required by the caller to minimize memory bandwidth and lock footprint.
16
- 2. **NEVER run destructive migrations without backward compatibility**: Always follow expand-and-contract (Phase 1: add new column as nullable; Phase 2: backfill; Phase 3: make non-nullable & remove old column).
17
- 3. **NEVER execute queries in loops (The N+1 Anti-Pattern)**: Always use batch loading (`inArray`, `DataLoader`, or relational `include` / `JOIN`).
18
- 4. **NEVER leave foreign keys without indexes**: In PostgreSQL/MySQL, child foreign key columns must always have an index to prevent table-level locking on cascade deletes.
19
- 5. **NEVER perform multi-entity writes without a database transaction**: Any operation touching multiple records must use `prisma.$transaction` or `db.transaction`.
20
- 6. **NEVER open unpooled database connections in Serverless / Edge functions**: Serverless scale-outs will instantly exhaust PostgreSQL's `max_connections`.
21
-
22
- ---
23
-
24
- ### Zero-Downtime Migrations (Expand-and-Contract)
25
-
26
- When modifying schemas with zero downtime:
27
-
28
- 1. **Phase 1 (Expand)**: Add the new column as `NULLABLE` (or with a default value). Deploy the application code that reads from old column and writes to both old and new.
29
- 2. **Phase 2 (Backfill)**: Run an asynchronous batch migration job in chunks (e.g. 1000 rows at a time) to populate data from old column to new column.
30
- 3. **Phase 3 (Contract)**: Update application code to read and write exclusively from the new column.
31
- 4. **Phase 4 (Cleanup)**: Once traffic is fully shifted, remove the old column and mark the new column as `NOT NULL` in a separate migration.
32
-
33
- ---
34
-
35
- ### Serverless & Edge Connection Pooling
36
-
37
- In serverless environments (AWS Lambda, Vercel Functions):
38
-
39
- - Always connect via a connection pooler:
40
- - **Prisma**: Use Prisma Accelerate or configure transaction mode connection URLs.
41
- - **Drizzle / Node-Postgres**: Use `@neondatabase/serverless` or connect to PgBouncer pooler port (`6543`) with `max: 1` per serverless container.
42
- - Set strict statement timeouts (e.g. `statement_timeout = '5000'`) to prevent hanging queries from exhausting pool capacity.
43
-
44
- ---
45
-
46
- ### Indexing & Performance Rules
47
-
48
- - **B-Tree Indexes**: For high-cardinality filters (`status`, `user_id`, `created_at`).
49
- - **Composite Indexes**: When querying multiple columns together (`WHERE organization_id = ? AND status = ?`), order columns in index by equality first, range second.
50
- - **Partial Indexes**: For sparse boolean flags (`WHERE is_processed = false`).
51
- - **Covering Indexes**: Include frequently selected columns (`INCLUDE (title, created_at)`) to enable index-only scans without table heap access.
52
-
53
- ---
54
-
55
- ## Code Examples
56
-
57
- ### Zero-Downtime Column Rename (Drizzle ORM)
58
-
59
- ```typescript
60
- // Step 1 (Expand): Keep old column, add new column
61
- export const users = pgTable('users', {
62
- id: uuid('id').primaryKey().defaultRandom(),
63
- fullName: varchar('full_name', { length: 255 }), // new column
64
- name: varchar('name', { length: 255 }), // old column kept during transition
65
- });
66
-
67
- // App write logic during transition:
68
- await db.insert(users).values({
69
- name: input.name,
70
- fullName: input.name
71
- });
72
- ```
73
-
74
- ---
75
-
76
- ## Validation Checklist
77
-
78
- - [ ] All database queries select explicit required columns (no `SELECT *`).
79
- - [ ] Foreign keys have matching indexes on child tables.
80
- - [ ] Multi-table writes wrapped in ACID transactions.
81
- - [ ] No N+1 queries in loops.
82
- - [ ] Schema migrations tested against expand-and-contract pattern.
83
- - [ ] Serverless database connection string uses pooling proxy.
84
-
85
- ---
86
-
87
- ## Common Mistakes
88
-
89
- - **Missing pagination limits**: Unbounded `findMany()` calls leading to Out-Of-Memory crashes under production volume.
90
- - **Locking entire tables**: Adding `NOT NULL` columns with heavy compute defaults in PostgreSQL without concurrent index creation.
91
-
92
- ---
93
-
94
- ## Integration Notes
95
-
96
- - Interacts with `system-design`, `ddd`, and `security` (multi-tenant tenantId scoping).
97
-
98
-
99
- # Database Examples — Anti-patterns vs ContextOS Standard
100
-
101
- ## Example 1: Solving the N+1 Query Problem
102
-
103
- ### Anti-pattern: Anti-pattern (N+1 database queries in a loop)
104
-
105
- ```typescript
106
- // BAD: 1 query for users + N queries for posts!
107
- const users = await prisma.user.findMany();
108
- const usersWithPosts = [];
109
- for (const user of users) {
110
- const posts = await prisma.post.findMany({ where: { userId: user.id } }); // N queries!
111
- usersWithPosts.push({ ...user, posts });
112
- }
113
- ```
114
-
115
- ### Best practice: ContextOS Standard (Batch query or relational include)
116
-
117
- ```typescript
118
- // GOOD: 1 single optimized batch query
119
- const usersWithPosts = await prisma.user.findMany({
120
- where: { isActive: true },
121
- select: {
122
- id: true,
123
- name: true,
124
- email: true,
125
- posts: {
126
- where: { published: true },
127
- select: { id: true, title: true, createdAt: true },
128
- take: 5
129
- }
130
- }
131
- });
132
- ```
133
-
134
- ---
135
-
136
- ## Example 2: Safe Atomic Transactions with Locking
137
-
138
- ### Anti-pattern: Anti-pattern (Unprotected read-modify-write race condition)
139
-
140
- ```typescript
141
- // BAD: race condition between reading balance and updating
142
- const account = await prisma.account.findUnique({ where: { id } });
143
- if (account.balance >= amount) {
144
- await prisma.account.update({
145
- where: { id },
146
- data: { balance: account.balance - amount }
147
- });
148
- }
149
- ```
150
-
151
- ### Best practice: ContextOS Standard (Atomic conditional update in transaction)
152
-
153
- ```typescript
154
- // GOOD: atomic database transaction with invariant check
155
- export async function deductBalance(accountId: string, amount: number) {
156
- return await prisma.$transaction(async (tx) => {
157
- const updated = await tx.account.updateMany({
158
- where: {
159
- id: accountId,
160
- balance: { gte: amount }
161
- },
162
- data: {
163
- balance: { decrement: amount }
164
- }
165
- });
166
-
167
- if (updated.count === 0) {
168
- throw new InsufficientFundsError(accountId);
169
- }
170
- });
171
- }
172
- ```
173
-
174
- # Database Troubleshooting Guide
175
-
176
- ## Common Issues & Fixes
177
-
178
- ### 1. Connection Pool Exhaustion in Serverless / Edge
179
-
180
- - **Cause**: Creating a new PrismaClient / DB connection instance on every serverless function invocation.
181
- - **Fix**: Declare PrismaClient as a global singleton across warm lambdas, and enable PgBouncer or Prisma Accelerate.
182
-
183
- ### 2. Slow Queries on Large Tables
184
-
185
- - **Cause**: Missing composite index on filtered and ordered columns.
186
- - **Fix**: Run `EXPLAIN ANALYZE <query>` and add targeted indexes matching the WHERE and ORDER BY columns.
187
-
188
- ### 3. Database Deadlocks during Concurrent Transactions
189
-
190
- - **Cause**: Different transactions updating resources in different orders.
191
- - **Fix**: Always acquire locks and update entities in a deterministic alphabetical or ID-ordered sequence.