claude-flow-novice 2.15.3 → 2.15.4

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 (461) hide show
  1. package/.claude/cfn-extras/skills/advanced-features/cfn-agent-swap/recommend-swap.sh +59 -59
  2. package/.claude/cfn-extras/skills/analytics/cfn-improvement-recommender/recommend-improvements.sh +91 -91
  3. package/.claude/cfn-extras/skills/analytics/cfn-pattern-extraction/extract-patterns.sh +79 -79
  4. package/.claude/cfn-extras/skills/analytics/cfn-retrospective-report/generate-report.sh +100 -100
  5. package/.claude/cfn-extras/skills/analytics/cfn-telemetry/start-telemetry.sh +110 -110
  6. package/.claude/cfn-extras/skills/deprecated/cfn-ace-system/add-bullet.sh +145 -145
  7. package/.claude/cfn-extras/skills/deprecated/cfn-ace-system/log-merge.sh +67 -67
  8. package/.claude/cfn-extras/skills/deprecated/cfn-ace-system/monitor-injection-performance.sh +137 -137
  9. package/.claude/cfn-extras/skills/deprecated/cfn-ace-system/optimize-injection-pipeline.sh +168 -168
  10. package/.claude/cfn-extras/skills/deprecated/cfn-ace-system/query-reflections.sh +35 -35
  11. package/.claude/cfn-extras/skills/deprecated/cfn-ace-system/store-reflection.sh +45 -45
  12. package/.claude/cfn-extras/skills/deprecated/cfn-ace-system/track-ab-test.sh +41 -41
  13. package/.claude/cfn-extras/skills/deprecated/cfn-ace-system/update-reflection.sh +41 -41
  14. package/.claude/cfn-extras/skills/deprecated/cfn-cli-setup/validate-cli-environment.sh +191 -191
  15. package/.claude/cfn-extras/skills/marketing/cfn-marketing-ad-campaigns/operations/create-campaign.sh +231 -231
  16. package/.claude/cfn-extras/skills/marketing/cfn-marketing-ad-campaigns/operations/get-campaign-performance.sh +190 -190
  17. package/.claude/cfn-extras/skills/marketing/cfn-marketing-ad-campaigns/operations/pause-campaign.sh +142 -142
  18. package/.claude/cfn-extras/skills/marketing/cfn-marketing-ad-campaigns/operations/set-budget.sh +181 -181
  19. package/.claude/cfn-extras/skills/marketing/cfn-marketing-ad-campaigns/operations/update-bid-strategy.sh +133 -133
  20. package/.claude/cfn-extras/skills/marketing/cfn-marketing-chatbot-conversations/operations/get-conversation-history.sh +121 -121
  21. package/.claude/cfn-extras/skills/marketing/cfn-marketing-chatbot-conversations/operations/qualify-lead.sh +156 -156
  22. package/.claude/cfn-extras/skills/marketing/cfn-marketing-chatbot-conversations/operations/schedule-demo.sh +181 -181
  23. package/.claude/cfn-extras/skills/marketing/cfn-marketing-chatbot-conversations/operations/send-message.sh +137 -137
  24. package/.claude/cfn-extras/skills/marketing/cfn-marketing-chatbot-conversations/operations/transfer-to-human.sh +179 -179
  25. package/.claude/cfn-extras/skills/marketing/cfn-marketing-sms-campaigns/operations/create-campaign.sh +183 -183
  26. package/.claude/cfn-extras/skills/marketing/cfn-marketing-sms-campaigns/operations/get-delivery-status.sh +139 -139
  27. package/.claude/cfn-extras/skills/marketing/cfn-marketing-sms-campaigns/operations/opt-out.sh +150 -150
  28. package/.claude/cfn-extras/skills/marketing/cfn-marketing-sms-campaigns/operations/schedule-campaign.sh +187 -187
  29. package/.claude/cfn-extras/skills/marketing/cfn-marketing-sms-campaigns/operations/send-sms.sh +181 -181
  30. package/.claude/cfn-extras/skills/ui-portal/cfn-web-portal/test-web-portal-skill.sh +50 -50
  31. package/.claude/cfn-extras/skills/ui-portal/cfn-web-portal/validate-deployment.sh +84 -84
  32. package/.claude/cfn-extras/skills/utility/cfn-environment-sanitization/sanitize-environment.sh +243 -243
  33. package/.claude/commands/cfn-loop-cli.md +16 -2
  34. package/.claude/commands/switch-api.md +31 -10
  35. package/.claude/hooks/cfn-lint-sql-injection.sh +61 -0
  36. package/.claude/hooks/cfn-post-edit-cfn-retrospective.sh +33 -2
  37. package/.claude/hooks/cfn-pre-edit-security-warning.sh +40 -0
  38. package/.claude/skills/cfn-agent-spawning/spawn-agent.sh +22 -24
  39. package/.claude/skills/cfn-docker-agent-spawning/SKILL.md +28 -4
  40. package/.claude/skills/cfn-docker-agent-spawning/spawn-agent.sh +3 -1
  41. package/.claude/skills/cfn-docker-loop-orchestration/orchestrate.sh +224 -20
  42. package/.claude/skills/cfn-loop-orchestration/helpers/gate-check.sh +550 -46
  43. package/.claude/skills/cfn-loop-orchestration/helpers/parse-test-results.sh +277 -0
  44. package/.claude/skills/cfn-loop-orchestration/orchestrate.sh +184 -23
  45. package/.claude/skills/cfn-loop-orchestration/security_utils.sh +24 -0
  46. package/.claude/skills/cfn-loop-orchestration/test-iteration-context-injection.sh +366 -0
  47. package/.claude/skills/cfn-redis-coordination/CENTRALIZED_REDIS_WRAPPER.md +319 -0
  48. package/.claude/skills/cfn-redis-coordination/agent-log.sh +4 -0
  49. package/.claude/skills/cfn-redis-coordination/agent-log.sh.bak +124 -0
  50. package/.claude/skills/cfn-redis-coordination/agent-recovery.sh +2 -2
  51. package/.claude/skills/cfn-redis-coordination/collect-confidence-scores.sh +30 -0
  52. package/.claude/skills/cfn-redis-coordination/get-context.sh +33 -0
  53. package/.claude/skills/cfn-redis-coordination/get-success-criteria.sh +54 -0
  54. package/.claude/skills/cfn-redis-coordination/invoke-waiting-mode.sh +3 -0
  55. package/.claude/skills/cfn-redis-coordination/redis-cli-wrapper.sh +24 -3
  56. package/.claude/skills/cfn-redis-coordination/redis-functions.sh +33 -0
  57. package/.claude/skills/cfn-redis-coordination/report-completion.sh +24 -31
  58. package/.claude/skills/cfn-redis-coordination/store-context.sh +4 -0
  59. package/.claude/skills/cfn-redis-coordination/store-success-criteria.sh +85 -0
  60. package/.claude/skills/cfn-redis-coordination/update-all-scripts.sh +67 -0
  61. package/.claude/skills/cfn-sqlite-memory/ttl-cleanup.sh +17 -25
  62. package/.claude/skills/cfn-transparency-middleware/test-e2e.sh +15 -0
  63. package/.claude/skills/cfn-transparency-middleware/tests/input-validation.sh +15 -0
  64. package/README.md +116 -475
  65. package/claude-assets/agents/cfn-dev-team/README.md +103 -0
  66. package/claude-assets/agents/cfn-dev-team/architecture/goal-planner.md +1 -1
  67. package/claude-assets/agents/cfn-dev-team/coordinators/cfn-frontend-coordinator.md +77 -15
  68. package/claude-assets/agents/cfn-dev-team/coordinators/cfn-v3-coordinator.md +355 -6
  69. package/claude-assets/agents/cfn-dev-team/coordinators/consensus-builder.md +82 -1
  70. package/claude-assets/agents/cfn-dev-team/coordinators/handoff-coordinator.md +82 -1
  71. package/claude-assets/agents/cfn-dev-team/coordinators/multi-sprint-coordinator.md +77 -15
  72. package/claude-assets/agents/cfn-dev-team/dev-ops/docker-specialist.md +99 -12
  73. package/claude-assets/agents/cfn-dev-team/dev-ops/github-commit-agent.md +1 -1
  74. package/claude-assets/agents/cfn-dev-team/dev-ops/kubernetes-specialist.md +97 -0
  75. package/claude-assets/agents/cfn-dev-team/dev-ops/monitoring-specialist.md +20 -1
  76. package/claude-assets/agents/cfn-dev-team/developers/api-gateway-specialist.md +97 -0
  77. package/claude-assets/agents/cfn-dev-team/developers/backend-developer.md +110 -13
  78. package/claude-assets/agents/cfn-dev-team/developers/data/data-engineer.md +106 -15
  79. package/claude-assets/agents/cfn-dev-team/developers/database/database-architect.md +115 -11
  80. package/claude-assets/agents/cfn-dev-team/developers/frontend/mobile-dev.md +94 -7
  81. package/claude-assets/agents/cfn-dev-team/developers/frontend/react-frontend-engineer.md +87 -9
  82. package/claude-assets/agents/cfn-dev-team/developers/frontend/typescript-specialist.md +85 -7
  83. package/claude-assets/agents/cfn-dev-team/developers/frontend/ui-designer.md +160 -28
  84. package/claude-assets/agents/cfn-dev-team/developers/graphql-specialist.md +101 -19
  85. package/claude-assets/agents/cfn-dev-team/developers/rust-developer.md +108 -14
  86. package/claude-assets/agents/cfn-dev-team/reviewers/{reviewer.md → code-reviewer.md} +95 -8
  87. package/claude-assets/agents/cfn-dev-team/reviewers/quality/code-quality-validator.md +107 -7
  88. package/claude-assets/agents/cfn-dev-team/reviewers/quality/perf-analyzer.md +98 -7
  89. package/claude-assets/agents/cfn-dev-team/reviewers/quality/performance-benchmarker.md +95 -7
  90. package/claude-assets/agents/cfn-dev-team/reviewers/quality/security-specialist.md +136 -9
  91. package/claude-assets/agents/cfn-dev-team/testers/api-testing-specialist.md +108 -1
  92. package/claude-assets/agents/cfn-dev-team/testers/chaos-engineering-specialist.md +107 -13
  93. package/claude-assets/agents/cfn-dev-team/testers/contract-tester.md +737 -0
  94. package/claude-assets/agents/cfn-dev-team/testers/e2e/playwright-tester.md +1 -1
  95. package/claude-assets/agents/cfn-dev-team/testers/integration-tester.md +828 -0
  96. package/claude-assets/agents/cfn-dev-team/testers/interaction-tester.md +106 -7
  97. package/claude-assets/agents/cfn-dev-team/testers/load-testing-specialist.md +77 -0
  98. package/claude-assets/agents/cfn-dev-team/testers/mutation-testing-specialist.md +684 -0
  99. package/claude-assets/agents/cfn-dev-team/testers/playwright-tester.md +110 -1
  100. package/claude-assets/agents/cfn-dev-team/testers/tester.md +94 -7
  101. package/claude-assets/agents/cfn-dev-team/utility/code-booster.md +1 -3
  102. package/claude-assets/agents/cfn-dev-team/utility/epic-creator.md +87 -13
  103. package/claude-assets/agents/cfn-dev-team/utility/memory-leak-specialist.md +103 -7
  104. package/claude-assets/agents/cfn-dev-team/utility/researcher.md +1 -3
  105. package/claude-assets/agents/cfn-dev-team/utility/z-ai-specialist.md +94 -7
  106. package/claude-assets/agents/docker-coordinators/cfn-docker-v3-coordinator.md +46 -0
  107. package/claude-assets/agents/project-only-agents/npm-package-specialist.md +1 -1
  108. package/claude-assets/cfn-extras/skills/advanced-features/cfn-agent-swap/recommend-swap.sh +59 -59
  109. package/claude-assets/cfn-extras/skills/analytics/cfn-improvement-recommender/recommend-improvements.sh +91 -91
  110. package/claude-assets/cfn-extras/skills/analytics/cfn-pattern-extraction/extract-patterns.sh +79 -79
  111. package/claude-assets/cfn-extras/skills/analytics/cfn-retrospective-report/generate-report.sh +100 -100
  112. package/claude-assets/cfn-extras/skills/analytics/cfn-telemetry/start-telemetry.sh +110 -110
  113. package/claude-assets/cfn-extras/skills/deprecated/cfn-ace-system/add-bullet.sh +145 -145
  114. package/claude-assets/cfn-extras/skills/deprecated/cfn-ace-system/log-merge.sh +67 -67
  115. package/claude-assets/cfn-extras/skills/deprecated/cfn-ace-system/monitor-injection-performance.sh +137 -137
  116. package/claude-assets/cfn-extras/skills/deprecated/cfn-ace-system/optimize-injection-pipeline.sh +168 -168
  117. package/claude-assets/cfn-extras/skills/deprecated/cfn-ace-system/query-reflections.sh +35 -35
  118. package/claude-assets/cfn-extras/skills/deprecated/cfn-ace-system/store-reflection.sh +45 -45
  119. package/claude-assets/cfn-extras/skills/deprecated/cfn-ace-system/track-ab-test.sh +41 -41
  120. package/claude-assets/cfn-extras/skills/deprecated/cfn-ace-system/update-reflection.sh +41 -41
  121. package/claude-assets/cfn-extras/skills/deprecated/cfn-cli-setup/validate-cli-environment.sh +191 -191
  122. package/claude-assets/cfn-extras/skills/marketing/cfn-marketing-ad-campaigns/operations/create-campaign.sh +231 -231
  123. package/claude-assets/cfn-extras/skills/marketing/cfn-marketing-ad-campaigns/operations/get-campaign-performance.sh +190 -190
  124. package/claude-assets/cfn-extras/skills/marketing/cfn-marketing-ad-campaigns/operations/pause-campaign.sh +142 -142
  125. package/claude-assets/cfn-extras/skills/marketing/cfn-marketing-ad-campaigns/operations/set-budget.sh +181 -181
  126. package/claude-assets/cfn-extras/skills/marketing/cfn-marketing-ad-campaigns/operations/update-bid-strategy.sh +133 -133
  127. package/claude-assets/cfn-extras/skills/marketing/cfn-marketing-chatbot-conversations/operations/get-conversation-history.sh +121 -121
  128. package/claude-assets/cfn-extras/skills/marketing/cfn-marketing-chatbot-conversations/operations/qualify-lead.sh +156 -156
  129. package/claude-assets/cfn-extras/skills/marketing/cfn-marketing-chatbot-conversations/operations/schedule-demo.sh +181 -181
  130. package/claude-assets/cfn-extras/skills/marketing/cfn-marketing-chatbot-conversations/operations/send-message.sh +137 -137
  131. package/claude-assets/cfn-extras/skills/marketing/cfn-marketing-chatbot-conversations/operations/transfer-to-human.sh +179 -179
  132. package/claude-assets/cfn-extras/skills/marketing/cfn-marketing-sms-campaigns/operations/create-campaign.sh +183 -183
  133. package/claude-assets/cfn-extras/skills/marketing/cfn-marketing-sms-campaigns/operations/get-delivery-status.sh +139 -139
  134. package/claude-assets/cfn-extras/skills/marketing/cfn-marketing-sms-campaigns/operations/opt-out.sh +150 -150
  135. package/claude-assets/cfn-extras/skills/marketing/cfn-marketing-sms-campaigns/operations/schedule-campaign.sh +187 -187
  136. package/claude-assets/cfn-extras/skills/marketing/cfn-marketing-sms-campaigns/operations/send-sms.sh +181 -181
  137. package/claude-assets/cfn-extras/skills/ui-portal/cfn-web-portal/test-web-portal-skill.sh +50 -50
  138. package/claude-assets/cfn-extras/skills/ui-portal/cfn-web-portal/validate-deployment.sh +84 -84
  139. package/claude-assets/cfn-extras/skills/utility/cfn-environment-sanitization/sanitize-environment.sh +243 -243
  140. package/claude-assets/commands/cfn-loop-cli.md +16 -2
  141. package/claude-assets/commands/switch-api.md +31 -10
  142. package/claude-assets/hooks/cfn-lint-sql-injection.sh +61 -0
  143. package/claude-assets/hooks/cfn-post-edit-cfn-retrospective.sh +33 -2
  144. package/claude-assets/hooks/cfn-pre-edit-security-warning.sh +40 -0
  145. package/claude-assets/hooks/detect-hardcoded-credentials.sh +212 -0
  146. package/claude-assets/skills/SKILL_TEMPLATE.md +774 -0
  147. package/claude-assets/skills/agent-lifecycle/execute-lifecycle-hook.sh +84 -113
  148. package/claude-assets/skills/agent-lifecycle/simple-audit.sh +33 -6
  149. package/claude-assets/skills/agent-template-generator/SKILL.md +440 -0
  150. package/claude-assets/skills/agent-template-generator/generate-agent.sh +405 -0
  151. package/claude-assets/skills/agent-validation-linter/SKILL.md +589 -0
  152. package/claude-assets/skills/agent-validation-linter/lint-agents.sh +271 -0
  153. package/claude-assets/skills/bootstrap/bash-fundamentals.md +786 -0
  154. package/claude-assets/skills/bootstrap/database-connection.md +464 -0
  155. package/claude-assets/skills/bootstrap/error-handling.md +580 -0
  156. package/claude-assets/skills/bootstrap/file-operations.md +699 -0
  157. package/claude-assets/skills/bootstrap/skill-loader.md +616 -0
  158. package/claude-assets/skills/bootstrap/sqlite-params.sh +287 -0
  159. package/claude-assets/skills/cfn-agent-spawning/spawn-agent.sh +22 -24
  160. package/claude-assets/skills/cfn-automatic-memory-persistence/test-memory-persistence.sh +17 -16
  161. package/claude-assets/skills/cfn-deployment/SKILL.md +293 -0
  162. package/claude-assets/skills/cfn-deployment/execute.sh +21 -0
  163. package/claude-assets/skills/cfn-docker-agent-spawning/SKILL.md +28 -4
  164. package/claude-assets/skills/cfn-docker-agent-spawning/spawn-agent.sh +3 -1
  165. package/claude-assets/skills/cfn-docker-loop-orchestration/orchestrate.sh +224 -20
  166. package/claude-assets/skills/cfn-environment-sanitization/sanitize-environment.sh +38 -0
  167. package/claude-assets/skills/cfn-error-batching-strategy/lib/core-functions.sh +47 -47
  168. package/claude-assets/skills/cfn-file-operations/SKILL.md +290 -0
  169. package/claude-assets/skills/cfn-file-operations/execute.sh +129 -0
  170. package/claude-assets/skills/cfn-file-operations/lib/atomic-write.sh +294 -0
  171. package/claude-assets/skills/cfn-file-operations/lib/lock.sh +361 -0
  172. package/claude-assets/skills/cfn-file-operations/test.sh +369 -0
  173. package/claude-assets/skills/cfn-log-operations/SKILL.md +308 -0
  174. package/claude-assets/skills/cfn-log-operations/execute.sh +420 -0
  175. package/claude-assets/skills/cfn-log-operations/lib/rotate.sh +406 -0
  176. package/claude-assets/skills/cfn-log-operations/lib/search.sh +448 -0
  177. package/claude-assets/skills/cfn-log-operations/test.sh +394 -0
  178. package/claude-assets/skills/cfn-loop-orchestration/helpers/gate-check.sh +550 -46
  179. package/claude-assets/skills/cfn-loop-orchestration/helpers/parse-test-results.sh +277 -0
  180. package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh +184 -23
  181. package/claude-assets/skills/cfn-loop-orchestration/security_utils.sh +24 -0
  182. package/claude-assets/skills/cfn-loop-orchestration/test-iteration-context-injection.sh +366 -0
  183. package/claude-assets/skills/cfn-parameterized-queries/SKILL.md +339 -0
  184. package/claude-assets/skills/cfn-playbook/query-playbook.sh +19 -15
  185. package/claude-assets/skills/cfn-playbook/update-playbook.sh +25 -14
  186. package/claude-assets/skills/cfn-process-instrumentation/instrument-process.sh +44 -0
  187. package/claude-assets/skills/cfn-promotion/SKILL.md +305 -0
  188. package/claude-assets/skills/cfn-redis-coordination/CENTRALIZED_REDIS_WRAPPER.md +319 -0
  189. package/claude-assets/skills/cfn-redis-coordination/agent-log.sh +4 -0
  190. package/claude-assets/skills/cfn-redis-coordination/agent-log.sh.bak +124 -0
  191. package/claude-assets/skills/cfn-redis-coordination/agent-recovery.sh +2 -2
  192. package/claude-assets/skills/cfn-redis-coordination/collect-confidence-scores.sh +30 -0
  193. package/claude-assets/skills/cfn-redis-coordination/get-context.sh +33 -0
  194. package/claude-assets/skills/cfn-redis-coordination/get-success-criteria.sh +54 -0
  195. package/claude-assets/skills/cfn-redis-coordination/invoke-waiting-mode.sh +3 -0
  196. package/claude-assets/skills/cfn-redis-coordination/redis-cli-wrapper.sh +24 -3
  197. package/claude-assets/skills/cfn-redis-coordination/redis-functions.sh +33 -0
  198. package/claude-assets/skills/cfn-redis-coordination/report-completion.sh +24 -31
  199. package/claude-assets/skills/cfn-redis-coordination/store-context.sh +4 -0
  200. package/claude-assets/skills/cfn-redis-coordination/store-success-criteria.sh +85 -0
  201. package/claude-assets/skills/cfn-redis-coordination/update-all-scripts.sh +67 -0
  202. package/claude-assets/skills/cfn-skill-loader/SKILL.md +466 -0
  203. package/claude-assets/skills/cfn-skill-loader/execute.sh +344 -0
  204. package/claude-assets/skills/cfn-sqlite-memory/ttl-cleanup.sh +17 -25
  205. package/claude-assets/skills/cfn-task-audit/get-audit-data.sh +42 -21
  206. package/claude-assets/skills/cfn-task-audit/store-task-audit.sh +17 -10
  207. package/claude-assets/skills/cfn-test-runner/detect-regressions.sh +17 -14
  208. package/claude-assets/skills/cfn-test-runner/detect-regressions.sh.backup-1763392821 +55 -0
  209. package/claude-assets/skills/cfn-test-runner/store-benchmarks.sh +17 -19
  210. package/claude-assets/skills/cfn-transparency-middleware/test-e2e.sh +15 -0
  211. package/claude-assets/skills/cfn-transparency-middleware/tests/input-validation.sh +15 -0
  212. package/claude-assets/skills/cfn-utilities/SKILL.md +237 -0
  213. package/claude-assets/skills/cfn-utilities/execute.sh +32 -0
  214. package/claude-assets/skills/cfn-utilities/lib/errors.sh +56 -0
  215. package/claude-assets/skills/cfn-utilities/lib/file-ops.sh +164 -0
  216. package/claude-assets/skills/cfn-utilities/lib/logging.sh +77 -0
  217. package/claude-assets/skills/cfn-utilities/lib/retry.sh +127 -0
  218. package/claude-assets/skills/cfn-utilities/test.sh +317 -0
  219. package/claude-assets/skills/integration/agent-handoff.sh +62 -64
  220. package/claude-assets/skills/json-validation/SKILL.md +431 -0
  221. package/claude-assets/skills/json-validation/test-validate-success-criteria.sh +421 -0
  222. package/claude-assets/skills/json-validation/validate-success-criteria.sh +197 -0
  223. package/claude-assets/skills/redis-coordination/validate-parameters.sh +34 -0
  224. package/claude-assets/skills/workflow-codification/DEPLOY_QUICK_REFERENCE.md +106 -0
  225. package/claude-assets/skills/workflow-codification/PROPAGATE_UPDATE_QUICK_REFERENCE.md +366 -0
  226. package/claude-assets/skills/workflow-codification/deploy-approved-skill.sh +481 -0
  227. package/claude-assets/skills/workflow-codification/deploy-approved-skill.sh.backup-1763392820 +512 -0
  228. package/claude-assets/skills/workflow-codification/lib/security-utils.sh +204 -0
  229. package/claude-assets/skills/workflow-codification/propagate-skill-update.sh +648 -0
  230. package/claude-assets/skills/workflow-codification/propagate-skill-update.sh.backup-1763392820 +664 -0
  231. package/claude-assets/skills/workflow-codification/test-integration.sh +15 -0
  232. package/claude-assets/skills/workflow-codification/test-metadata-update.sh +350 -0
  233. package/claude-assets/skills/workflow-codification/track-cost-savings.sh +55 -14
  234. package/claude-assets/skills/workflow-codification/track-cost-savings.sh.backup-1763392821 +445 -0
  235. package/claude-assets/skills/workflow-codification/track-edge-case.sh +27 -60
  236. package/claude-assets/skills/workflow-codification/workflow-codification.db +0 -0
  237. package/dist/ace/ace-curator.js +10 -2
  238. package/dist/ace/ace-curator.js.map +1 -1
  239. package/dist/ace/ace-generator.js +4 -0
  240. package/dist/ace/ace-generator.js.map +1 -1
  241. package/dist/ace/ace-reflector.js +1 -1
  242. package/dist/ace/ace-reflector.js.map +1 -1
  243. package/dist/ace/context-injection.js +24 -2
  244. package/dist/ace/context-injection.js.map +1 -1
  245. package/dist/agents/agent-loader.js +146 -165
  246. package/dist/agents/agent-loader.js.map +1 -1
  247. package/dist/agents/task-agent-integration.js +1 -1
  248. package/dist/agents/task-agent-integration.js.map +1 -1
  249. package/dist/api/health-endpoints.js +390 -0
  250. package/dist/api/health-endpoints.js.map +1 -0
  251. package/dist/cli/agent-executor.js +4 -1
  252. package/dist/cli/agent-executor.js.map +1 -1
  253. package/dist/cli/agent-prompt-builder.js +89 -1
  254. package/dist/cli/agent-prompt-builder.js.map +1 -1
  255. package/dist/cli/agent-spawn.js +130 -37
  256. package/dist/cli/agent-spawn.js.map +1 -1
  257. package/dist/cli/skill-cache-validator.js +412 -0
  258. package/dist/cli/skill-cache-validator.js.map +1 -0
  259. package/dist/cli/skill-cli.js +991 -0
  260. package/dist/cli/skill-cli.js.map +1 -0
  261. package/dist/cli/skill-execution-logger.js +284 -0
  262. package/dist/cli/skill-execution-logger.js.map +1 -0
  263. package/dist/cli/skill-loader.js +457 -0
  264. package/dist/cli/skill-loader.js.map +1 -0
  265. package/dist/coordination/event-bus.js +2 -2
  266. package/dist/coordination/event-bus.js.map +1 -1
  267. package/dist/coordination/fleet-manager.js +1 -1
  268. package/dist/coordination/fleet-manager.js.map +1 -1
  269. package/dist/coordination/index.js +23 -9
  270. package/dist/coordination/index.js.map +1 -1
  271. package/dist/coordination/types/fleet-manager.types.js.map +1 -1
  272. package/dist/db/migration-manager.js +483 -0
  273. package/dist/db/migration-manager.js.map +1 -0
  274. package/dist/db/skills-query.js +535 -0
  275. package/dist/db/skills-query.js.map +1 -0
  276. package/dist/integration/DatabaseHandoff.js +1 -1
  277. package/dist/integration/DatabaseHandoff.js.map +1 -1
  278. package/dist/jobs/edge-case-analyzer.js +367 -0
  279. package/dist/jobs/edge-case-analyzer.js.map +1 -0
  280. package/dist/jobs/promotion-sla-enforcer.js +288 -0
  281. package/dist/jobs/promotion-sla-enforcer.js.map +1 -0
  282. package/dist/lib/agent-output-parser.js.map +1 -1
  283. package/dist/lib/agent-output-validator.js.map +1 -1
  284. package/dist/lib/agent-workspace.js +281 -0
  285. package/dist/lib/agent-workspace.js.map +1 -0
  286. package/dist/lib/atomic-file-writer.js +377 -0
  287. package/dist/lib/atomic-file-writer.js.map +1 -0
  288. package/dist/lib/backup-manager.js +779 -0
  289. package/dist/lib/backup-manager.js.map +1 -0
  290. package/dist/lib/checkpoint-manager.js +837 -0
  291. package/dist/lib/checkpoint-manager.js.map +1 -0
  292. package/dist/lib/circuit-breaker.js +340 -0
  293. package/dist/lib/circuit-breaker.js.map +1 -0
  294. package/dist/lib/completion-signal-handler.js +243 -0
  295. package/dist/lib/completion-signal-handler.js.map +1 -0
  296. package/dist/lib/config-manager.js +312 -0
  297. package/dist/lib/config-manager.js.map +1 -0
  298. package/dist/lib/config-migrator.js +386 -0
  299. package/dist/lib/config-migrator.js.map +1 -0
  300. package/dist/lib/config-validator.js.map +1 -1
  301. package/dist/lib/correlation-cache.js +311 -0
  302. package/dist/lib/correlation-cache.js.map +1 -0
  303. package/dist/lib/correlation.js +263 -0
  304. package/dist/lib/correlation.js.map +1 -0
  305. package/dist/lib/database-service/connection-pool-manager.js +520 -0
  306. package/dist/lib/database-service/connection-pool-manager.js.map +1 -0
  307. package/dist/lib/database-service/correlation.js +329 -0
  308. package/dist/lib/database-service/correlation.js.map +1 -0
  309. package/dist/lib/database-service/errors.js +120 -0
  310. package/dist/lib/database-service/errors.js.map +1 -0
  311. package/dist/lib/database-service/index.js +168 -0
  312. package/dist/lib/database-service/index.js.map +1 -0
  313. package/dist/lib/database-service/postgres-adapter.js +526 -0
  314. package/dist/lib/database-service/postgres-adapter.js.map +1 -0
  315. package/dist/lib/database-service/redis-adapter.js +360 -0
  316. package/dist/lib/database-service/redis-adapter.js.map +1 -0
  317. package/dist/lib/database-service/sqlite-adapter.js +544 -0
  318. package/dist/lib/database-service/sqlite-adapter.js.map +1 -0
  319. package/dist/lib/database-service/transaction-manager.js +773 -0
  320. package/dist/lib/database-service/transaction-manager.js.map +1 -0
  321. package/dist/lib/database-service/types.js +23 -0
  322. package/dist/lib/database-service/types.js.map +1 -0
  323. package/dist/lib/deadlock-resolver.js +292 -0
  324. package/dist/lib/deadlock-resolver.js.map +1 -0
  325. package/dist/lib/distributed-lock.js +451 -0
  326. package/dist/lib/distributed-lock.js.map +1 -0
  327. package/dist/lib/edge-case-deduplicator.js +227 -0
  328. package/dist/lib/edge-case-deduplicator.js.map +1 -0
  329. package/dist/lib/encryption-manager.js +322 -0
  330. package/dist/lib/encryption-manager.js.map +1 -0
  331. package/dist/lib/error-aggregator.js +234 -0
  332. package/dist/lib/error-aggregator.js.map +1 -0
  333. package/dist/lib/errors.js +287 -0
  334. package/dist/lib/errors.js.map +1 -0
  335. package/dist/lib/file-lock-manager.js +578 -0
  336. package/dist/lib/file-lock-manager.js.map +1 -0
  337. package/dist/lib/file-operations.js +367 -0
  338. package/dist/lib/file-operations.js.map +1 -0
  339. package/dist/lib/idempotent-write.js +237 -0
  340. package/dist/lib/idempotent-write.js.map +1 -0
  341. package/dist/lib/integration-schema-validator.js +522 -0
  342. package/dist/lib/integration-schema-validator.js.map +1 -0
  343. package/dist/lib/lock-health-monitor.js +298 -0
  344. package/dist/lib/lock-health-monitor.js.map +1 -0
  345. package/dist/lib/log-shipper.js +422 -0
  346. package/dist/lib/log-shipper.js.map +1 -0
  347. package/dist/lib/logging.js +146 -0
  348. package/dist/lib/logging.js.map +1 -0
  349. package/dist/lib/message-deduplicator.js +439 -0
  350. package/dist/lib/message-deduplicator.js.map +1 -0
  351. package/dist/lib/multi-system-query.js +604 -0
  352. package/dist/lib/multi-system-query.js.map +1 -0
  353. package/dist/lib/orphan-detector.js +332 -0
  354. package/dist/lib/orphan-detector.js.map +1 -0
  355. package/dist/lib/password-generator.js +166 -0
  356. package/dist/lib/password-generator.js.map +1 -0
  357. package/dist/lib/path-validator.js +429 -0
  358. package/dist/lib/path-validator.js.map +1 -0
  359. package/dist/lib/query-translator.js +905 -0
  360. package/dist/lib/query-translator.js.map +1 -0
  361. package/dist/lib/queue-recovery.js +469 -0
  362. package/dist/lib/queue-recovery.js.map +1 -0
  363. package/dist/lib/redis-queue-manager.js +512 -0
  364. package/dist/lib/redis-queue-manager.js.map +1 -0
  365. package/dist/lib/reflection-archiver.js +272 -0
  366. package/dist/lib/reflection-archiver.js.map +1 -0
  367. package/dist/lib/retry-manager.js +453 -0
  368. package/dist/lib/retry-manager.js.map +1 -0
  369. package/dist/lib/retry.js +262 -0
  370. package/dist/lib/retry.js.map +1 -0
  371. package/dist/lib/schema-transform.js +695 -0
  372. package/dist/lib/schema-transform.js.map +1 -0
  373. package/dist/lib/schema-validator.js +491 -0
  374. package/dist/lib/schema-validator.js.map +1 -0
  375. package/dist/lib/skill-cache.js +297 -0
  376. package/dist/lib/skill-cache.js.map +1 -0
  377. package/dist/lib/skill-content-manager.js +337 -0
  378. package/dist/lib/skill-content-manager.js.map +1 -0
  379. package/dist/lib/skill-frontmatter-parser.js +237 -0
  380. package/dist/lib/skill-frontmatter-parser.js.map +1 -0
  381. package/dist/lib/skill-git-integration.js +275 -0
  382. package/dist/lib/skill-git-integration.js.map +1 -0
  383. package/dist/lib/skill-markdown-validator.js +396 -0
  384. package/dist/lib/skill-markdown-validator.js.map +1 -0
  385. package/dist/lib/skill-output-parser.js +312 -0
  386. package/dist/lib/skill-output-parser.js.map +1 -0
  387. package/dist/lib/unified-query-api.js +467 -0
  388. package/dist/lib/unified-query-api.js.map +1 -0
  389. package/dist/middleware/auth-middleware.js +350 -0
  390. package/dist/middleware/auth-middleware.js.map +1 -0
  391. package/dist/middleware/schema-validation.js +347 -0
  392. package/dist/middleware/schema-validation.js.map +1 -0
  393. package/dist/providers/anthropic-provider.js +1 -1
  394. package/dist/providers/anthropic-provider.js.map +1 -1
  395. package/dist/providers/provider-factory.js +2 -2
  396. package/dist/providers/provider-factory.js.map +1 -1
  397. package/dist/services/edge-case-analyzer.js +321 -0
  398. package/dist/services/edge-case-analyzer.js.map +1 -0
  399. package/dist/services/edge-case-deduplicator.js +266 -0
  400. package/dist/services/edge-case-deduplicator.js.map +1 -0
  401. package/dist/services/edge-case-detector.js +337 -0
  402. package/dist/services/edge-case-detector.js.map +1 -0
  403. package/dist/services/edge-case-tracker.js +547 -0
  404. package/dist/services/edge-case-tracker.js.map +1 -0
  405. package/dist/services/health-check-system.js +586 -0
  406. package/dist/services/health-check-system.js.map +1 -0
  407. package/dist/services/metrics-logger.js +412 -0
  408. package/dist/services/metrics-logger.js.map +1 -0
  409. package/dist/services/patch-generator.js +378 -0
  410. package/dist/services/patch-generator.js.map +1 -0
  411. package/dist/services/patch-validator.js +337 -0
  412. package/dist/services/patch-validator.js.map +1 -0
  413. package/dist/services/performance-monitor.js +811 -0
  414. package/dist/services/performance-monitor.js.map +1 -0
  415. package/dist/services/promotion-pipeline.js +918 -0
  416. package/dist/services/promotion-pipeline.js.map +1 -0
  417. package/dist/services/promotion-validator.js +394 -0
  418. package/dist/services/promotion-validator.js.map +1 -0
  419. package/dist/services/reflection-logger.js +388 -0
  420. package/dist/services/reflection-logger.js.map +1 -0
  421. package/dist/services/skill-deployment.js +472 -0
  422. package/dist/services/skill-deployment.js.map +1 -0
  423. package/dist/services/skill-loader.js +427 -0
  424. package/dist/services/skill-loader.js.map +1 -0
  425. package/dist/services/skill-promotion.js +372 -0
  426. package/dist/services/skill-promotion.js.map +1 -0
  427. package/dist/services/skill-validator.js +454 -0
  428. package/dist/services/skill-validator.js.map +1 -0
  429. package/dist/services/skill-versioning.js +244 -0
  430. package/dist/services/skill-versioning.js.map +1 -0
  431. package/dist/services/workspace-supervisor.js +597 -0
  432. package/dist/services/workspace-supervisor.js.map +1 -0
  433. package/dist/types/edge-case.js +45 -0
  434. package/dist/types/edge-case.js.map +1 -0
  435. package/package.json +201 -177
  436. package/readme/README.md +19 -4
  437. package/scripts/backup-cleanup.sh +627 -0
  438. package/scripts/cleanup-workspaces.sh +412 -0
  439. package/scripts/cleanup-yaml-configs.sh +141 -0
  440. package/scripts/deploy-approved-skills.sh +263 -0
  441. package/scripts/health-check.sh +447 -0
  442. package/scripts/log-aggregator.sh +554 -0
  443. package/scripts/log-monitor.sh +629 -0
  444. package/scripts/manage-agent-workspaces.sh +434 -0
  445. package/scripts/migrate-schema.sh +533 -0
  446. package/scripts/promote-staged-skills.sh +423 -0
  447. package/scripts/verify-no-secrets.sh +88 -35
  448. package/.claude/cfn-extras/agents/deprecated-coordinators/adaptive-coordinator.md.backup +0 -161
  449. package/.claude/cfn-extras/agents/deprecated-coordinators/blocking-coordinator-example.md.backup +0 -728
  450. package/.claude/cfn-extras/agents/deprecated-coordinators/mesh-coordinator.md.backup +0 -131
  451. package/.claude/skills/agent-lifecycle/SKILL.md +0 -60
  452. package/.claude/skills/agent-lifecycle/execute-lifecycle-hook.sh +0 -573
  453. package/.claude/skills/agent-lifecycle/simple-audit.sh +0 -31
  454. package/.claude/skills/cfn-agent-spawning/spawn-agent.sh.backup +0 -273
  455. package/.claude/skills/cfn-loop-orchestration/orchestrate.sh.backup +0 -949
  456. package/README.md.backup_before_replace +0 -781
  457. package/claude-assets/cfn-extras/agents/deprecated-coordinators/adaptive-coordinator.md.backup +0 -161
  458. package/claude-assets/cfn-extras/agents/deprecated-coordinators/blocking-coordinator-example.md.backup +0 -728
  459. package/claude-assets/cfn-extras/agents/deprecated-coordinators/mesh-coordinator.md.backup +0 -131
  460. package/claude-assets/skills/cfn-agent-spawning/spawn-agent.sh.backup +0 -273
  461. package/claude-assets/skills/cfn-loop-orchestration/orchestrate.sh.backup +0 -949
@@ -0,0 +1,520 @@
1
+ /**
2
+ * Connection Pool Manager
3
+ *
4
+ * Manages connection pools for database adapters with:
5
+ * - Automatic initialization on service startup
6
+ * - Connection health checks (ping every 30s)
7
+ * - Automatic reconnection with exponential backoff
8
+ * - Connection metrics (active, idle, pending)
9
+ * - Graceful degradation on connection failures
10
+ *
11
+ * Part of Bug Fix: Connection Pool Initialization
12
+ */ import sqlite3 from 'sqlite3';
13
+ import { open } from 'sqlite';
14
+ import { createClient } from 'redis';
15
+ import { Pool } from 'pg';
16
+ import { DatabaseErrorCode } from './types.js';
17
+ import { createDatabaseError } from './errors.js';
18
+ /**
19
+ * Connection Pool Manager
20
+ *
21
+ * Manages connection lifecycle, health checks, and automatic recovery
22
+ */ export class ConnectionPoolManager {
23
+ config;
24
+ options;
25
+ pool = null;
26
+ connections = new Set();
27
+ activeConnections = new Set();
28
+ pendingRequests = [];
29
+ healthCheckInterval;
30
+ lastHealthCheck;
31
+ healthCheckActive = false;
32
+ reconnectAttempts = 0;
33
+ maxReconnectAttempts = 10;
34
+ failedAttempts = 0;
35
+ startTime;
36
+ isShuttingDown = false;
37
+ cacheFallbackEnabled = false;
38
+ cache = new Map();
39
+ constructor(config, options = {}){
40
+ this.config = config;
41
+ this.options = {
42
+ minConnections: options.minConnections ?? 2,
43
+ maxConnections: options.maxConnections ?? config.poolSize ?? 10,
44
+ acquireTimeout: options.acquireTimeout ?? config.timeout ?? 5000,
45
+ idleTimeout: options.idleTimeout ?? 30000,
46
+ healthCheckInterval: options.healthCheckInterval ?? 30000,
47
+ maxReconnectAttempts: options.maxReconnectAttempts ?? 10,
48
+ reconnectBaseDelay: options.reconnectBaseDelay ?? 1000
49
+ };
50
+ this.maxReconnectAttempts = this.options.maxReconnectAttempts;
51
+ this.startTime = new Date();
52
+ }
53
+ /**
54
+ * Initialize connection pool
55
+ */ async initialize() {
56
+ try {
57
+ switch(this.config.type){
58
+ case 'sqlite':
59
+ await this.initializeSQLitePool();
60
+ break;
61
+ case 'redis':
62
+ await this.initializeRedisPool();
63
+ break;
64
+ case 'postgres':
65
+ await this.initializePostgresPool();
66
+ break;
67
+ default:
68
+ throw new Error(`Unsupported database type: ${this.config.type}`);
69
+ }
70
+ // Initialize minimum connections
71
+ await this.warmUpPool();
72
+ } catch (err) {
73
+ this.failedAttempts++;
74
+ throw createDatabaseError(DatabaseErrorCode.CONNECTION_FAILED, `Failed to initialize ${this.config.type} connection pool`, err instanceof Error ? err : new Error(String(err)), {
75
+ config: this.config
76
+ });
77
+ }
78
+ }
79
+ /**
80
+ * Initialize SQLite connection pool
81
+ */ async initializeSQLitePool() {
82
+ const dbPath = this.config.database || this.config.connectionString || ':memory:';
83
+ if (!dbPath || dbPath === '') {
84
+ throw new Error('SQLite database path is required');
85
+ }
86
+ // Create connection pool for SQLite
87
+ for(let i = 0; i < this.options.minConnections; i++){
88
+ const db = await open({
89
+ filename: dbPath,
90
+ driver: sqlite3.Database
91
+ });
92
+ await db.run('PRAGMA foreign_keys = ON');
93
+ await db.run(`PRAGMA busy_timeout = ${this.config.timeout || 5000}`);
94
+ this.connections.add(db);
95
+ }
96
+ }
97
+ /**
98
+ * Initialize Redis connection pool
99
+ */ async initializeRedisPool() {
100
+ let url = this.config.connectionString;
101
+ if (!url) {
102
+ // Build connection string with optional authentication
103
+ const host = this.config.host || 'localhost';
104
+ const port = this.config.port || 6379;
105
+ if (this.config.password) {
106
+ // Include password in connection string: redis://:password@host:port
107
+ url = `redis://:${encodeURIComponent(this.config.password)}@${host}:${port}`;
108
+ } else {
109
+ url = `redis://${host}:${port}`;
110
+ }
111
+ }
112
+ this.pool = createClient({
113
+ url,
114
+ socket: {
115
+ connectTimeout: this.config.timeout || 5000,
116
+ reconnectStrategy: (retries)=>{
117
+ if (retries > this.maxReconnectAttempts) {
118
+ return false;
119
+ }
120
+ // Exponential backoff
121
+ return Math.min(this.options.reconnectBaseDelay * Math.pow(2, retries), 30000);
122
+ }
123
+ }
124
+ });
125
+ // Set up event handlers
126
+ this.pool.on('error', (err)=>{
127
+ console.error('Redis connection error:', err);
128
+ this.failedAttempts++;
129
+ });
130
+ this.pool.on('reconnecting', ()=>{
131
+ this.reconnectAttempts++;
132
+ });
133
+ await this.pool.connect();
134
+ }
135
+ /**
136
+ * Initialize PostgreSQL connection pool
137
+ */ async initializePostgresPool() {
138
+ const connectionString = this.config.connectionString || `postgresql://${this.config.username}:${this.config.password}@${this.config.host}:${this.config.port}/${this.config.database}`;
139
+ this.pool = new Pool({
140
+ connectionString,
141
+ min: this.options.minConnections,
142
+ max: this.options.maxConnections,
143
+ idleTimeoutMillis: this.options.idleTimeout,
144
+ connectionTimeoutMillis: this.options.acquireTimeout
145
+ });
146
+ // Test connection
147
+ const client = await this.pool.connect();
148
+ await client.query('SELECT 1');
149
+ client.release();
150
+ }
151
+ /**
152
+ * Warm up pool by creating minimum connections
153
+ */ async warmUpPool() {
154
+ if (this.config.type === 'sqlite') {
155
+ // SQLite connections already created in initializeSQLitePool
156
+ return;
157
+ }
158
+ // For Redis and Postgres, connections are managed by their libraries
159
+ // We just need to verify connectivity
160
+ if (this.config.type === 'redis') {
161
+ await this.pool.ping();
162
+ } else if (this.config.type === 'postgres') {
163
+ const client = await this.pool.connect();
164
+ await client.query('SELECT 1');
165
+ client.release();
166
+ }
167
+ }
168
+ /**
169
+ * Acquire connection from pool
170
+ */ async acquire() {
171
+ if (this.isShuttingDown) {
172
+ throw createDatabaseError(DatabaseErrorCode.CONNECTION_FAILED, 'Connection pool is shutting down', undefined, {
173
+ type: this.config.type
174
+ });
175
+ }
176
+ const startTime = Date.now();
177
+ try {
178
+ switch(this.config.type){
179
+ case 'sqlite':
180
+ return await this.acquireSQLiteConnection(startTime);
181
+ case 'redis':
182
+ return this.pool;
183
+ case 'postgres':
184
+ return await this.pool.connect();
185
+ default:
186
+ throw new Error(`Unsupported database type: ${this.config.type}`);
187
+ }
188
+ } catch (err) {
189
+ throw createDatabaseError(DatabaseErrorCode.CONNECTION_FAILED, 'Failed to acquire connection', err instanceof Error ? err : new Error(String(err)), {
190
+ type: this.config.type
191
+ });
192
+ }
193
+ }
194
+ /**
195
+ * Acquire SQLite connection from pool
196
+ */ async acquireSQLiteConnection(startTime) {
197
+ // Check for available connection
198
+ const availableConnection = Array.from(this.connections).find((conn)=>!this.activeConnections.has(conn));
199
+ if (availableConnection) {
200
+ this.activeConnections.add(availableConnection);
201
+ return availableConnection;
202
+ }
203
+ // Check if we can create more connections
204
+ if (this.connections.size < this.options.maxConnections) {
205
+ const newConnection = await this.createSQLiteConnection();
206
+ this.connections.add(newConnection);
207
+ this.activeConnections.add(newConnection);
208
+ return newConnection;
209
+ }
210
+ // Queue request
211
+ return new Promise((resolve, reject)=>{
212
+ const timeoutId = setTimeout(()=>{
213
+ const index = this.pendingRequests.findIndex((req)=>req.resolve === resolve);
214
+ if (index !== -1) {
215
+ this.pendingRequests.splice(index, 1);
216
+ }
217
+ reject(createDatabaseError(DatabaseErrorCode.TIMEOUT, 'Connection acquisition timeout', undefined, {
218
+ timeout: this.options.acquireTimeout
219
+ }));
220
+ }, this.options.acquireTimeout);
221
+ this.pendingRequests.push({
222
+ resolve: (conn)=>{
223
+ clearTimeout(timeoutId);
224
+ resolve(conn);
225
+ },
226
+ reject: (err)=>{
227
+ clearTimeout(timeoutId);
228
+ reject(err);
229
+ },
230
+ timestamp: startTime
231
+ });
232
+ });
233
+ }
234
+ /**
235
+ * Create new SQLite connection
236
+ */ async createSQLiteConnection() {
237
+ const dbPath = this.config.database || this.config.connectionString || ':memory:';
238
+ const db = await open({
239
+ filename: dbPath,
240
+ driver: sqlite3.Database
241
+ });
242
+ await db.run('PRAGMA foreign_keys = ON');
243
+ await db.run(`PRAGMA busy_timeout = ${this.config.timeout || 5000}`);
244
+ return db;
245
+ }
246
+ /**
247
+ * Release connection back to pool
248
+ */ async release(connection) {
249
+ if (!connection) {
250
+ return;
251
+ }
252
+ try {
253
+ switch(this.config.type){
254
+ case 'sqlite':
255
+ this.releaseSQLiteConnection(connection);
256
+ break;
257
+ case 'redis':
258
+ break;
259
+ case 'postgres':
260
+ if (connection && typeof connection.release === 'function') {
261
+ connection.release();
262
+ }
263
+ break;
264
+ }
265
+ } catch (err) {
266
+ console.error('Failed to release connection:', err);
267
+ }
268
+ }
269
+ /**
270
+ * Release SQLite connection
271
+ */ releaseSQLiteConnection(connection) {
272
+ this.activeConnections.delete(connection);
273
+ // Process pending requests
274
+ if (this.pendingRequests.length > 0) {
275
+ const pending = this.pendingRequests.shift();
276
+ if (pending) {
277
+ this.activeConnections.add(connection);
278
+ pending.resolve(connection);
279
+ }
280
+ }
281
+ }
282
+ /**
283
+ * Start periodic health checks
284
+ */ startHealthChecks() {
285
+ if (this.healthCheckActive) {
286
+ return;
287
+ }
288
+ this.healthCheckActive = true;
289
+ this.healthCheckInterval = setInterval(async ()=>{
290
+ try {
291
+ const healthy = await this.performHealthCheck();
292
+ this.lastHealthCheck = new Date();
293
+ if (!healthy) {
294
+ console.warn(`Health check failed for ${this.config.type} pool`);
295
+ await this.attemptReconnection();
296
+ }
297
+ } catch (err) {
298
+ console.error('Health check error:', err);
299
+ }
300
+ }, this.options.healthCheckInterval);
301
+ }
302
+ /**
303
+ * Stop health checks
304
+ */ stopHealthChecks() {
305
+ if (this.healthCheckInterval) {
306
+ clearInterval(this.healthCheckInterval);
307
+ this.healthCheckInterval = undefined;
308
+ }
309
+ this.healthCheckActive = false;
310
+ }
311
+ /**
312
+ * Perform health check
313
+ */ async performHealthCheck() {
314
+ try {
315
+ switch(this.config.type){
316
+ case 'sqlite':
317
+ {
318
+ const connection = Array.from(this.connections)[0];
319
+ if (connection) {
320
+ await connection.get('SELECT 1');
321
+ return true;
322
+ }
323
+ return false;
324
+ }
325
+ case 'redis':
326
+ if (this.pool) {
327
+ await this.pool.ping();
328
+ return true;
329
+ }
330
+ return false;
331
+ case 'postgres':
332
+ if (this.pool) {
333
+ const client = await this.pool.connect();
334
+ await client.query('SELECT 1');
335
+ client.release();
336
+ return true;
337
+ }
338
+ return false;
339
+ default:
340
+ return false;
341
+ }
342
+ } catch (err) {
343
+ return false;
344
+ }
345
+ }
346
+ /**
347
+ * Check if pool is healthy (exposed for testing)
348
+ */ async isHealthy() {
349
+ return this.performHealthCheck();
350
+ }
351
+ /**
352
+ * Attempt reconnection with exponential backoff
353
+ */ async attemptReconnection() {
354
+ if (this.reconnectAttempts >= this.maxReconnectAttempts) {
355
+ console.error(`Max reconnection attempts (${this.maxReconnectAttempts}) reached for ${this.config.type}`);
356
+ return;
357
+ }
358
+ const delay = Math.min(this.options.reconnectBaseDelay * Math.pow(2, this.reconnectAttempts), 30000);
359
+ this.reconnectAttempts++;
360
+ await new Promise((resolve)=>setTimeout(resolve, delay));
361
+ try {
362
+ await this.initialize();
363
+ console.log(`Reconnection successful for ${this.config.type}`);
364
+ this.reconnectAttempts = 0;
365
+ } catch (err) {
366
+ console.error(`Reconnection failed for ${this.config.type}:`, err);
367
+ }
368
+ }
369
+ /**
370
+ * Get reconnection delays for testing
371
+ */ getReconnectDelays() {
372
+ const delays = [];
373
+ for(let i = 0; i < 5; i++){
374
+ delays.push(Math.min(this.options.reconnectBaseDelay * Math.pow(2, i), 30000));
375
+ }
376
+ return delays;
377
+ }
378
+ /**
379
+ * Simulate disconnection (for testing)
380
+ */ simulateDisconnection() {
381
+ if (this.config.type === 'redis' && this.pool) {
382
+ this.pool.disconnect();
383
+ } else if (this.config.type === 'postgres' && this.pool) {
384
+ this.pool.end();
385
+ }
386
+ }
387
+ /**
388
+ * Remove unhealthy connections (for testing)
389
+ */ removeUnhealthyConnections(count) {
390
+ if (this.config.type === 'sqlite') {
391
+ const connectionsToRemove = Array.from(this.connections).slice(0, count);
392
+ connectionsToRemove.forEach((conn)=>{
393
+ this.connections.delete(conn);
394
+ this.activeConnections.delete(conn);
395
+ conn.close();
396
+ });
397
+ }
398
+ }
399
+ /**
400
+ * Enable cache fallback for graceful degradation
401
+ */ enableCacheFallback(enabled) {
402
+ this.cacheFallbackEnabled = enabled;
403
+ }
404
+ /**
405
+ * Get data with cache fallback
406
+ */ async getWithFallback(key) {
407
+ try {
408
+ const connection = await this.acquire();
409
+ // Actual data retrieval would happen here
410
+ await this.release(connection);
411
+ return null;
412
+ } catch (err) {
413
+ if (this.cacheFallbackEnabled && this.cache.has(key)) {
414
+ console.warn(`Using cached data for key: ${key}`);
415
+ return this.cache.get(key);
416
+ }
417
+ throw err;
418
+ }
419
+ }
420
+ /**
421
+ * Get connection pool statistics
422
+ */ getStats() {
423
+ const now = Date.now();
424
+ const uptime = now - this.startTime.getTime();
425
+ switch(this.config.type){
426
+ case 'sqlite':
427
+ return {
428
+ type: 'sqlite',
429
+ total: this.connections.size,
430
+ active: this.activeConnections.size,
431
+ idle: this.connections.size - this.activeConnections.size,
432
+ pending: this.pendingRequests.length,
433
+ maxConnections: this.options.maxConnections,
434
+ available: this.connections.size - this.activeConnections.size,
435
+ healthy: this.connections.size > 0,
436
+ lastHealthCheck: this.lastHealthCheck,
437
+ healthCheckActive: this.healthCheckActive,
438
+ reconnectAttempts: this.reconnectAttempts,
439
+ failedAttempts: this.failedAttempts,
440
+ uptime
441
+ };
442
+ case 'redis':
443
+ return {
444
+ type: 'redis',
445
+ total: this.pool ? 1 : 0,
446
+ active: this.pool?.isOpen ? 1 : 0,
447
+ idle: 0,
448
+ pending: 0,
449
+ maxConnections: 1,
450
+ available: this.pool?.isOpen ? 1 : 0,
451
+ healthy: this.pool?.isOpen ?? false,
452
+ lastHealthCheck: this.lastHealthCheck,
453
+ healthCheckActive: this.healthCheckActive,
454
+ reconnectAttempts: this.reconnectAttempts,
455
+ failedAttempts: this.failedAttempts,
456
+ uptime
457
+ };
458
+ case 'postgres':
459
+ return {
460
+ type: 'postgres',
461
+ total: this.pool?.totalCount ?? 0,
462
+ active: (this.pool?.totalCount ?? 0) - (this.pool?.idleCount ?? 0),
463
+ idle: this.pool?.idleCount ?? 0,
464
+ pending: this.pool?.waitingCount ?? 0,
465
+ maxConnections: this.options.maxConnections,
466
+ available: this.pool?.idleCount ?? 0,
467
+ healthy: this.pool !== null,
468
+ lastHealthCheck: this.lastHealthCheck,
469
+ healthCheckActive: this.healthCheckActive,
470
+ reconnectAttempts: this.reconnectAttempts,
471
+ failedAttempts: this.failedAttempts,
472
+ uptime
473
+ };
474
+ default:
475
+ throw new Error(`Unsupported database type: ${this.config.type}`);
476
+ }
477
+ }
478
+ /**
479
+ * Shutdown connection pool
480
+ */ async shutdown() {
481
+ if (this.isShuttingDown) {
482
+ return;
483
+ }
484
+ this.isShuttingDown = true;
485
+ this.stopHealthChecks();
486
+ // Reject all pending requests
487
+ this.pendingRequests.forEach((req)=>{
488
+ req.reject(createDatabaseError(DatabaseErrorCode.CONNECTION_FAILED, 'Connection pool is shutting down', undefined, {
489
+ type: this.config.type
490
+ }));
491
+ });
492
+ this.pendingRequests = [];
493
+ // Close all connections
494
+ try {
495
+ switch(this.config.type){
496
+ case 'sqlite':
497
+ await Promise.all(Array.from(this.connections).map((conn)=>conn.close()));
498
+ this.connections.clear();
499
+ this.activeConnections.clear();
500
+ break;
501
+ case 'redis':
502
+ if (this.pool) {
503
+ await this.pool.quit();
504
+ this.pool = null;
505
+ }
506
+ break;
507
+ case 'postgres':
508
+ if (this.pool) {
509
+ await this.pool.end();
510
+ this.pool = null;
511
+ }
512
+ break;
513
+ }
514
+ } catch (err) {
515
+ console.error('Error during shutdown:', err);
516
+ }
517
+ }
518
+ }
519
+
520
+ //# sourceMappingURL=connection-pool-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/database-service/connection-pool-manager.ts"],"sourcesContent":["/**\r\n * Connection Pool Manager\r\n *\r\n * Manages connection pools for database adapters with:\r\n * - Automatic initialization on service startup\r\n * - Connection health checks (ping every 30s)\r\n * - Automatic reconnection with exponential backoff\r\n * - Connection metrics (active, idle, pending)\r\n * - Graceful degradation on connection failures\r\n *\r\n * Part of Bug Fix: Connection Pool Initialization\r\n */\r\n\r\nimport sqlite3 from 'sqlite3';\r\nimport { open, Database } from 'sqlite';\r\nimport { createClient, RedisClientType } from 'redis';\r\nimport { Pool, PoolClient } from 'pg';\r\nimport {\r\n DatabaseConfig,\r\n DatabaseErrorCode,\r\n} from './types.js';\r\nimport { createDatabaseError } from './errors.js';\r\n\r\nexport interface ConnectionPoolStats {\r\n type: 'redis' | 'sqlite' | 'postgres';\r\n total: number;\r\n active: number;\r\n idle: number;\r\n pending: number;\r\n maxConnections: number;\r\n available: number;\r\n healthy: boolean;\r\n lastHealthCheck?: Date;\r\n healthCheckActive: boolean;\r\n reconnectAttempts: number;\r\n failedAttempts: number;\r\n uptime: number;\r\n}\r\n\r\nexport interface PoolOptions {\r\n minConnections?: number;\r\n maxConnections?: number;\r\n acquireTimeout?: number;\r\n idleTimeout?: number;\r\n healthCheckInterval?: number;\r\n maxReconnectAttempts?: number;\r\n reconnectBaseDelay?: number;\r\n}\r\n\r\n/**\r\n * Connection Pool Manager\r\n *\r\n * Manages connection lifecycle, health checks, and automatic recovery\r\n */\r\nexport class ConnectionPoolManager {\r\n private config: DatabaseConfig;\r\n private options: Required<PoolOptions>;\r\n private pool: any = null;\r\n private connections: Set<any> = new Set();\r\n private activeConnections: Set<any> = new Set();\r\n private pendingRequests: Array<{\r\n resolve: (connection: any) => void;\r\n reject: (error: Error) => void;\r\n timestamp: number;\r\n }> = [];\r\n private healthCheckInterval?: NodeJS.Timeout;\r\n private lastHealthCheck?: Date;\r\n private healthCheckActive: boolean = false;\r\n private reconnectAttempts: number = 0;\r\n private maxReconnectAttempts: number = 10;\r\n private failedAttempts: number = 0;\r\n private startTime: Date;\r\n private isShuttingDown: boolean = false;\r\n private cacheFallbackEnabled: boolean = false;\r\n private cache: Map<string, any> = new Map();\r\n\r\n constructor(config: DatabaseConfig, options: PoolOptions = {}) {\r\n this.config = config;\r\n this.options = {\r\n minConnections: options.minConnections ?? 2,\r\n maxConnections: options.maxConnections ?? config.poolSize ?? 10,\r\n acquireTimeout: options.acquireTimeout ?? config.timeout ?? 5000,\r\n idleTimeout: options.idleTimeout ?? 30000,\r\n healthCheckInterval: options.healthCheckInterval ?? 30000,\r\n maxReconnectAttempts: options.maxReconnectAttempts ?? 10,\r\n reconnectBaseDelay: options.reconnectBaseDelay ?? 1000,\r\n };\r\n this.maxReconnectAttempts = this.options.maxReconnectAttempts;\r\n this.startTime = new Date();\r\n }\r\n\r\n /**\r\n * Initialize connection pool\r\n */\r\n async initialize(): Promise<void> {\r\n try {\r\n switch (this.config.type) {\r\n case 'sqlite':\r\n await this.initializeSQLitePool();\r\n break;\r\n case 'redis':\r\n await this.initializeRedisPool();\r\n break;\r\n case 'postgres':\r\n await this.initializePostgresPool();\r\n break;\r\n default:\r\n throw new Error(`Unsupported database type: ${this.config.type}`);\r\n }\r\n\r\n // Initialize minimum connections\r\n await this.warmUpPool();\r\n } catch (err) {\r\n this.failedAttempts++;\r\n throw createDatabaseError(\r\n DatabaseErrorCode.CONNECTION_FAILED,\r\n `Failed to initialize ${this.config.type} connection pool`,\r\n err instanceof Error ? err : new Error(String(err)),\r\n { config: this.config }\r\n );\r\n }\r\n }\r\n\r\n /**\r\n * Initialize SQLite connection pool\r\n */\r\n private async initializeSQLitePool(): Promise<void> {\r\n const dbPath = this.config.database || this.config.connectionString || ':memory:';\r\n\r\n if (!dbPath || dbPath === '') {\r\n throw new Error('SQLite database path is required');\r\n }\r\n\r\n // Create connection pool for SQLite\r\n for (let i = 0; i < this.options.minConnections; i++) {\r\n const db = await open({\r\n filename: dbPath,\r\n driver: sqlite3.Database,\r\n });\r\n\r\n await db.run('PRAGMA foreign_keys = ON');\r\n await db.run(`PRAGMA busy_timeout = ${this.config.timeout || 5000}`);\r\n\r\n this.connections.add(db);\r\n }\r\n }\r\n\r\n /**\r\n * Initialize Redis connection pool\r\n */\r\n private async initializeRedisPool(): Promise<void> {\r\n let url = this.config.connectionString;\r\n\r\n if (!url) {\r\n // Build connection string with optional authentication\r\n const host = this.config.host || 'localhost';\r\n const port = this.config.port || 6379;\r\n\r\n if (this.config.password) {\r\n // Include password in connection string: redis://:password@host:port\r\n url = `redis://:${encodeURIComponent(this.config.password)}@${host}:${port}`;\r\n } else {\r\n url = `redis://${host}:${port}`;\r\n }\r\n }\r\n\r\n this.pool = createClient({\r\n url,\r\n socket: {\r\n connectTimeout: this.config.timeout || 5000,\r\n reconnectStrategy: (retries) => {\r\n if (retries > this.maxReconnectAttempts) {\r\n return false;\r\n }\r\n // Exponential backoff\r\n return Math.min(this.options.reconnectBaseDelay * Math.pow(2, retries), 30000);\r\n },\r\n },\r\n });\r\n\r\n // Set up event handlers\r\n this.pool.on('error', (err: Error) => {\r\n console.error('Redis connection error:', err);\r\n this.failedAttempts++;\r\n });\r\n\r\n this.pool.on('reconnecting', () => {\r\n this.reconnectAttempts++;\r\n });\r\n\r\n await this.pool.connect();\r\n }\r\n\r\n /**\r\n * Initialize PostgreSQL connection pool\r\n */\r\n private async initializePostgresPool(): Promise<void> {\r\n const connectionString = this.config.connectionString ||\r\n `postgresql://${this.config.username}:${this.config.password}@${this.config.host}:${this.config.port}/${this.config.database}`;\r\n\r\n this.pool = new Pool({\r\n connectionString,\r\n min: this.options.minConnections,\r\n max: this.options.maxConnections,\r\n idleTimeoutMillis: this.options.idleTimeout,\r\n connectionTimeoutMillis: this.options.acquireTimeout,\r\n });\r\n\r\n // Test connection\r\n const client = await this.pool.connect();\r\n await client.query('SELECT 1');\r\n client.release();\r\n }\r\n\r\n /**\r\n * Warm up pool by creating minimum connections\r\n */\r\n private async warmUpPool(): Promise<void> {\r\n if (this.config.type === 'sqlite') {\r\n // SQLite connections already created in initializeSQLitePool\r\n return;\r\n }\r\n\r\n // For Redis and Postgres, connections are managed by their libraries\r\n // We just need to verify connectivity\r\n if (this.config.type === 'redis') {\r\n await this.pool.ping();\r\n } else if (this.config.type === 'postgres') {\r\n const client = await this.pool.connect();\r\n await client.query('SELECT 1');\r\n client.release();\r\n }\r\n }\r\n\r\n /**\r\n * Acquire connection from pool\r\n */\r\n async acquire(): Promise<any> {\r\n if (this.isShuttingDown) {\r\n throw createDatabaseError(\r\n DatabaseErrorCode.CONNECTION_FAILED,\r\n 'Connection pool is shutting down',\r\n undefined,\r\n { type: this.config.type }\r\n );\r\n }\r\n\r\n const startTime = Date.now();\r\n\r\n try {\r\n switch (this.config.type) {\r\n case 'sqlite':\r\n return await this.acquireSQLiteConnection(startTime);\r\n case 'redis':\r\n return this.pool;\r\n case 'postgres':\r\n return await this.pool.connect();\r\n default:\r\n throw new Error(`Unsupported database type: ${this.config.type}`);\r\n }\r\n } catch (err) {\r\n throw createDatabaseError(\r\n DatabaseErrorCode.CONNECTION_FAILED,\r\n 'Failed to acquire connection',\r\n err instanceof Error ? err : new Error(String(err)),\r\n { type: this.config.type }\r\n );\r\n }\r\n }\r\n\r\n /**\r\n * Acquire SQLite connection from pool\r\n */\r\n private async acquireSQLiteConnection(startTime: number): Promise<Database> {\r\n // Check for available connection\r\n const availableConnection = Array.from(this.connections).find(\r\n conn => !this.activeConnections.has(conn)\r\n );\r\n\r\n if (availableConnection) {\r\n this.activeConnections.add(availableConnection);\r\n return availableConnection as Database;\r\n }\r\n\r\n // Check if we can create more connections\r\n if (this.connections.size < this.options.maxConnections) {\r\n const newConnection = await this.createSQLiteConnection();\r\n this.connections.add(newConnection);\r\n this.activeConnections.add(newConnection);\r\n return newConnection;\r\n }\r\n\r\n // Queue request\r\n return new Promise((resolve, reject) => {\r\n const timeoutId = setTimeout(() => {\r\n const index = this.pendingRequests.findIndex(req => req.resolve === resolve);\r\n if (index !== -1) {\r\n this.pendingRequests.splice(index, 1);\r\n }\r\n reject(createDatabaseError(\r\n DatabaseErrorCode.TIMEOUT,\r\n 'Connection acquisition timeout',\r\n undefined,\r\n { timeout: this.options.acquireTimeout }\r\n ));\r\n }, this.options.acquireTimeout);\r\n\r\n this.pendingRequests.push({\r\n resolve: (conn) => {\r\n clearTimeout(timeoutId);\r\n resolve(conn);\r\n },\r\n reject: (err) => {\r\n clearTimeout(timeoutId);\r\n reject(err);\r\n },\r\n timestamp: startTime,\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Create new SQLite connection\r\n */\r\n private async createSQLiteConnection(): Promise<Database> {\r\n const dbPath = this.config.database || this.config.connectionString || ':memory:';\r\n\r\n const db = await open({\r\n filename: dbPath,\r\n driver: sqlite3.Database,\r\n });\r\n\r\n await db.run('PRAGMA foreign_keys = ON');\r\n await db.run(`PRAGMA busy_timeout = ${this.config.timeout || 5000}`);\r\n\r\n return db;\r\n }\r\n\r\n /**\r\n * Release connection back to pool\r\n */\r\n async release(connection: any): Promise<void> {\r\n if (!connection) {\r\n return;\r\n }\r\n\r\n try {\r\n switch (this.config.type) {\r\n case 'sqlite':\r\n this.releaseSQLiteConnection(connection);\r\n break;\r\n case 'redis':\r\n // Redis client is shared, no release needed\r\n break;\r\n case 'postgres':\r\n if (connection && typeof connection.release === 'function') {\r\n connection.release();\r\n }\r\n break;\r\n }\r\n } catch (err) {\r\n console.error('Failed to release connection:', err);\r\n }\r\n }\r\n\r\n /**\r\n * Release SQLite connection\r\n */\r\n private releaseSQLiteConnection(connection: Database): void {\r\n this.activeConnections.delete(connection);\r\n\r\n // Process pending requests\r\n if (this.pendingRequests.length > 0) {\r\n const pending = this.pendingRequests.shift();\r\n if (pending) {\r\n this.activeConnections.add(connection);\r\n pending.resolve(connection);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Start periodic health checks\r\n */\r\n startHealthChecks(): void {\r\n if (this.healthCheckActive) {\r\n return;\r\n }\r\n\r\n this.healthCheckActive = true;\r\n this.healthCheckInterval = setInterval(async () => {\r\n try {\r\n const healthy = await this.performHealthCheck();\r\n this.lastHealthCheck = new Date();\r\n\r\n if (!healthy) {\r\n console.warn(`Health check failed for ${this.config.type} pool`);\r\n await this.attemptReconnection();\r\n }\r\n } catch (err) {\r\n console.error('Health check error:', err);\r\n }\r\n }, this.options.healthCheckInterval);\r\n }\r\n\r\n /**\r\n * Stop health checks\r\n */\r\n stopHealthChecks(): void {\r\n if (this.healthCheckInterval) {\r\n clearInterval(this.healthCheckInterval);\r\n this.healthCheckInterval = undefined;\r\n }\r\n this.healthCheckActive = false;\r\n }\r\n\r\n /**\r\n * Perform health check\r\n */\r\n private async performHealthCheck(): Promise<boolean> {\r\n try {\r\n switch (this.config.type) {\r\n case 'sqlite': {\r\n const connection = Array.from(this.connections)[0];\r\n if (connection) {\r\n await (connection as Database).get('SELECT 1');\r\n return true;\r\n }\r\n return false;\r\n }\r\n case 'redis':\r\n if (this.pool) {\r\n await this.pool.ping();\r\n return true;\r\n }\r\n return false;\r\n case 'postgres':\r\n if (this.pool) {\r\n const client = await this.pool.connect();\r\n await client.query('SELECT 1');\r\n client.release();\r\n return true;\r\n }\r\n return false;\r\n default:\r\n return false;\r\n }\r\n } catch (err) {\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * Check if pool is healthy (exposed for testing)\r\n */\r\n private async isHealthy(): Promise<boolean> {\r\n return this.performHealthCheck();\r\n }\r\n\r\n /**\r\n * Attempt reconnection with exponential backoff\r\n */\r\n private async attemptReconnection(): Promise<void> {\r\n if (this.reconnectAttempts >= this.maxReconnectAttempts) {\r\n console.error(`Max reconnection attempts (${this.maxReconnectAttempts}) reached for ${this.config.type}`);\r\n return;\r\n }\r\n\r\n const delay = Math.min(\r\n this.options.reconnectBaseDelay * Math.pow(2, this.reconnectAttempts),\r\n 30000\r\n );\r\n\r\n this.reconnectAttempts++;\r\n\r\n await new Promise(resolve => setTimeout(resolve, delay));\r\n\r\n try {\r\n await this.initialize();\r\n console.log(`Reconnection successful for ${this.config.type}`);\r\n this.reconnectAttempts = 0;\r\n } catch (err) {\r\n console.error(`Reconnection failed for ${this.config.type}:`, err);\r\n }\r\n }\r\n\r\n /**\r\n * Get reconnection delays for testing\r\n */\r\n private getReconnectDelays(): number[] {\r\n const delays: number[] = [];\r\n for (let i = 0; i < 5; i++) {\r\n delays.push(\r\n Math.min(this.options.reconnectBaseDelay * Math.pow(2, i), 30000)\r\n );\r\n }\r\n return delays;\r\n }\r\n\r\n /**\r\n * Simulate disconnection (for testing)\r\n */\r\n private simulateDisconnection(): void {\r\n if (this.config.type === 'redis' && this.pool) {\r\n this.pool.disconnect();\r\n } else if (this.config.type === 'postgres' && this.pool) {\r\n this.pool.end();\r\n }\r\n }\r\n\r\n /**\r\n * Remove unhealthy connections (for testing)\r\n */\r\n private removeUnhealthyConnections(count: number): void {\r\n if (this.config.type === 'sqlite') {\r\n const connectionsToRemove = Array.from(this.connections).slice(0, count);\r\n connectionsToRemove.forEach(conn => {\r\n this.connections.delete(conn);\r\n this.activeConnections.delete(conn);\r\n (conn as Database).close();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Enable cache fallback for graceful degradation\r\n */\r\n enableCacheFallback(enabled: boolean): void {\r\n this.cacheFallbackEnabled = enabled;\r\n }\r\n\r\n /**\r\n * Get data with cache fallback\r\n */\r\n async getWithFallback(key: string): Promise<any> {\r\n try {\r\n const connection = await this.acquire();\r\n // Actual data retrieval would happen here\r\n await this.release(connection);\r\n return null;\r\n } catch (err) {\r\n if (this.cacheFallbackEnabled && this.cache.has(key)) {\r\n console.warn(`Using cached data for key: ${key}`);\r\n return this.cache.get(key);\r\n }\r\n throw err;\r\n }\r\n }\r\n\r\n /**\r\n * Get connection pool statistics\r\n */\r\n getStats(): ConnectionPoolStats {\r\n const now = Date.now();\r\n const uptime = now - this.startTime.getTime();\r\n\r\n switch (this.config.type) {\r\n case 'sqlite':\r\n return {\r\n type: 'sqlite',\r\n total: this.connections.size,\r\n active: this.activeConnections.size,\r\n idle: this.connections.size - this.activeConnections.size,\r\n pending: this.pendingRequests.length,\r\n maxConnections: this.options.maxConnections,\r\n available: this.connections.size - this.activeConnections.size,\r\n healthy: this.connections.size > 0,\r\n lastHealthCheck: this.lastHealthCheck,\r\n healthCheckActive: this.healthCheckActive,\r\n reconnectAttempts: this.reconnectAttempts,\r\n failedAttempts: this.failedAttempts,\r\n uptime,\r\n };\r\n\r\n case 'redis':\r\n return {\r\n type: 'redis',\r\n total: this.pool ? 1 : 0,\r\n active: this.pool?.isOpen ? 1 : 0,\r\n idle: 0,\r\n pending: 0,\r\n maxConnections: 1,\r\n available: this.pool?.isOpen ? 1 : 0,\r\n healthy: this.pool?.isOpen ?? false,\r\n lastHealthCheck: this.lastHealthCheck,\r\n healthCheckActive: this.healthCheckActive,\r\n reconnectAttempts: this.reconnectAttempts,\r\n failedAttempts: this.failedAttempts,\r\n uptime,\r\n };\r\n\r\n case 'postgres':\r\n return {\r\n type: 'postgres',\r\n total: this.pool?.totalCount ?? 0,\r\n active: (this.pool?.totalCount ?? 0) - (this.pool?.idleCount ?? 0),\r\n idle: this.pool?.idleCount ?? 0,\r\n pending: this.pool?.waitingCount ?? 0,\r\n maxConnections: this.options.maxConnections,\r\n available: this.pool?.idleCount ?? 0,\r\n healthy: this.pool !== null,\r\n lastHealthCheck: this.lastHealthCheck,\r\n healthCheckActive: this.healthCheckActive,\r\n reconnectAttempts: this.reconnectAttempts,\r\n failedAttempts: this.failedAttempts,\r\n uptime,\r\n };\r\n\r\n default:\r\n throw new Error(`Unsupported database type: ${this.config.type}`);\r\n }\r\n }\r\n\r\n /**\r\n * Shutdown connection pool\r\n */\r\n async shutdown(): Promise<void> {\r\n if (this.isShuttingDown) {\r\n return;\r\n }\r\n\r\n this.isShuttingDown = true;\r\n this.stopHealthChecks();\r\n\r\n // Reject all pending requests\r\n this.pendingRequests.forEach(req => {\r\n req.reject(createDatabaseError(\r\n DatabaseErrorCode.CONNECTION_FAILED,\r\n 'Connection pool is shutting down',\r\n undefined,\r\n { type: this.config.type }\r\n ));\r\n });\r\n this.pendingRequests = [];\r\n\r\n // Close all connections\r\n try {\r\n switch (this.config.type) {\r\n case 'sqlite':\r\n await Promise.all(\r\n Array.from(this.connections).map(conn => (conn as Database).close())\r\n );\r\n this.connections.clear();\r\n this.activeConnections.clear();\r\n break;\r\n\r\n case 'redis':\r\n if (this.pool) {\r\n await this.pool.quit();\r\n this.pool = null;\r\n }\r\n break;\r\n\r\n case 'postgres':\r\n if (this.pool) {\r\n await this.pool.end();\r\n this.pool = null;\r\n }\r\n break;\r\n }\r\n } catch (err) {\r\n console.error('Error during shutdown:', err);\r\n }\r\n }\r\n}\r\n"],"names":["sqlite3","open","createClient","Pool","DatabaseErrorCode","createDatabaseError","ConnectionPoolManager","config","options","pool","connections","Set","activeConnections","pendingRequests","healthCheckInterval","lastHealthCheck","healthCheckActive","reconnectAttempts","maxReconnectAttempts","failedAttempts","startTime","isShuttingDown","cacheFallbackEnabled","cache","Map","minConnections","maxConnections","poolSize","acquireTimeout","timeout","idleTimeout","reconnectBaseDelay","Date","initialize","type","initializeSQLitePool","initializeRedisPool","initializePostgresPool","Error","warmUpPool","err","CONNECTION_FAILED","String","dbPath","database","connectionString","i","db","filename","driver","Database","run","add","url","host","port","password","encodeURIComponent","socket","connectTimeout","reconnectStrategy","retries","Math","min","pow","on","console","error","connect","username","max","idleTimeoutMillis","connectionTimeoutMillis","client","query","release","ping","acquire","undefined","now","acquireSQLiteConnection","availableConnection","Array","from","find","conn","has","size","newConnection","createSQLiteConnection","Promise","resolve","reject","timeoutId","setTimeout","index","findIndex","req","splice","TIMEOUT","push","clearTimeout","timestamp","connection","releaseSQLiteConnection","delete","length","pending","shift","startHealthChecks","setInterval","healthy","performHealthCheck","warn","attemptReconnection","stopHealthChecks","clearInterval","get","isHealthy","delay","log","getReconnectDelays","delays","simulateDisconnection","disconnect","end","removeUnhealthyConnections","count","connectionsToRemove","slice","forEach","close","enableCacheFallback","enabled","getWithFallback","key","getStats","uptime","getTime","total","active","idle","available","isOpen","totalCount","idleCount","waitingCount","shutdown","all","map","clear","quit"],"mappings":"AAAA;;;;;;;;;;;CAWC,GAED,OAAOA,aAAa,UAAU;AAC9B,SAASC,IAAI,QAAkB,SAAS;AACxC,SAASC,YAAY,QAAyB,QAAQ;AACtD,SAASC,IAAI,QAAoB,KAAK;AACtC,SAEEC,iBAAiB,QACZ,aAAa;AACpB,SAASC,mBAAmB,QAAQ,cAAc;AA4BlD;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