@hivehub/rulebook 5.5.1 → 5.7.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 (342) hide show
  1. package/.claude/commands/rulebook-learn-capture.md +41 -48
  2. package/.claude/commands/rulebook-learn-list.md +13 -13
  3. package/README.md +332 -394
  4. package/dist/cli/commands/context-intelligence.d.ts +0 -1
  5. package/dist/cli/commands/context-intelligence.d.ts.map +1 -1
  6. package/dist/cli/commands/context-intelligence.js +12 -33
  7. package/dist/cli/commands/context-intelligence.js.map +1 -1
  8. package/dist/cli/commands/index.d.ts +4 -7
  9. package/dist/cli/commands/index.d.ts.map +1 -1
  10. package/dist/cli/commands/index.js +4 -7
  11. package/dist/cli/commands/index.js.map +1 -1
  12. package/dist/cli/commands/init.d.ts.map +1 -1
  13. package/dist/cli/commands/init.js +40 -81
  14. package/dist/cli/commands/init.js.map +1 -1
  15. package/dist/cli/commands/mcp.d.ts +0 -1
  16. package/dist/cli/commands/mcp.d.ts.map +1 -1
  17. package/dist/cli/commands/mcp.js +1 -7
  18. package/dist/cli/commands/mcp.js.map +1 -1
  19. package/dist/cli/commands/memory.d.ts +7 -1
  20. package/dist/cli/commands/memory.d.ts.map +1 -1
  21. package/dist/cli/commands/memory.js +51 -57
  22. package/dist/cli/commands/memory.js.map +1 -1
  23. package/dist/cli/commands/misc.d.ts +1 -15
  24. package/dist/cli/commands/misc.d.ts.map +1 -1
  25. package/dist/cli/commands/misc.js +36 -215
  26. package/dist/cli/commands/misc.js.map +1 -1
  27. package/dist/cli/commands/plans.d.ts +0 -6
  28. package/dist/cli/commands/plans.d.ts.map +1 -1
  29. package/dist/cli/commands/plans.js +9 -77
  30. package/dist/cli/commands/plans.js.map +1 -1
  31. package/dist/cli/commands/skills.js +6 -6
  32. package/dist/cli/commands/skills.js.map +1 -1
  33. package/dist/cli/commands/task.js +4 -4
  34. package/dist/cli/commands/task.js.map +1 -1
  35. package/dist/cli/commands/update.d.ts.map +1 -1
  36. package/dist/cli/commands/update.js +122 -52
  37. package/dist/cli/commands/update.js.map +1 -1
  38. package/dist/cli/prompts.d.ts.map +1 -1
  39. package/dist/cli/prompts.js +1 -78
  40. package/dist/cli/prompts.js.map +1 -1
  41. package/dist/core/claude/claude-mcp.d.ts +59 -0
  42. package/dist/core/claude/claude-mcp.d.ts.map +1 -0
  43. package/dist/core/claude/claude-mcp.js +220 -0
  44. package/dist/core/claude/claude-mcp.js.map +1 -0
  45. package/dist/core/claude/claude-md-generator.d.ts +52 -0
  46. package/dist/core/claude/claude-md-generator.d.ts.map +1 -0
  47. package/dist/core/claude/claude-md-generator.js +104 -0
  48. package/dist/core/claude/claude-md-generator.js.map +1 -0
  49. package/dist/core/claude/claude-settings-manager.d.ts +44 -0
  50. package/dist/core/claude/claude-settings-manager.d.ts.map +1 -0
  51. package/dist/core/claude/claude-settings-manager.js +194 -0
  52. package/dist/core/claude/claude-settings-manager.js.map +1 -0
  53. package/dist/core/claude-settings-manager.d.ts.map +1 -1
  54. package/dist/core/claude-settings-manager.js +9 -3
  55. package/dist/core/claude-settings-manager.js.map +1 -1
  56. package/dist/core/console/cli-bridge.d.ts +113 -0
  57. package/dist/core/console/cli-bridge.d.ts.map +1 -0
  58. package/dist/core/console/cli-bridge.js +1094 -0
  59. package/dist/core/console/cli-bridge.js.map +1 -0
  60. package/dist/core/detect/detector.d.ts +35 -0
  61. package/dist/core/detect/detector.d.ts.map +1 -0
  62. package/dist/core/detect/detector.js +541 -0
  63. package/dist/core/detect/detector.js.map +1 -0
  64. package/dist/core/docs/docs-generator.d.ts +9 -0
  65. package/dist/core/docs/docs-generator.d.ts.map +1 -0
  66. package/dist/core/docs/docs-generator.js +531 -0
  67. package/dist/core/docs/docs-generator.js.map +1 -0
  68. package/dist/core/docs/mcp-reference-generator.d.ts +13 -0
  69. package/dist/core/docs/mcp-reference-generator.d.ts.map +1 -0
  70. package/dist/core/docs/mcp-reference-generator.js +66 -0
  71. package/dist/core/docs/mcp-reference-generator.js.map +1 -0
  72. package/dist/core/generators/generator.d.ts +54 -0
  73. package/dist/core/generators/generator.d.ts.map +1 -0
  74. package/dist/core/generators/generator.js +1041 -0
  75. package/dist/core/generators/generator.js.map +1 -0
  76. package/dist/core/generators/gitignore-generator.d.ts +13 -0
  77. package/dist/core/generators/gitignore-generator.d.ts.map +1 -0
  78. package/dist/core/generators/gitignore-generator.js +307 -0
  79. package/dist/core/generators/gitignore-generator.js.map +1 -0
  80. package/dist/core/generators/minimal-scaffolder.d.ts +8 -0
  81. package/dist/core/generators/minimal-scaffolder.d.ts.map +1 -0
  82. package/dist/core/generators/minimal-scaffolder.js +51 -0
  83. package/dist/core/generators/minimal-scaffolder.js.map +1 -0
  84. package/dist/core/generators/rules-generator.d.ts +73 -0
  85. package/dist/core/generators/rules-generator.d.ts.map +1 -0
  86. package/dist/core/generators/rules-generator.js +202 -0
  87. package/dist/core/generators/rules-generator.js.map +1 -0
  88. package/dist/core/generators/workflow-generator.d.ts +15 -0
  89. package/dist/core/generators/workflow-generator.d.ts.map +1 -0
  90. package/dist/core/generators/workflow-generator.js +390 -0
  91. package/dist/core/generators/workflow-generator.js.map +1 -0
  92. package/dist/core/ide/multi-tool-generator.d.ts +59 -0
  93. package/dist/core/ide/multi-tool-generator.d.ts.map +1 -0
  94. package/dist/core/ide/multi-tool-generator.js +157 -0
  95. package/dist/core/ide/multi-tool-generator.js.map +1 -0
  96. package/dist/core/ide/opencode-generator.d.ts +72 -0
  97. package/dist/core/ide/opencode-generator.d.ts.map +1 -0
  98. package/dist/core/ide/opencode-generator.js +450 -0
  99. package/dist/core/ide/opencode-generator.js.map +1 -0
  100. package/dist/core/merger.d.ts +1 -1
  101. package/dist/core/merger.d.ts.map +1 -1
  102. package/dist/core/merger.js +5 -5
  103. package/dist/core/merger.js.map +1 -1
  104. package/dist/core/migrator.d.ts +0 -1
  105. package/dist/core/migrator.d.ts.map +1 -1
  106. package/dist/core/migrator.js +4 -29
  107. package/dist/core/migrator.js.map +1 -1
  108. package/dist/core/quality/coverage-checker.d.ts +14 -0
  109. package/dist/core/quality/coverage-checker.d.ts.map +1 -0
  110. package/dist/core/quality/coverage-checker.js +176 -0
  111. package/dist/core/quality/coverage-checker.js.map +1 -0
  112. package/dist/core/quality/dependency-checker.d.ts +21 -0
  113. package/dist/core/quality/dependency-checker.d.ts.map +1 -0
  114. package/dist/core/quality/dependency-checker.js +247 -0
  115. package/dist/core/quality/dependency-checker.js.map +1 -0
  116. package/dist/core/quality/doctor.d.ts +19 -0
  117. package/dist/core/quality/doctor.d.ts.map +1 -0
  118. package/dist/core/quality/doctor.js +163 -0
  119. package/dist/core/quality/doctor.js.map +1 -0
  120. package/dist/core/quality/validator.d.ts +21 -0
  121. package/dist/core/quality/validator.d.ts.map +1 -0
  122. package/dist/core/quality/validator.js +177 -0
  123. package/dist/core/quality/validator.js.map +1 -0
  124. package/dist/core/ralph-scripts.d.ts.map +1 -1
  125. package/dist/core/ralph-scripts.js +7 -6
  126. package/dist/core/ralph-scripts.js.map +1 -1
  127. package/dist/core/skills/skills-manager.d.ts +126 -0
  128. package/dist/core/skills/skills-manager.d.ts.map +1 -0
  129. package/dist/core/skills/skills-manager.js +630 -0
  130. package/dist/core/skills/skills-manager.js.map +1 -0
  131. package/dist/core/state/config-manager.d.ts +86 -0
  132. package/dist/core/state/config-manager.d.ts.map +1 -0
  133. package/dist/core/state/config-manager.js +562 -0
  134. package/dist/core/state/config-manager.js.map +1 -0
  135. package/dist/core/state/override-manager.d.ts +23 -0
  136. package/dist/core/state/override-manager.d.ts.map +1 -0
  137. package/dist/core/state/override-manager.js +82 -0
  138. package/dist/core/state/override-manager.js.map +1 -0
  139. package/dist/core/state/state-writer.d.ts +34 -0
  140. package/dist/core/state/state-writer.d.ts.map +1 -0
  141. package/dist/core/state/state-writer.js +78 -0
  142. package/dist/core/state/state-writer.js.map +1 -0
  143. package/dist/core/state/version-bumper.d.ts +19 -0
  144. package/dist/core/state/version-bumper.d.ts.map +1 -0
  145. package/dist/core/state/version-bumper.js +180 -0
  146. package/dist/core/state/version-bumper.js.map +1 -0
  147. package/dist/core/tasks/decision-manager.d.ts +25 -0
  148. package/dist/core/tasks/decision-manager.d.ts.map +1 -0
  149. package/dist/core/tasks/decision-manager.js +183 -0
  150. package/dist/core/tasks/decision-manager.js.map +1 -0
  151. package/dist/core/tasks/knowledge-manager.d.ts +24 -0
  152. package/dist/core/tasks/knowledge-manager.d.ts.map +1 -0
  153. package/dist/core/tasks/knowledge-manager.js +173 -0
  154. package/dist/core/tasks/knowledge-manager.js.map +1 -0
  155. package/dist/core/tasks/learn-manager.d.ts +27 -0
  156. package/dist/core/tasks/learn-manager.d.ts.map +1 -0
  157. package/dist/core/tasks/learn-manager.js +121 -0
  158. package/dist/core/tasks/learn-manager.js.map +1 -0
  159. package/dist/core/tasks/plans-manager.d.ts +46 -0
  160. package/dist/core/tasks/plans-manager.d.ts.map +1 -0
  161. package/dist/core/tasks/plans-manager.js +158 -0
  162. package/dist/core/tasks/plans-manager.js.map +1 -0
  163. package/dist/core/tasks/task-manager.d.ts +127 -0
  164. package/dist/core/tasks/task-manager.d.ts.map +1 -0
  165. package/dist/core/tasks/task-manager.js +607 -0
  166. package/dist/core/tasks/task-manager.js.map +1 -0
  167. package/dist/core/workspace/project-worker.d.ts +6 -6
  168. package/dist/core/workspace/project-worker.d.ts.map +1 -1
  169. package/dist/core/workspace/project-worker.js +6 -6
  170. package/dist/core/workspace/project-worker.js.map +1 -1
  171. package/dist/index.d.ts +1 -1
  172. package/dist/index.d.ts.map +1 -1
  173. package/dist/index.js +19 -176
  174. package/dist/index.js.map +1 -1
  175. package/dist/mcp/rulebook-server.d.ts.map +1 -1
  176. package/dist/mcp/rulebook-server.js +16 -960
  177. package/dist/mcp/rulebook-server.js.map +1 -1
  178. package/dist/memory/file-search.d.ts +43 -0
  179. package/dist/memory/file-search.d.ts.map +1 -0
  180. package/dist/memory/file-search.js +228 -0
  181. package/dist/memory/file-search.js.map +1 -0
  182. package/dist/memory/file-store.d.ts +99 -0
  183. package/dist/memory/file-store.d.ts.map +1 -0
  184. package/dist/memory/file-store.js +615 -0
  185. package/dist/memory/file-store.js.map +1 -0
  186. package/dist/memory/legacy-migrator.d.ts +27 -0
  187. package/dist/memory/legacy-migrator.d.ts.map +1 -0
  188. package/dist/memory/legacy-migrator.js +185 -0
  189. package/dist/memory/legacy-migrator.js.map +1 -0
  190. package/dist/memory/memory-manager.d.ts +25 -24
  191. package/dist/memory/memory-manager.d.ts.map +1 -1
  192. package/dist/memory/memory-manager.js +97 -140
  193. package/dist/memory/memory-manager.js.map +1 -1
  194. package/dist/memory/memory-types.d.ts +1 -1
  195. package/dist/memory/memory-types.d.ts.map +1 -1
  196. package/dist/types.d.ts +8 -119
  197. package/dist/types.d.ts.map +1 -1
  198. package/dist/utils/file-system.d.ts +22 -0
  199. package/dist/utils/file-system.d.ts.map +1 -1
  200. package/dist/utils/file-system.js +31 -0
  201. package/dist/utils/file-system.js.map +1 -1
  202. package/dist/utils/git-hooks.d.ts.map +1 -1
  203. package/dist/utils/git-hooks.js +3 -2
  204. package/dist/utils/git-hooks.js.map +1 -1
  205. package/package.json +2 -6
  206. package/templates/agents/context-intelligence.md +50 -52
  207. package/templates/cli/OPENCODE.md +85 -18
  208. package/templates/commands/rulebook-learn-capture.md +41 -48
  209. package/templates/commands/rulebook-learn-list.md +13 -13
  210. package/templates/core/AGENTS_LEAN.md +0 -14
  211. package/templates/hooks/check-context-and-handoff.sh +74 -76
  212. package/templates/hooks/enforce-pre-tool.sh +70 -0
  213. package/templates/hooks/enforce-team-for-background-agents.sh +55 -55
  214. package/templates/hooks/on-compact-reinject.sh +34 -34
  215. package/templates/hooks/resume-from-handoff.sh +61 -61
  216. package/templates/hooks/terse-activate.sh +197 -197
  217. package/templates/hooks/terse-mode-tracker.sh +190 -187
  218. package/templates/ides/OPENCODE.md +63 -0
  219. package/templates/skills/cli/opencode/SKILL.md +82 -28
  220. package/.claude/commands/ralph-config.md +0 -112
  221. package/.claude/commands/ralph-history.md +0 -110
  222. package/.claude/commands/ralph-init.md +0 -72
  223. package/.claude/commands/ralph-pause-resume.md +0 -105
  224. package/.claude/commands/ralph-run.md +0 -101
  225. package/.claude/commands/ralph-status.md +0 -76
  226. package/templates/core/RALPH.md +0 -471
  227. package/templates/frameworks/ANGULAR.md +0 -36
  228. package/templates/frameworks/DJANGO.md +0 -83
  229. package/templates/frameworks/ELECTRON.md +0 -147
  230. package/templates/frameworks/FLASK.md +0 -38
  231. package/templates/frameworks/FLUTTER.md +0 -55
  232. package/templates/frameworks/JQUERY.md +0 -32
  233. package/templates/frameworks/LARAVEL.md +0 -38
  234. package/templates/frameworks/NESTJS.md +0 -43
  235. package/templates/frameworks/NEXTJS.md +0 -127
  236. package/templates/frameworks/NUXT.md +0 -40
  237. package/templates/frameworks/RAILS.md +0 -66
  238. package/templates/frameworks/REACT.md +0 -38
  239. package/templates/frameworks/REACT_NATIVE.md +0 -47
  240. package/templates/frameworks/SPRING.md +0 -39
  241. package/templates/frameworks/SYMFONY.md +0 -36
  242. package/templates/frameworks/VUE.md +0 -36
  243. package/templates/frameworks/ZEND.md +0 -35
  244. package/templates/hooks/enforce-mcp-for-tasks.sh +0 -31
  245. package/templates/hooks/enforce-no-deferred.sh +0 -21
  246. package/templates/hooks/enforce-no-shortcuts.sh +0 -31
  247. package/templates/ides/COPILOT.md +0 -37
  248. package/templates/ides/CURSOR.md +0 -43
  249. package/templates/ides/JETBRAINS_AI.md +0 -35
  250. package/templates/ides/REPLIT.md +0 -36
  251. package/templates/ides/TABNINE.md +0 -29
  252. package/templates/ides/VSCODE.md +0 -40
  253. package/templates/ides/WINDSURF.md +0 -36
  254. package/templates/ides/ZED.md +0 -32
  255. package/templates/ides/cursor-mdc/go.mdc +0 -24
  256. package/templates/ides/cursor-mdc/python.mdc +0 -24
  257. package/templates/ides/cursor-mdc/quality.mdc +0 -25
  258. package/templates/ides/cursor-mdc/ralph.mdc +0 -39
  259. package/templates/ides/cursor-mdc/rulebook.mdc +0 -38
  260. package/templates/ides/cursor-mdc/rust.mdc +0 -24
  261. package/templates/ides/cursor-mdc/typescript.mdc +0 -25
  262. package/templates/ralph/ralph-history.bat +0 -4
  263. package/templates/ralph/ralph-history.sh +0 -5
  264. package/templates/ralph/ralph-init.bat +0 -5
  265. package/templates/ralph/ralph-init.sh +0 -5
  266. package/templates/ralph/ralph-pause.bat +0 -5
  267. package/templates/ralph/ralph-pause.sh +0 -5
  268. package/templates/ralph/ralph-run.bat +0 -5
  269. package/templates/ralph/ralph-run.sh +0 -5
  270. package/templates/ralph/ralph-status.bat +0 -4
  271. package/templates/ralph/ralph-status.sh +0 -5
  272. package/templates/services/AZURE_BLOB.md +0 -184
  273. package/templates/services/CASSANDRA.md +0 -239
  274. package/templates/services/DATADOG.md +0 -26
  275. package/templates/services/DOCKER.md +0 -124
  276. package/templates/services/DOCKER_COMPOSE.md +0 -168
  277. package/templates/services/DYNAMODB.md +0 -308
  278. package/templates/services/ELASTICSEARCH.md +0 -347
  279. package/templates/services/GCS.md +0 -178
  280. package/templates/services/HELM.md +0 -194
  281. package/templates/services/INFLUXDB.md +0 -265
  282. package/templates/services/KAFKA.md +0 -341
  283. package/templates/services/KUBERNETES.md +0 -208
  284. package/templates/services/MARIADB.md +0 -183
  285. package/templates/services/MEMCACHED.md +0 -242
  286. package/templates/services/MINIO.md +0 -201
  287. package/templates/services/MONGODB.md +0 -268
  288. package/templates/services/MYSQL.md +0 -358
  289. package/templates/services/NEO4J.md +0 -247
  290. package/templates/services/OPENTELEMETRY.md +0 -25
  291. package/templates/services/ORACLE.md +0 -290
  292. package/templates/services/PINO.md +0 -24
  293. package/templates/services/POSTGRESQL.md +0 -326
  294. package/templates/services/PROMETHEUS.md +0 -33
  295. package/templates/services/RABBITMQ.md +0 -286
  296. package/templates/services/REDIS.md +0 -292
  297. package/templates/services/S3.md +0 -298
  298. package/templates/services/SENTRY.md +0 -23
  299. package/templates/services/SQLITE.md +0 -294
  300. package/templates/services/SQLSERVER.md +0 -294
  301. package/templates/services/WINSTON.md +0 -30
  302. package/templates/skills/frameworks/angular/SKILL.md +0 -46
  303. package/templates/skills/frameworks/django/SKILL.md +0 -93
  304. package/templates/skills/frameworks/electron/SKILL.md +0 -157
  305. package/templates/skills/frameworks/flask/SKILL.md +0 -48
  306. package/templates/skills/frameworks/flutter/SKILL.md +0 -65
  307. package/templates/skills/frameworks/jquery/SKILL.md +0 -42
  308. package/templates/skills/frameworks/laravel/SKILL.md +0 -48
  309. package/templates/skills/frameworks/nestjs/SKILL.md +0 -53
  310. package/templates/skills/frameworks/nextjs/SKILL.md +0 -137
  311. package/templates/skills/frameworks/nuxt/SKILL.md +0 -50
  312. package/templates/skills/frameworks/rails/SKILL.md +0 -76
  313. package/templates/skills/frameworks/react/SKILL.md +0 -48
  314. package/templates/skills/frameworks/react-native/SKILL.md +0 -57
  315. package/templates/skills/frameworks/spring/SKILL.md +0 -49
  316. package/templates/skills/frameworks/symfony/SKILL.md +0 -46
  317. package/templates/skills/frameworks/vue/SKILL.md +0 -46
  318. package/templates/skills/frameworks/zend/SKILL.md +0 -45
  319. package/templates/skills/services/azure-blob/SKILL.md +0 -194
  320. package/templates/skills/services/cassandra/SKILL.md +0 -249
  321. package/templates/skills/services/dynamodb/SKILL.md +0 -318
  322. package/templates/skills/services/elasticsearch/SKILL.md +0 -357
  323. package/templates/skills/services/gcs/SKILL.md +0 -188
  324. package/templates/skills/services/influxdb/SKILL.md +0 -275
  325. package/templates/skills/services/kafka/SKILL.md +0 -351
  326. package/templates/skills/services/mariadb/SKILL.md +0 -193
  327. package/templates/skills/services/memcached/SKILL.md +0 -252
  328. package/templates/skills/services/minio/SKILL.md +0 -211
  329. package/templates/skills/services/mongodb/SKILL.md +0 -278
  330. package/templates/skills/services/mysql/SKILL.md +0 -368
  331. package/templates/skills/services/neo4j/SKILL.md +0 -257
  332. package/templates/skills/services/oracle/SKILL.md +0 -300
  333. package/templates/skills/services/postgresql/SKILL.md +0 -336
  334. package/templates/skills/services/rabbitmq/SKILL.md +0 -296
  335. package/templates/skills/services/redis/SKILL.md +0 -302
  336. package/templates/skills/services/s3/SKILL.md +0 -308
  337. package/templates/skills/services/sqlite/SKILL.md +0 -304
  338. package/templates/skills/services/sqlserver/SKILL.md +0 -304
  339. package/templates/skills/workflows/ralph/SETUP.md +0 -228
  340. package/templates/skills/workflows/ralph/SKILL.md +0 -309
  341. package/templates/skills/workflows/ralph/install.sh +0 -87
  342. package/templates/skills/workflows/ralph/manifest.json +0 -158
@@ -1,358 +0,0 @@
1
- <!-- MYSQL:START -->
2
- # MySQL Database Instructions
3
-
4
- **CRITICAL**: Use MySQL for relational data storage with high performance, replication, and wide ecosystem support.
5
-
6
- ## Core Features
7
-
8
- ### Connection
9
- ```typescript
10
- // Using mysql2 (Node.js)
11
- import mysql from 'mysql2/promise'
12
-
13
- const pool = mysql.createPool({
14
- host: process.env.DB_HOST,
15
- port: parseInt(process.env.DB_PORT || '3306'),
16
- database: process.env.DB_NAME,
17
- user: process.env.DB_USER,
18
- password: process.env.DB_PASSWORD,
19
- waitForConnections: true,
20
- connectionLimit: 10,
21
- queueLimit: 0,
22
- enableKeepAlive: true,
23
- keepAliveInitialDelay: 0,
24
- })
25
-
26
- // Using Prisma
27
- import { PrismaClient } from '@prisma/client'
28
- const prisma = new PrismaClient()
29
- ```
30
-
31
- ### Basic Queries
32
- ```typescript
33
- // SELECT
34
- const [rows] = await pool.execute('SELECT * FROM users WHERE id = ?', [userId])
35
- const users = rows as User[]
36
-
37
- // INSERT
38
- const [result] = await pool.execute(
39
- 'INSERT INTO users (name, email) VALUES (?, ?)',
40
- ['John Doe', 'john@example.com']
41
- )
42
- const insertId = (result as any).insertId
43
-
44
- // UPDATE
45
- const [result] = await pool.execute(
46
- 'UPDATE users SET name = ? WHERE id = ?',
47
- ['Jane Doe', userId]
48
- )
49
- const affectedRows = (result as any).affectedRows
50
-
51
- // DELETE
52
- const [result] = await pool.execute('DELETE FROM users WHERE id = ?', [userId])
53
- ```
54
-
55
- ### Transactions
56
- ```typescript
57
- const connection = await pool.getConnection()
58
- try {
59
- await connection.beginTransaction()
60
-
61
- await connection.execute('INSERT INTO accounts (user_id, balance) VALUES (?, ?)', [userId, 1000])
62
- await connection.execute('INSERT INTO transactions (account_id, amount) VALUES (?, ?)', [accountId, 1000])
63
-
64
- await connection.commit()
65
- } catch (error) {
66
- await connection.rollback()
67
- throw error
68
- } finally {
69
- connection.release()
70
- }
71
- ```
72
-
73
- ### Advanced Features
74
- ```typescript
75
- // JSON queries (MySQL 5.7+)
76
- const [rows] = await pool.execute(
77
- "SELECT * FROM products WHERE JSON_EXTRACT(metadata, '$.category') = ?",
78
- ['electronics']
79
- )
80
-
81
- // Full-text search
82
- const [rows] = await pool.execute(
83
- "SELECT * FROM articles WHERE MATCH(title, content) AGAINST(? IN NATURAL LANGUAGE MODE)",
84
- ['search term']
85
- )
86
-
87
- // Window functions (MySQL 8.0+)
88
- const [rows] = await pool.execute(`
89
- SELECT
90
- name,
91
- salary,
92
- ROW_NUMBER() OVER (PARTITION BY department ORDER BY salary DESC) as rank
93
- FROM employees
94
- `)
95
-
96
- // Common Table Expressions (CTE) (MySQL 8.0+)
97
- const [rows] = await pool.execute(`
98
- WITH RECURSIVE cte AS (
99
- SELECT id, name, parent_id FROM categories WHERE parent_id IS NULL
100
- UNION ALL
101
- SELECT c.id, c.name, c.parent_id FROM categories c
102
- INNER JOIN cte ON c.parent_id = cte.id
103
- )
104
- SELECT * FROM cte
105
- `)
106
- ```
107
-
108
- ## Common Patterns
109
-
110
- ### Connection Pooling
111
- ```typescript
112
- // Reuse connection pool
113
- let pool: mysql.Pool | null = null
114
-
115
- export function getPool(): mysql.Pool {
116
- if (!pool) {
117
- pool = mysql.createPool({
118
- // ... config
119
- })
120
-
121
- pool.on('connection', (connection) => {
122
- connection.query('SET SESSION sql_mode = "STRICT_TRANS_TABLES"')
123
- })
124
- }
125
- return pool
126
- }
127
-
128
- // Graceful shutdown
129
- process.on('SIGINT', async () => {
130
- if (pool) {
131
- await pool.end()
132
- }
133
- process.exit(0)
134
- })
135
- ```
136
-
137
- ### Prepared Statements
138
- ```typescript
139
- // Always use parameterized queries (?) to prevent SQL injection
140
- // ❌ WRONG
141
- await pool.execute(`SELECT * FROM users WHERE email = '${email}'`)
142
-
143
- // ✅ CORRECT
144
- await pool.execute('SELECT * FROM users WHERE email = ?', [email])
145
- ```
146
-
147
- ### Error Handling
148
- ```typescript
149
- try {
150
- const [rows] = await pool.execute('SELECT * FROM users WHERE id = ?', [userId])
151
- if ((rows as any[]).length === 0) {
152
- throw new Error('User not found')
153
- }
154
- return rows[0]
155
- } catch (error: any) {
156
- if (error.code === 'ER_DUP_ENTRY') {
157
- throw new Error('Duplicate entry')
158
- }
159
- if (error.code === 'ER_NO_REFERENCED_ROW_2') {
160
- throw new Error('Referenced record does not exist')
161
- }
162
- throw error
163
- }
164
- ```
165
-
166
- ### Migrations
167
- ```typescript
168
- // Using db-migrate
169
- import { migrate } from 'db-migrate'
170
-
171
- await migrate({
172
- config: {
173
- dev: {
174
- driver: 'mysql',
175
- database: process.env.DB_NAME,
176
- user: process.env.DB_USER,
177
- password: process.env.DB_PASSWORD,
178
- host: process.env.DB_HOST,
179
- }
180
- },
181
- env: 'dev',
182
- })
183
- ```
184
-
185
- ## Best Practices
186
-
187
- ✅ **DO:**
188
- - Use connection pooling (10-20 connections typically)
189
- - Always use parameterized queries (? placeholders)
190
- - Use transactions for multi-step operations
191
- - Create indexes on frequently queried columns
192
- - Use EXPLAIN to optimize queries
193
- - Enable query caching for read-heavy workloads
194
- - Use InnoDB engine (ACID compliance)
195
- - Set appropriate charset (utf8mb4 for full Unicode)
196
- - Monitor slow query log
197
- - Use prepared statements for repeated queries
198
-
199
- ❌ **DON'T:**
200
- - Use string concatenation for queries (SQL injection risk)
201
- - Create too many connections (exhaust pool)
202
- - Skip error handling
203
- - Ignore connection pool limits
204
- - Use SELECT * in production (specify columns)
205
- - Skip indexes on foreign keys
206
- - Hardcode connection strings
207
- - Use MyISAM engine (no transactions)
208
- - Ignore query performance
209
- - Use synchronous queries
210
-
211
- ## Configuration
212
-
213
- ### Environment Variables
214
- ```bash
215
- DB_HOST=localhost
216
- DB_PORT=3306
217
- DB_NAME=myapp
218
- DB_USER=myuser
219
- DB_PASSWORD=securepassword
220
- DATABASE_URL=mysql://user:password@host:port/database
221
- ```
222
-
223
- ### Docker Compose
224
- ```yaml
225
- services:
226
- mysql:
227
- image: mysql:8.0
228
- environment:
229
- MYSQL_DATABASE: myapp
230
- MYSQL_USER: myuser
231
- MYSQL_PASSWORD: securepassword
232
- MYSQL_ROOT_PASSWORD: rootpassword
233
- ports:
234
- - "3306:3306"
235
- volumes:
236
- - mysql_data:/var/lib/mysql
237
- command: --default-authentication-plugin=mysql_native_password
238
- healthcheck:
239
- test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
240
- interval: 10s
241
- timeout: 5s
242
- retries: 5
243
-
244
- volumes:
245
- mysql_data:
246
- ```
247
-
248
- ### Prisma Schema
249
- ```prisma
250
- datasource db {
251
- provider = "mysql"
252
- url = env("DATABASE_URL")
253
- }
254
-
255
- model User {
256
- id Int @id @default(autoincrement())
257
- email String @unique @db.VarChar(255)
258
- name String? @db.VarChar(255)
259
- createdAt DateTime @default(now()) @db.Timestamp(6)
260
- posts Post[]
261
- }
262
-
263
- model Post {
264
- id Int @id @default(autoincrement())
265
- title String @db.VarChar(255)
266
- content String? @db.Text
267
- authorId Int
268
- author User @relation(fields: [authorId], references: [id])
269
- createdAt DateTime @default(now()) @db.Timestamp(6)
270
-
271
- @@index([authorId, createdAt(sort: Desc)])
272
- }
273
- ```
274
-
275
- ## Performance Optimization
276
-
277
- ### Indexing
278
- ```sql
279
- -- Single column index
280
- CREATE INDEX idx_users_email ON users(email);
281
-
282
- -- Composite index
283
- CREATE INDEX idx_posts_author_created ON posts(author_id, created_at DESC);
284
-
285
- -- Full-text index
286
- CREATE FULLTEXT INDEX idx_articles_content ON articles(title, content);
287
-
288
- -- Prefix index (for long strings)
289
- CREATE INDEX idx_users_name_prefix ON users(name(10));
290
- ```
291
-
292
- ### Query Optimization
293
- ```typescript
294
- // Use LIMIT for pagination
295
- const [rows] = await pool.execute(
296
- 'SELECT * FROM posts ORDER BY created_at DESC LIMIT ? OFFSET ?',
297
- [limit, offset]
298
- )
299
-
300
- // Use EXISTS instead of COUNT
301
- const [rows] = await pool.execute(
302
- 'SELECT EXISTS(SELECT 1 FROM users WHERE email = ?) as exists',
303
- [email]
304
- )
305
-
306
- // Use JOIN instead of subqueries when possible
307
- const [rows] = await pool.execute(`
308
- SELECT u.*, COUNT(p.id) as post_count
309
- FROM users u
310
- LEFT JOIN posts p ON u.id = p.author_id
311
- GROUP BY u.id
312
- `)
313
- ```
314
-
315
- ## Integration with Development
316
-
317
- ### Testing
318
- ```typescript
319
- // Use test database
320
- const testPool = mysql.createPool({
321
- database: 'myapp_test',
322
- // ... config
323
- })
324
-
325
- // Clean up after tests
326
- afterEach(async () => {
327
- await testPool.execute('SET FOREIGN_KEY_CHECKS = 0')
328
- await testPool.execute('TRUNCATE TABLE users')
329
- await testPool.execute('TRUNCATE TABLE posts')
330
- await testPool.execute('SET FOREIGN_KEY_CHECKS = 1')
331
- })
332
-
333
- // Use transactions for test isolation
334
- beforeEach(async () => {
335
- const connection = await testPool.getConnection()
336
- await connection.beginTransaction()
337
- // Store connection for rollback
338
- })
339
-
340
- afterEach(async () => {
341
- // Rollback transaction
342
- })
343
- ```
344
-
345
- ### Health Checks
346
- ```typescript
347
- async function checkDatabaseHealth(): Promise<boolean> {
348
- try {
349
- const [rows] = await pool.execute('SELECT 1 as health')
350
- return (rows as any[]).length > 0
351
- } catch {
352
- return false
353
- }
354
- }
355
- ```
356
-
357
- <!-- MYSQL:END -->
358
-
@@ -1,247 +0,0 @@
1
- <!-- NEO4J:START -->
2
- # Neo4j Graph Database Instructions
3
-
4
- **CRITICAL**: Use Neo4j for graph data modeling, relationship traversal, and complex connected data queries.
5
-
6
- ## Core Features
7
-
8
- ### Connection
9
- ```typescript
10
- // Using neo4j-driver
11
- import neo4j from 'neo4j-driver'
12
-
13
- const driver = neo4j.driver(
14
- process.env.NEO4J_URI || 'bolt://localhost:7687',
15
- neo4j.auth.basic(
16
- process.env.NEO4J_USER || 'neo4j',
17
- process.env.NEO4J_PASSWORD || 'password'
18
- ),
19
- {
20
- maxConnectionLifetime: 3 * 60 * 60 * 1000, // 3 hours
21
- maxConnectionPoolSize: 50,
22
- connectionAcquisitionTimeout: 2 * 60 * 1000, // 2 minutes
23
- }
24
- )
25
-
26
- const session = driver.session()
27
- ```
28
-
29
- ### Basic Operations
30
- ```typescript
31
- // Create node
32
- const result = await session.run(
33
- 'CREATE (u:User {id: $id, name: $name, email: $email}) RETURN u',
34
- { id: '1', name: 'John Doe', email: 'john@example.com' }
35
- )
36
-
37
- // Create relationship
38
- await session.run(
39
- 'MATCH (u:User {id: $userId}), (p:Post {id: $postId}) CREATE (u)-[:CREATED]->(p)',
40
- { userId: '1', postId: '1' }
41
- )
42
-
43
- // Find nodes
44
- const result = await session.run(
45
- 'MATCH (u:User {email: $email}) RETURN u',
46
- { email: 'john@example.com' }
47
- )
48
- const user = result.records[0]?.get('u')
49
-
50
- // Update node
51
- await session.run(
52
- 'MATCH (u:User {id: $id}) SET u.name = $name, u.updatedAt = $updatedAt',
53
- { id: '1', name: 'Jane Doe', updatedAt: new Date().toISOString() }
54
- )
55
-
56
- // Delete node and relationships
57
- await session.run(
58
- 'MATCH (u:User {id: $id}) DETACH DELETE u',
59
- { id: '1' }
60
- )
61
- ```
62
-
63
- ### Advanced Queries
64
- ```typescript
65
- // Find relationships
66
- const result = await session.run(`
67
- MATCH (u:User)-[r:FOLLOWS]->(f:User)
68
- WHERE u.id = $userId
69
- RETURN f, r.createdAt
70
- ORDER BY r.createdAt DESC
71
- LIMIT 10
72
- `, { userId: '1' })
73
-
74
- // Shortest path
75
- const result = await session.run(`
76
- MATCH path = shortestPath(
77
- (start:User {id: $startId})-[*]-(end:User {id: $endId})
78
- )
79
- RETURN path, length(path) as distance
80
- `, { startId: '1', endId: '2' })
81
-
82
- // Pattern matching
83
- const result = await session.run(`
84
- MATCH (u:User)-[:CREATED]->(p:Post)-[:TAGGED_WITH]->(t:Tag)
85
- WHERE t.name = $tagName
86
- RETURN u, count(p) as postCount
87
- ORDER BY postCount DESC
88
- `, { tagName: 'javascript' })
89
-
90
- // Aggregations
91
- const result = await session.run(`
92
- MATCH (u:User)-[:FOLLOWS]->(f:User)
93
- RETURN u.id, count(f) as followerCount
94
- ORDER BY followerCount DESC
95
- LIMIT 10
96
- `)
97
- ```
98
-
99
- ## Common Patterns
100
-
101
- ### User Recommendations
102
- ```typescript
103
- async function getRecommendedUsers(userId: string) {
104
- const result = await session.run(`
105
- MATCH (u:User {id: $userId})-[:FOLLOWS]->(f:User)-[:FOLLOWS]->(recommended:User)
106
- WHERE NOT (u)-[:FOLLOWS]->(recommended) AND u <> recommended
107
- RETURN recommended, count(recommended) as mutualFollowers
108
- ORDER BY mutualFollowers DESC
109
- LIMIT 10
110
- `, { userId })
111
-
112
- return result.records.map(record => ({
113
- user: record.get('recommended').properties,
114
- score: record.get('mutualFollowers').toNumber(),
115
- }))
116
- }
117
- ```
118
-
119
- ### Graph Traversal
120
- ```typescript
121
- async function findConnections(userId: string, depth: number) {
122
- const result = await session.run(`
123
- MATCH path = (start:User {id: $userId})-[*1..${depth}]-(connected:User)
124
- RETURN connected, length(path) as distance
125
- ORDER BY distance
126
- `, { userId })
127
-
128
- return result.records.map(record => ({
129
- user: record.get('connected').properties,
130
- distance: record.get('distance').toNumber(),
131
- }))
132
- }
133
- ```
134
-
135
- ### Transaction
136
- ```typescript
137
- const session = driver.session()
138
- const tx = session.beginTransaction()
139
-
140
- try {
141
- await tx.run('CREATE (u:User {id: $id, name: $name})', { id: '1', name: 'John' })
142
- await tx.run('CREATE (p:Post {id: $id, title: $title})', { id: '1', title: 'Post 1' })
143
- await tx.run(
144
- 'MATCH (u:User {id: $userId}), (p:Post {id: $postId}) CREATE (u)-[:CREATED]->(p)',
145
- { userId: '1', postId: '1' }
146
- )
147
- await tx.commit()
148
- } catch (error) {
149
- await tx.rollback()
150
- throw error
151
- } finally {
152
- await session.close()
153
- }
154
- ```
155
-
156
- ## Best Practices
157
-
158
- ✅ **DO:**
159
- - Use parameterized queries ($param)
160
- - Create indexes on frequently queried properties
161
- - Use appropriate relationship types
162
- - Batch operations when possible
163
- - Close sessions after use
164
- - Use transactions for multi-step operations
165
- - Monitor query performance
166
- - Use appropriate data types
167
- - Implement connection pooling
168
- - Use labels effectively
169
-
170
- ❌ **DON'T:**
171
- - Use string concatenation for queries (injection risk)
172
- - Create too many relationships per node
173
- - Skip error handling
174
- - Ignore query performance
175
- - Hardcode connection strings
176
- - Store large properties (use external storage)
177
- - Skip indexes on lookup properties
178
- - Ignore transaction boundaries
179
- - Use synchronous operations
180
- - Store sensitive data without encryption
181
-
182
- ## Configuration
183
-
184
- ### Environment Variables
185
- ```bash
186
- NEO4J_URI=bolt://localhost:7687
187
- NEO4J_URI=neo4j+s://cluster.example.com:7687 # SSL
188
- NEO4J_USER=neo4j
189
- NEO4J_PASSWORD=securepassword
190
- ```
191
-
192
- ### Docker Compose
193
- ```yaml
194
- services:
195
- neo4j:
196
- image: neo4j:5
197
- ports:
198
- - "7474:7474" # HTTP
199
- - "7687:7687" # Bolt
200
- environment:
201
- NEO4J_AUTH: neo4j/securepassword
202
- NEO4J_PLUGINS: '["apoc"]'
203
- volumes:
204
- - neo4j_data:/data
205
- - neo4j_logs:/logs
206
- healthcheck:
207
- test: ["CMD", "cypher-shell", "-u", "neo4j", "-p", "securepassword", "RETURN 1"]
208
- interval: 10s
209
- timeout: 5s
210
- retries: 5
211
-
212
- volumes:
213
- neo4j_data:
214
- neo4j_logs:
215
- ```
216
-
217
- ## Integration with Development
218
-
219
- ### Testing
220
- ```typescript
221
- // Use test database
222
- const testDriver = neo4j.driver('bolt://localhost:7688', neo4j.auth.basic('neo4j', 'test'))
223
-
224
- // Clean up after tests
225
- afterEach(async () => {
226
- const session = testDriver.session()
227
- await session.run('MATCH (n) DETACH DELETE n')
228
- await session.close()
229
- })
230
- ```
231
-
232
- ### Health Checks
233
- ```typescript
234
- async function checkNeo4jHealth(): Promise<boolean> {
235
- try {
236
- const session = driver.session()
237
- const result = await session.run('RETURN 1 as health')
238
- await session.close()
239
- return result.records.length > 0
240
- } catch {
241
- return false
242
- }
243
- }
244
- ```
245
-
246
- <!-- NEO4J:END -->
247
-
@@ -1,25 +0,0 @@
1
- <!-- OPENTELEMETRY:START -->
2
- # OpenTelemetry — Distributed Tracing
3
-
4
- ## Initialization
5
- - Initialize OTel SDK BEFORE application code (use `--require` flag or top-level import)
6
- - Configure exporter based on environment (OTLP, Jaeger, console for dev)
7
- - Set `serviceName` from environment: `process.env.OTEL_SERVICE_NAME`
8
-
9
- ## Instrumentation
10
- - Use auto-instrumentation packages for common libraries (HTTP, Express, pg)
11
- - Create manual spans for business logic operations:
12
- ```typescript
13
- const tracer = trace.getTracer('service-name');
14
- const span = tracer.startSpan('operation.name');
15
- try { ... } finally { span.end(); }
16
- ```
17
-
18
- ## Context Propagation
19
- - Always propagate context across service boundaries using W3C Trace Context headers
20
- - Use `context.with()` for async operations to preserve trace context
21
-
22
- ## Metrics
23
- - Use `@opentelemetry/sdk-metrics` for custom metrics
24
- - Follow naming conventions: `<namespace>.<metric_type>.<name>` (e.g., `http.server.request_count`)
25
- <!-- OPENTELEMETRY:END -->