hungry-ghost-hive 0.48.0 → 0.49.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 (472) hide show
  1. package/dist/agents/base-agent.d.ts +11 -11
  2. package/dist/agents/base-agent.d.ts.map +1 -1
  3. package/dist/agents/base-agent.js +25 -25
  4. package/dist/agents/base-agent.js.map +1 -1
  5. package/dist/agents/base-agent.test.js +2 -1
  6. package/dist/agents/base-agent.test.js.map +1 -1
  7. package/dist/agents/intermediate.d.ts +2 -0
  8. package/dist/agents/intermediate.d.ts.map +1 -1
  9. package/dist/agents/intermediate.js +25 -18
  10. package/dist/agents/intermediate.js.map +1 -1
  11. package/dist/agents/junior.d.ts +2 -0
  12. package/dist/agents/junior.d.ts.map +1 -1
  13. package/dist/agents/junior.js +25 -18
  14. package/dist/agents/junior.js.map +1 -1
  15. package/dist/agents/qa.d.ts +2 -0
  16. package/dist/agents/qa.d.ts.map +1 -1
  17. package/dist/agents/qa.js +47 -38
  18. package/dist/agents/qa.js.map +1 -1
  19. package/dist/agents/senior.d.ts +2 -0
  20. package/dist/agents/senior.d.ts.map +1 -1
  21. package/dist/agents/senior.js +40 -27
  22. package/dist/agents/senior.js.map +1 -1
  23. package/dist/agents/tech-lead.d.ts +2 -0
  24. package/dist/agents/tech-lead.d.ts.map +1 -1
  25. package/dist/agents/tech-lead.js +37 -31
  26. package/dist/agents/tech-lead.js.map +1 -1
  27. package/dist/cli/commands/add-repo.js +2 -2
  28. package/dist/cli/commands/add-repo.js.map +1 -1
  29. package/dist/cli/commands/add-repo.test.js +1 -1
  30. package/dist/cli/commands/add-repo.test.js.map +1 -1
  31. package/dist/cli/commands/agents.d.ts.map +1 -1
  32. package/dist/cli/commands/agents.js +12 -10
  33. package/dist/cli/commands/agents.js.map +1 -1
  34. package/dist/cli/commands/agents.test.js +7 -7
  35. package/dist/cli/commands/agents.test.js.map +1 -1
  36. package/dist/cli/commands/approach.js +2 -2
  37. package/dist/cli/commands/approach.js.map +1 -1
  38. package/dist/cli/commands/approvals.js +7 -7
  39. package/dist/cli/commands/approvals.js.map +1 -1
  40. package/dist/cli/commands/approvals.test.js +8 -8
  41. package/dist/cli/commands/approvals.test.js.map +1 -1
  42. package/dist/cli/commands/assign.js +4 -4
  43. package/dist/cli/commands/assign.js.map +1 -1
  44. package/dist/cli/commands/assign.test.js +18 -16
  45. package/dist/cli/commands/assign.test.js.map +1 -1
  46. package/dist/cli/commands/cleanup.d.ts.map +1 -1
  47. package/dist/cli/commands/cleanup.js +8 -8
  48. package/dist/cli/commands/cleanup.js.map +1 -1
  49. package/dist/cli/commands/cleanup.test.js +5 -1
  50. package/dist/cli/commands/cleanup.test.js.map +1 -1
  51. package/dist/cli/commands/escalations.js +9 -7
  52. package/dist/cli/commands/escalations.js.map +1 -1
  53. package/dist/cli/commands/escalations.test.js +2 -2
  54. package/dist/cli/commands/escalations.test.js.map +1 -1
  55. package/dist/cli/commands/init.d.ts.map +1 -1
  56. package/dist/cli/commands/init.js +48 -5
  57. package/dist/cli/commands/init.js.map +1 -1
  58. package/dist/cli/commands/init.test.js +4 -0
  59. package/dist/cli/commands/init.test.js.map +1 -1
  60. package/dist/cli/commands/manager/agent-monitoring.d.ts +2 -2
  61. package/dist/cli/commands/manager/agent-monitoring.d.ts.map +1 -1
  62. package/dist/cli/commands/manager/agent-monitoring.js +1 -1
  63. package/dist/cli/commands/manager/agent-monitoring.js.map +1 -1
  64. package/dist/cli/commands/manager/auditor-lifecycle.js +3 -3
  65. package/dist/cli/commands/manager/auditor-lifecycle.js.map +1 -1
  66. package/dist/cli/commands/manager/auditor-lifecycle.test.js +21 -14
  67. package/dist/cli/commands/manager/auditor-lifecycle.test.js.map +1 -1
  68. package/dist/cli/commands/manager/auto-reject-comment-only-reviews.test.js +28 -23
  69. package/dist/cli/commands/manager/auto-reject-comment-only-reviews.test.js.map +1 -1
  70. package/dist/cli/commands/manager/escalation-handler.d.ts +2 -2
  71. package/dist/cli/commands/manager/escalation-handler.d.ts.map +1 -1
  72. package/dist/cli/commands/manager/escalation-handler.js +11 -10
  73. package/dist/cli/commands/manager/escalation-handler.js.map +1 -1
  74. package/dist/cli/commands/manager/escalation-handler.test.js +8 -8
  75. package/dist/cli/commands/manager/escalation-handler.test.js.map +1 -1
  76. package/dist/cli/commands/manager/feature-sign-off.js +7 -7
  77. package/dist/cli/commands/manager/feature-sign-off.js.map +1 -1
  78. package/dist/cli/commands/manager/feature-sign-off.test.js +40 -31
  79. package/dist/cli/commands/manager/feature-sign-off.test.js.map +1 -1
  80. package/dist/cli/commands/manager/feature-test-result.d.ts.map +1 -1
  81. package/dist/cli/commands/manager/feature-test-result.js +12 -13
  82. package/dist/cli/commands/manager/feature-test-result.js.map +1 -1
  83. package/dist/cli/commands/manager/handoff-recovery.d.ts.map +1 -1
  84. package/dist/cli/commands/manager/handoff-recovery.js +14 -15
  85. package/dist/cli/commands/manager/handoff-recovery.js.map +1 -1
  86. package/dist/cli/commands/manager/index.d.ts.map +1 -1
  87. package/dist/cli/commands/manager/index.js +26 -26
  88. package/dist/cli/commands/manager/index.js.map +1 -1
  89. package/dist/cli/commands/manager/index.test.js +3 -3
  90. package/dist/cli/commands/manager/index.test.js.map +1 -1
  91. package/dist/cli/commands/manager/merged-story-cleanup.d.ts +2 -2
  92. package/dist/cli/commands/manager/merged-story-cleanup.d.ts.map +1 -1
  93. package/dist/cli/commands/manager/merged-story-cleanup.js +6 -7
  94. package/dist/cli/commands/manager/merged-story-cleanup.js.map +1 -1
  95. package/dist/cli/commands/manager/merged-story-cleanup.test.js +27 -18
  96. package/dist/cli/commands/manager/merged-story-cleanup.test.js.map +1 -1
  97. package/dist/cli/commands/manager/pr-sync-orchestrator.d.ts.map +1 -1
  98. package/dist/cli/commands/manager/pr-sync-orchestrator.js +46 -38
  99. package/dist/cli/commands/manager/pr-sync-orchestrator.js.map +1 -1
  100. package/dist/cli/commands/manager/qa-review-handler.d.ts.map +1 -1
  101. package/dist/cli/commands/manager/qa-review-handler.js +25 -22
  102. package/dist/cli/commands/manager/qa-review-handler.js.map +1 -1
  103. package/dist/cli/commands/manager/spin-down.d.ts.map +1 -1
  104. package/dist/cli/commands/manager/spin-down.js +23 -19
  105. package/dist/cli/commands/manager/spin-down.js.map +1 -1
  106. package/dist/cli/commands/manager/stale-escalations.d.ts +2 -3
  107. package/dist/cli/commands/manager/stale-escalations.d.ts.map +1 -1
  108. package/dist/cli/commands/manager/stale-escalations.js.map +1 -1
  109. package/dist/cli/commands/manager/stuck-story-helpers.js +8 -8
  110. package/dist/cli/commands/manager/stuck-story-helpers.js.map +1 -1
  111. package/dist/cli/commands/manager/stuck-story-processor.d.ts +2 -2
  112. package/dist/cli/commands/manager/stuck-story-processor.d.ts.map +1 -1
  113. package/dist/cli/commands/manager/stuck-story-processor.js +23 -22
  114. package/dist/cli/commands/manager/stuck-story-processor.js.map +1 -1
  115. package/dist/cli/commands/manager/tech-lead-lifecycle.js +6 -6
  116. package/dist/cli/commands/manager/tech-lead-lifecycle.js.map +1 -1
  117. package/dist/cli/commands/manager/types.d.ts +2 -3
  118. package/dist/cli/commands/manager/types.d.ts.map +1 -1
  119. package/dist/cli/commands/manager/types.js.map +1 -1
  120. package/dist/cli/commands/msg.test.js +2 -2
  121. package/dist/cli/commands/msg.test.js.map +1 -1
  122. package/dist/cli/commands/my-stories.d.ts.map +1 -1
  123. package/dist/cli/commands/my-stories.js +17 -18
  124. package/dist/cli/commands/my-stories.js.map +1 -1
  125. package/dist/cli/commands/my-stories.test.js +2 -2
  126. package/dist/cli/commands/my-stories.test.js.map +1 -1
  127. package/dist/cli/commands/nuke.test.js +1 -1
  128. package/dist/cli/commands/nuke.test.js.map +1 -1
  129. package/dist/cli/commands/pr.js +32 -32
  130. package/dist/cli/commands/pr.js.map +1 -1
  131. package/dist/cli/commands/pr.test.js +10 -6
  132. package/dist/cli/commands/pr.test.js.map +1 -1
  133. package/dist/cli/commands/progress.d.ts.map +1 -1
  134. package/dist/cli/commands/progress.js +4 -5
  135. package/dist/cli/commands/progress.js.map +1 -1
  136. package/dist/cli/commands/progress.test.js +1 -1
  137. package/dist/cli/commands/progress.test.js.map +1 -1
  138. package/dist/cli/commands/req-headless.test.d.ts +2 -0
  139. package/dist/cli/commands/req-headless.test.d.ts.map +1 -0
  140. package/dist/cli/commands/req-headless.test.js +128 -0
  141. package/dist/cli/commands/req-headless.test.js.map +1 -0
  142. package/dist/cli/commands/req-spawn.test.js +5 -1
  143. package/dist/cli/commands/req-spawn.test.js.map +1 -1
  144. package/dist/cli/commands/req.d.ts.map +1 -1
  145. package/dist/cli/commands/req.js +13 -14
  146. package/dist/cli/commands/req.js.map +1 -1
  147. package/dist/cli/commands/resume.d.ts.map +1 -1
  148. package/dist/cli/commands/resume.js +7 -8
  149. package/dist/cli/commands/resume.js.map +1 -1
  150. package/dist/cli/commands/resume.test.js +1 -1
  151. package/dist/cli/commands/resume.test.js.map +1 -1
  152. package/dist/cli/commands/status.d.ts.map +1 -1
  153. package/dist/cli/commands/status.js +42 -40
  154. package/dist/cli/commands/status.js.map +1 -1
  155. package/dist/cli/commands/status.test.js +1 -1
  156. package/dist/cli/commands/status.test.js.map +1 -1
  157. package/dist/cli/commands/stories.js +9 -9
  158. package/dist/cli/commands/stories.js.map +1 -1
  159. package/dist/cli/commands/stories.test.js +2 -2
  160. package/dist/cli/commands/stories.test.js.map +1 -1
  161. package/dist/cli/commands/teams.js +11 -11
  162. package/dist/cli/commands/teams.js.map +1 -1
  163. package/dist/cli/commands/teams.test.js +2 -2
  164. package/dist/cli/commands/teams.test.js.map +1 -1
  165. package/dist/cli/dashboard/index.d.ts +2 -2
  166. package/dist/cli/dashboard/index.d.ts.map +1 -1
  167. package/dist/cli/dashboard/index.js +29 -20
  168. package/dist/cli/dashboard/index.js.map +1 -1
  169. package/dist/cli/dashboard/index.test.js +34 -32
  170. package/dist/cli/dashboard/index.test.js.map +1 -1
  171. package/dist/cli/dashboard/panels/activity.d.ts +3 -3
  172. package/dist/cli/dashboard/panels/activity.d.ts.map +1 -1
  173. package/dist/cli/dashboard/panels/activity.js +1 -1
  174. package/dist/cli/dashboard/panels/activity.js.map +1 -1
  175. package/dist/cli/dashboard/panels/agents.d.ts +3 -3
  176. package/dist/cli/dashboard/panels/agents.d.ts.map +1 -1
  177. package/dist/cli/dashboard/panels/agents.js +2 -2
  178. package/dist/cli/dashboard/panels/agents.js.map +1 -1
  179. package/dist/cli/dashboard/panels/escalations.d.ts +3 -3
  180. package/dist/cli/dashboard/panels/escalations.d.ts.map +1 -1
  181. package/dist/cli/dashboard/panels/escalations.js +1 -1
  182. package/dist/cli/dashboard/panels/escalations.js.map +1 -1
  183. package/dist/cli/dashboard/panels/merge-queue.d.ts +3 -3
  184. package/dist/cli/dashboard/panels/merge-queue.d.ts.map +1 -1
  185. package/dist/cli/dashboard/panels/merge-queue.js +1 -1
  186. package/dist/cli/dashboard/panels/merge-queue.js.map +1 -1
  187. package/dist/cli/dashboard/panels/pipeline.d.ts +3 -3
  188. package/dist/cli/dashboard/panels/pipeline.d.ts.map +1 -1
  189. package/dist/cli/dashboard/panels/pipeline.js +1 -1
  190. package/dist/cli/dashboard/panels/pipeline.js.map +1 -1
  191. package/dist/config/schema.d.ts +85 -82
  192. package/dist/config/schema.d.ts.map +1 -1
  193. package/dist/config/schema.js +1 -0
  194. package/dist/config/schema.js.map +1 -1
  195. package/dist/connectors/project-management/operations.d.ts +7 -7
  196. package/dist/connectors/project-management/operations.d.ts.map +1 -1
  197. package/dist/connectors/project-management/operations.js +2 -3
  198. package/dist/connectors/project-management/operations.js.map +1 -1
  199. package/dist/context-files/index.test.js +1 -0
  200. package/dist/context-files/index.test.js.map +1 -1
  201. package/dist/db/client.d.ts +6 -0
  202. package/dist/db/client.d.ts.map +1 -1
  203. package/dist/db/client.js +7 -0
  204. package/dist/db/client.js.map +1 -1
  205. package/dist/db/postgres-provider.d.ts +43 -0
  206. package/dist/db/postgres-provider.d.ts.map +1 -0
  207. package/dist/db/postgres-provider.integration.test.d.ts +2 -0
  208. package/dist/db/postgres-provider.integration.test.d.ts.map +1 -0
  209. package/dist/db/postgres-provider.integration.test.js +399 -0
  210. package/dist/db/postgres-provider.integration.test.js.map +1 -0
  211. package/dist/db/postgres-provider.js +315 -0
  212. package/dist/db/postgres-provider.js.map +1 -0
  213. package/dist/db/postgres-provider.test.d.ts +2 -0
  214. package/dist/db/postgres-provider.test.d.ts.map +1 -0
  215. package/dist/db/postgres-provider.test.js +72 -0
  216. package/dist/db/postgres-provider.test.js.map +1 -0
  217. package/dist/db/provider.d.ts +59 -0
  218. package/dist/db/provider.d.ts.map +1 -0
  219. package/dist/db/provider.js +121 -0
  220. package/dist/db/provider.js.map +1 -0
  221. package/dist/db/provider.test.d.ts +2 -0
  222. package/dist/db/provider.test.d.ts.map +1 -0
  223. package/dist/db/provider.test.js +226 -0
  224. package/dist/db/provider.test.js.map +1 -0
  225. package/dist/db/queries/agents.d.ts +13 -13
  226. package/dist/db/queries/agents.d.ts.map +1 -1
  227. package/dist/db/queries/agents.js +27 -28
  228. package/dist/db/queries/agents.js.map +1 -1
  229. package/dist/db/queries/agents.test.js +113 -111
  230. package/dist/db/queries/agents.test.js.map +1 -1
  231. package/dist/db/queries/escalations.d.ts +16 -16
  232. package/dist/db/queries/escalations.d.ts.map +1 -1
  233. package/dist/db/queries/escalations.js +34 -35
  234. package/dist/db/queries/escalations.js.map +1 -1
  235. package/dist/db/queries/escalations.test.js +133 -131
  236. package/dist/db/queries/escalations.test.js.map +1 -1
  237. package/dist/db/queries/heartbeat.d.ts +5 -5
  238. package/dist/db/queries/heartbeat.d.ts.map +1 -1
  239. package/dist/db/queries/heartbeat.js +7 -23
  240. package/dist/db/queries/heartbeat.js.map +1 -1
  241. package/dist/db/queries/heartbeat.test.js +76 -76
  242. package/dist/db/queries/heartbeat.test.js.map +1 -1
  243. package/dist/db/queries/integration-sync.d.ts +7 -7
  244. package/dist/db/queries/integration-sync.d.ts.map +1 -1
  245. package/dist/db/queries/integration-sync.js +13 -14
  246. package/dist/db/queries/integration-sync.js.map +1 -1
  247. package/dist/db/queries/logs.d.ts +10 -10
  248. package/dist/db/queries/logs.d.ts.map +1 -1
  249. package/dist/db/queries/logs.js +44 -42
  250. package/dist/db/queries/logs.js.map +1 -1
  251. package/dist/db/queries/logs.test.js +149 -146
  252. package/dist/db/queries/logs.test.js.map +1 -1
  253. package/dist/db/queries/messages.d.ts +6 -6
  254. package/dist/db/queries/messages.d.ts.map +1 -1
  255. package/dist/db/queries/messages.js +12 -11
  256. package/dist/db/queries/messages.js.map +1 -1
  257. package/dist/db/queries/messages.test.js +47 -46
  258. package/dist/db/queries/messages.test.js.map +1 -1
  259. package/dist/db/queries/pull-requests.d.ts +18 -18
  260. package/dist/db/queries/pull-requests.d.ts.map +1 -1
  261. package/dist/db/queries/pull-requests.js +50 -48
  262. package/dist/db/queries/pull-requests.js.map +1 -1
  263. package/dist/db/queries/pull-requests.test.js +195 -198
  264. package/dist/db/queries/pull-requests.test.js.map +1 -1
  265. package/dist/db/queries/requirements.d.ts +8 -8
  266. package/dist/db/queries/requirements.d.ts.map +1 -1
  267. package/dist/db/queries/requirements.js +17 -18
  268. package/dist/db/queries/requirements.js.map +1 -1
  269. package/dist/db/queries/requirements.test.js +83 -81
  270. package/dist/db/queries/requirements.test.js.map +1 -1
  271. package/dist/db/queries/stories.d.ts +29 -29
  272. package/dist/db/queries/stories.d.ts.map +1 -1
  273. package/dist/db/queries/stories.js +58 -64
  274. package/dist/db/queries/stories.js.map +1 -1
  275. package/dist/db/queries/stories.test.js +172 -170
  276. package/dist/db/queries/stories.test.js.map +1 -1
  277. package/dist/db/queries/teams.d.ts +6 -6
  278. package/dist/db/queries/teams.d.ts.map +1 -1
  279. package/dist/db/queries/teams.js +11 -12
  280. package/dist/db/queries/teams.js.map +1 -1
  281. package/dist/db/queries/teams.test.js +36 -34
  282. package/dist/db/queries/teams.test.js.map +1 -1
  283. package/dist/integrations/jira/repair.test.js +26 -24
  284. package/dist/integrations/jira/repair.test.js.map +1 -1
  285. package/dist/integrations/jira/stories.d.ts +3 -3
  286. package/dist/integrations/jira/stories.d.ts.map +1 -1
  287. package/dist/integrations/jira/stories.js +12 -12
  288. package/dist/integrations/jira/stories.js.map +1 -1
  289. package/dist/integrations/jira/stories.test.js +10 -8
  290. package/dist/integrations/jira/stories.test.js.map +1 -1
  291. package/dist/integrations/jira/sync.d.ts +7 -7
  292. package/dist/integrations/jira/sync.d.ts.map +1 -1
  293. package/dist/integrations/jira/sync.js +17 -20
  294. package/dist/integrations/jira/sync.js.map +1 -1
  295. package/dist/integrations/jira/sync.test.js +63 -62
  296. package/dist/integrations/jira/sync.test.js.map +1 -1
  297. package/dist/integrations/jira/transitions.d.ts +3 -3
  298. package/dist/integrations/jira/transitions.d.ts.map +1 -1
  299. package/dist/integrations/jira/transitions.js +3 -3
  300. package/dist/integrations/jira/transitions.js.map +1 -1
  301. package/dist/orchestrator/agent-selector.d.ts +3 -3
  302. package/dist/orchestrator/agent-selector.d.ts.map +1 -1
  303. package/dist/orchestrator/agent-selector.js +5 -6
  304. package/dist/orchestrator/agent-selector.js.map +1 -1
  305. package/dist/orchestrator/dependency-resolver.d.ts +4 -4
  306. package/dist/orchestrator/dependency-resolver.d.ts.map +1 -1
  307. package/dist/orchestrator/dependency-resolver.js +6 -6
  308. package/dist/orchestrator/dependency-resolver.js.map +1 -1
  309. package/dist/orchestrator/feature-branch.d.ts +3 -3
  310. package/dist/orchestrator/feature-branch.d.ts.map +1 -1
  311. package/dist/orchestrator/feature-branch.js +9 -10
  312. package/dist/orchestrator/feature-branch.js.map +1 -1
  313. package/dist/orchestrator/feature-branch.test.js +80 -78
  314. package/dist/orchestrator/feature-branch.test.js.map +1 -1
  315. package/dist/orchestrator/orphan-recovery.d.ts +2 -2
  316. package/dist/orchestrator/orphan-recovery.d.ts.map +1 -1
  317. package/dist/orchestrator/orphan-recovery.js +10 -10
  318. package/dist/orchestrator/orphan-recovery.js.map +1 -1
  319. package/dist/orchestrator/scheduler.d.ts +4 -4
  320. package/dist/orchestrator/scheduler.d.ts.map +1 -1
  321. package/dist/orchestrator/scheduler.js +90 -76
  322. package/dist/orchestrator/scheduler.js.map +1 -1
  323. package/dist/orchestrator/scheduler.test.js +496 -374
  324. package/dist/orchestrator/scheduler.test.js.map +1 -1
  325. package/dist/utils/auto-merge.d.ts.map +1 -1
  326. package/dist/utils/auto-merge.js +74 -56
  327. package/dist/utils/auto-merge.js.map +1 -1
  328. package/dist/utils/auto-merge.test.js +101 -66
  329. package/dist/utils/auto-merge.test.js.map +1 -1
  330. package/dist/utils/cli-helpers.d.ts +5 -5
  331. package/dist/utils/cli-helpers.d.ts.map +1 -1
  332. package/dist/utils/cli-helpers.js +8 -9
  333. package/dist/utils/cli-helpers.js.map +1 -1
  334. package/dist/utils/cli-helpers.test.js +28 -30
  335. package/dist/utils/cli-helpers.test.js.map +1 -1
  336. package/dist/utils/paths.d.ts +6 -0
  337. package/dist/utils/paths.d.ts.map +1 -1
  338. package/dist/utils/paths.js +12 -1
  339. package/dist/utils/paths.js.map +1 -1
  340. package/dist/utils/paths.test.js +1 -0
  341. package/dist/utils/paths.test.js.map +1 -1
  342. package/dist/utils/pr-sync.d.ts +10 -10
  343. package/dist/utils/pr-sync.d.ts.map +1 -1
  344. package/dist/utils/pr-sync.js +20 -21
  345. package/dist/utils/pr-sync.js.map +1 -1
  346. package/dist/utils/pr-sync.test.js +52 -50
  347. package/dist/utils/pr-sync.test.js.map +1 -1
  348. package/dist/utils/with-hive-context.d.ts.map +1 -1
  349. package/dist/utils/with-hive-context.js +70 -1
  350. package/dist/utils/with-hive-context.js.map +1 -1
  351. package/package.json +3 -1
  352. package/src/agents/base-agent.test.ts +2 -1
  353. package/src/agents/base-agent.ts +32 -28
  354. package/src/agents/intermediate.ts +27 -18
  355. package/src/agents/junior.ts +27 -18
  356. package/src/agents/qa.ts +54 -40
  357. package/src/agents/senior.ts +42 -27
  358. package/src/agents/tech-lead.ts +42 -32
  359. package/src/cli/commands/add-repo.test.ts +1 -1
  360. package/src/cli/commands/add-repo.ts +2 -2
  361. package/src/cli/commands/agents.test.ts +7 -7
  362. package/src/cli/commands/agents.ts +12 -10
  363. package/src/cli/commands/approach.ts +2 -2
  364. package/src/cli/commands/approvals.test.ts +8 -8
  365. package/src/cli/commands/approvals.ts +9 -7
  366. package/src/cli/commands/assign.test.ts +19 -18
  367. package/src/cli/commands/assign.ts +4 -4
  368. package/src/cli/commands/cleanup.test.ts +5 -1
  369. package/src/cli/commands/cleanup.ts +11 -9
  370. package/src/cli/commands/escalations.test.ts +2 -2
  371. package/src/cli/commands/escalations.ts +9 -7
  372. package/src/cli/commands/init.test.ts +5 -0
  373. package/src/cli/commands/init.ts +53 -5
  374. package/src/cli/commands/manager/agent-monitoring.ts +3 -3
  375. package/src/cli/commands/manager/auditor-lifecycle.test.ts +21 -14
  376. package/src/cli/commands/manager/auditor-lifecycle.ts +3 -3
  377. package/src/cli/commands/manager/auto-reject-comment-only-reviews.test.ts +28 -23
  378. package/src/cli/commands/manager/escalation-handler.test.ts +13 -13
  379. package/src/cli/commands/manager/escalation-handler.ts +19 -12
  380. package/src/cli/commands/manager/feature-sign-off.test.ts +40 -31
  381. package/src/cli/commands/manager/feature-sign-off.ts +7 -7
  382. package/src/cli/commands/manager/feature-test-result.ts +13 -16
  383. package/src/cli/commands/manager/handoff-recovery.ts +20 -20
  384. package/src/cli/commands/manager/index.test.ts +4 -4
  385. package/src/cli/commands/manager/index.ts +58 -59
  386. package/src/cli/commands/manager/merged-story-cleanup.test.ts +28 -19
  387. package/src/cli/commands/manager/merged-story-cleanup.ts +11 -14
  388. package/src/cli/commands/manager/pr-sync-orchestrator.ts +115 -110
  389. package/src/cli/commands/manager/qa-review-handler.ts +50 -63
  390. package/src/cli/commands/manager/spin-down.ts +27 -25
  391. package/src/cli/commands/manager/stale-escalations.ts +2 -3
  392. package/src/cli/commands/manager/stuck-story-helpers.ts +10 -10
  393. package/src/cli/commands/manager/stuck-story-processor.ts +56 -62
  394. package/src/cli/commands/manager/tech-lead-lifecycle.ts +6 -6
  395. package/src/cli/commands/manager/types.ts +2 -3
  396. package/src/cli/commands/msg.test.ts +2 -2
  397. package/src/cli/commands/my-stories.test.ts +4 -2
  398. package/src/cli/commands/my-stories.ts +22 -27
  399. package/src/cli/commands/nuke.test.ts +1 -1
  400. package/src/cli/commands/pr.test.ts +10 -6
  401. package/src/cli/commands/pr.ts +41 -32
  402. package/src/cli/commands/progress.test.ts +1 -1
  403. package/src/cli/commands/progress.ts +11 -6
  404. package/src/cli/commands/req-headless.test.ts +170 -0
  405. package/src/cli/commands/req-spawn.test.ts +12 -2
  406. package/src/cli/commands/req.ts +13 -14
  407. package/src/cli/commands/resume.test.ts +1 -1
  408. package/src/cli/commands/resume.ts +7 -8
  409. package/src/cli/commands/status.test.ts +1 -1
  410. package/src/cli/commands/status.ts +52 -40
  411. package/src/cli/commands/stories.test.ts +4 -2
  412. package/src/cli/commands/stories.ts +11 -11
  413. package/src/cli/commands/teams.test.ts +2 -2
  414. package/src/cli/commands/teams.ts +11 -11
  415. package/src/cli/dashboard/index.test.ts +35 -34
  416. package/src/cli/dashboard/index.ts +34 -23
  417. package/src/cli/dashboard/panels/activity.ts +10 -4
  418. package/src/cli/dashboard/panels/agents.ts +8 -5
  419. package/src/cli/dashboard/panels/escalations.ts +4 -4
  420. package/src/cli/dashboard/panels/merge-queue.ts +4 -4
  421. package/src/cli/dashboard/panels/pipeline.ts +10 -4
  422. package/src/config/schema.ts +1 -0
  423. package/src/connectors/project-management/operations.ts +9 -10
  424. package/src/context-files/index.test.ts +1 -0
  425. package/src/db/client.ts +17 -0
  426. package/src/db/pg-migrations/001-full-schema.sql +209 -0
  427. package/src/db/postgres-provider.integration.test.ts +574 -0
  428. package/src/db/postgres-provider.test.ts +97 -0
  429. package/src/db/postgres-provider.ts +364 -0
  430. package/src/db/provider.test.ts +283 -0
  431. package/src/db/provider.ts +161 -0
  432. package/src/db/queries/agents.test.ts +114 -113
  433. package/src/db/queries/agents.ts +50 -36
  434. package/src/db/queries/escalations.test.ts +134 -133
  435. package/src/db/queries/escalations.ts +72 -57
  436. package/src/db/queries/heartbeat.test.ts +77 -78
  437. package/src/db/queries/heartbeat.ts +24 -46
  438. package/src/db/queries/integration-sync.ts +26 -26
  439. package/src/db/queries/logs.test.ts +151 -148
  440. package/src/db/queries/logs.ts +78 -53
  441. package/src/db/queries/messages.test.ts +48 -50
  442. package/src/db/queries/messages.ts +26 -18
  443. package/src/db/queries/pull-requests.test.ts +194 -199
  444. package/src/db/queries/pull-requests.ts +117 -88
  445. package/src/db/queries/requirements.test.ts +84 -83
  446. package/src/db/queries/requirements.ts +33 -28
  447. package/src/db/queries/stories.test.ts +173 -172
  448. package/src/db/queries/stories.ts +141 -110
  449. package/src/db/queries/teams.test.ts +37 -36
  450. package/src/db/queries/teams.ts +22 -14
  451. package/src/integrations/jira/repair.test.ts +27 -26
  452. package/src/integrations/jira/stories.test.ts +15 -16
  453. package/src/integrations/jira/stories.ts +15 -15
  454. package/src/integrations/jira/sync.test.ts +68 -68
  455. package/src/integrations/jira/sync.ts +29 -39
  456. package/src/integrations/jira/transitions.ts +6 -6
  457. package/src/orchestrator/agent-selector.ts +9 -8
  458. package/src/orchestrator/dependency-resolver.ts +16 -7
  459. package/src/orchestrator/feature-branch.test.ts +85 -80
  460. package/src/orchestrator/feature-branch.ts +13 -14
  461. package/src/orchestrator/orphan-recovery.ts +14 -13
  462. package/src/orchestrator/scheduler.test.ts +536 -394
  463. package/src/orchestrator/scheduler.ts +129 -115
  464. package/src/utils/auto-merge.test.ts +102 -68
  465. package/src/utils/auto-merge.ts +161 -168
  466. package/src/utils/cli-helpers.test.ts +30 -32
  467. package/src/utils/cli-helpers.ts +15 -11
  468. package/src/utils/paths.test.ts +1 -0
  469. package/src/utils/paths.ts +14 -1
  470. package/src/utils/pr-sync.test.ts +55 -52
  471. package/src/utils/pr-sync.ts +27 -32
  472. package/src/utils/with-hive-context.ts +89 -1
@@ -1,6 +1,7 @@
1
1
  // Licensed under the Hungry Ghost Hive License. See LICENSE.
2
2
  import initSqlJs from 'sql.js';
3
3
  import { beforeEach, describe, expect, it } from 'vitest';
4
+ import { SqliteProvider } from '../provider.js';
4
5
  import { createAgent } from './agents.js';
5
6
  import { countQaFailuresByStory, createLog, getLogById, getLogsByAgent, getLogsByEventType, getLogsByStory, getLogsSince, getRecentLogs, pruneOldLogs, } from './logs.js';
6
7
  import { createStory } from './stories.js';
@@ -12,20 +13,21 @@ describe('logs queries', () => {
12
13
  let agentId;
13
14
  let storyId;
14
15
  beforeEach(async () => {
15
- db = await createTestDatabase();
16
- const team = createTeam(db, {
16
+ const rawDb = await createTestDatabase();
17
+ db = new SqliteProvider(rawDb);
18
+ const team = await createTeam(db, {
17
19
  repoUrl: 'https://github.com/test/repo.git',
18
20
  repoPath: '/path/to/repo',
19
21
  name: 'Test Team',
20
22
  });
21
23
  teamId = team.id;
22
- const agent = createAgent(db, {
24
+ const agent = await createAgent(db, {
23
25
  type: 'senior',
24
26
  teamId,
25
27
  model: 'claude-sonnet-4-5',
26
28
  });
27
29
  agentId = agent.id;
28
- const story = createStory(db, {
30
+ const story = await createStory(db, {
29
31
  teamId,
30
32
  title: 'Test Story',
31
33
  description: 'Test description',
@@ -33,9 +35,9 @@ describe('logs queries', () => {
33
35
  storyId = story.id;
34
36
  });
35
37
  describe('createLog', () => {
36
- it('should create a log entry with all fields', () => {
38
+ it('should create a log entry with all fields', async () => {
37
39
  const metadata = { key: 'value', count: 42 };
38
- const log = createLog(db, {
40
+ const log = await createLog(db, {
39
41
  agentId,
40
42
  storyId,
41
43
  eventType: 'STORY_STARTED',
@@ -52,8 +54,8 @@ describe('logs queries', () => {
52
54
  expect(log.metadata).toBe(JSON.stringify(metadata));
53
55
  expect(log.timestamp).toBeDefined();
54
56
  });
55
- it('should create a log entry with minimal fields', () => {
56
- const log = createLog(db, {
57
+ it('should create a log entry with minimal fields', async () => {
58
+ const log = await createLog(db, {
57
59
  agentId,
58
60
  eventType: 'AGENT_SPAWNED',
59
61
  });
@@ -65,8 +67,8 @@ describe('logs queries', () => {
65
67
  expect(log.message).toBeNull();
66
68
  expect(log.metadata).toBeNull();
67
69
  });
68
- it('should create a log entry without story', () => {
69
- const log = createLog(db, {
70
+ it('should create a log entry without story', async () => {
71
+ const log = await createLog(db, {
70
72
  agentId,
71
73
  eventType: 'AGENT_TERMINATED',
72
74
  message: 'Agent terminated',
@@ -76,50 +78,50 @@ describe('logs queries', () => {
76
78
  expect(log.event_type).toBe('AGENT_TERMINATED');
77
79
  expect(log.message).toBe('Agent terminated');
78
80
  });
79
- it('should handle null metadata', () => {
80
- const log = createLog(db, {
81
+ it('should handle null metadata', async () => {
82
+ const log = await createLog(db, {
81
83
  agentId,
82
84
  eventType: 'STORY_STARTED',
83
85
  metadata: null,
84
86
  });
85
87
  expect(log.metadata).toBeNull();
86
88
  });
87
- it('should serialize complex metadata', () => {
89
+ it('should serialize complex metadata', async () => {
88
90
  const metadata = {
89
91
  nested: { value: 'test' },
90
92
  array: [1, 2, 3],
91
93
  bool: true,
92
94
  };
93
- const log = createLog(db, {
95
+ const log = await createLog(db, {
94
96
  agentId,
95
97
  eventType: 'BUILD_STARTED',
96
98
  metadata,
97
99
  });
98
100
  expect(log.metadata).toBe(JSON.stringify(metadata));
99
101
  });
100
- it('should resolve tmux session names to canonical agent IDs', () => {
101
- const qaAgent = createAgent(db, {
102
+ it('should resolve tmux session names to canonical agent IDs', async () => {
103
+ const qaAgent = await createAgent(db, {
102
104
  type: 'qa',
103
105
  teamId,
104
106
  tmuxSession: 'hive-qa-testteam',
105
107
  });
106
- const log = createLog(db, {
108
+ const log = await createLog(db, {
107
109
  agentId: 'hive-qa-testteam',
108
110
  eventType: 'PR_REVIEW_STARTED',
109
111
  });
110
112
  expect(log.agent_id).toBe(qaAgent.id);
111
113
  });
112
- it('should create a synthetic agent row for unknown system actors', () => {
113
- const log = createLog(db, {
114
+ it('should create a synthetic agent row for unknown system actors', async () => {
115
+ const log = await createLog(db, {
114
116
  agentId: 'scheduler',
115
117
  eventType: 'TEAM_SCALED_UP',
116
118
  });
117
119
  expect(log.agent_id).toBe('scheduler');
118
- const result = db.exec("SELECT id, type, status FROM agents WHERE id = 'scheduler'");
120
+ const result = db.db.exec("SELECT id, type, status FROM agents WHERE id = 'scheduler'");
119
121
  expect(result[0]?.values[0]).toEqual(['scheduler', 'tech_lead', 'terminated']);
120
122
  });
121
- it('should drop invalid story references to avoid FK failures', () => {
122
- const log = createLog(db, {
123
+ it('should drop invalid story references to avoid FK failures', async () => {
124
+ const log = await createLog(db, {
123
125
  agentId,
124
126
  storyId: 'STORY-DOES-NOT-EXIST',
125
127
  eventType: 'STORY_PROGRESS_UPDATE',
@@ -128,9 +130,9 @@ describe('logs queries', () => {
128
130
  });
129
131
  it('should support legacy agents schemas without last_seen', async () => {
130
132
  const SQL = await initSqlJs();
131
- const legacyDb = new SQL.Database();
132
- legacyDb.run('PRAGMA foreign_keys = ON');
133
- legacyDb.run(`
133
+ const legacyRawDb = new SQL.Database();
134
+ legacyRawDb.run('PRAGMA foreign_keys = ON');
135
+ legacyRawDb.run(`
134
136
  CREATE TABLE agents (
135
137
  id TEXT PRIMARY KEY,
136
138
  type TEXT,
@@ -139,8 +141,8 @@ describe('logs queries', () => {
139
141
  updated_at TIMESTAMP
140
142
  );
141
143
  `);
142
- legacyDb.run(`CREATE TABLE stories (id TEXT PRIMARY KEY);`);
143
- legacyDb.run(`
144
+ legacyRawDb.run(`CREATE TABLE stories (id TEXT PRIMARY KEY);`);
145
+ legacyRawDb.run(`
144
146
  CREATE TABLE agent_logs (
145
147
  id INTEGER PRIMARY KEY AUTOINCREMENT,
146
148
  agent_id TEXT NOT NULL REFERENCES agents(id),
@@ -152,53 +154,54 @@ describe('logs queries', () => {
152
154
  timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
153
155
  );
154
156
  `);
155
- const log = createLog(legacyDb, {
157
+ const legacyDb = new SqliteProvider(legacyRawDb);
158
+ const log = await createLog(legacyDb, {
156
159
  agentId: 'scheduler',
157
160
  eventType: 'TEAM_SCALED_UP',
158
161
  });
159
162
  expect(log.agent_id).toBe('scheduler');
160
- const row = legacyDb.exec("SELECT id, status FROM agents WHERE id = 'scheduler'");
163
+ const row = legacyRawDb.exec("SELECT id, status FROM agents WHERE id = 'scheduler'");
161
164
  expect(row[0]?.values[0]).toEqual(['scheduler', 'terminated']);
162
165
  });
163
166
  });
164
167
  describe('getLogById', () => {
165
- it('should retrieve a log by ID', () => {
166
- const created = createLog(db, {
168
+ it('should retrieve a log by ID', async () => {
169
+ const created = await createLog(db, {
167
170
  agentId,
168
171
  eventType: 'STORY_STARTED',
169
172
  message: 'Test log',
170
173
  });
171
- const retrieved = getLogById(db, created.id);
174
+ const retrieved = await getLogById(db, created.id);
172
175
  expect(retrieved).toBeDefined();
173
176
  expect(retrieved?.id).toBe(created.id);
174
177
  expect(retrieved?.agent_id).toBe(agentId);
175
178
  expect(retrieved?.event_type).toBe('STORY_STARTED');
176
179
  expect(retrieved?.message).toBe('Test log');
177
180
  });
178
- it('should return undefined for non-existent log', () => {
179
- const log = getLogById(db, 99999);
181
+ it('should return undefined for non-existent log', async () => {
182
+ const log = await getLogById(db, 99999);
180
183
  expect(log).toBeUndefined();
181
184
  });
182
185
  });
183
186
  describe('getLogsByAgent', () => {
184
- it('should retrieve all logs for an agent', () => {
185
- createLog(db, { agentId, eventType: 'AGENT_SPAWNED' });
186
- createLog(db, { agentId, eventType: 'STORY_STARTED' });
187
- createLog(db, { agentId, eventType: 'STORY_COMPLETED' });
187
+ it('should retrieve all logs for an agent', async () => {
188
+ await createLog(db, { agentId, eventType: 'AGENT_SPAWNED' });
189
+ await createLog(db, { agentId, eventType: 'STORY_STARTED' });
190
+ await createLog(db, { agentId, eventType: 'STORY_COMPLETED' });
188
191
  // Create log for different agent
189
- const agent2 = createAgent(db, { type: 'junior', teamId });
190
- createLog(db, { agentId: agent2.id, eventType: 'AGENT_SPAWNED' });
191
- const logs = getLogsByAgent(db, agentId);
192
+ const agent2 = await createAgent(db, { type: 'junior', teamId });
193
+ await createLog(db, { agentId: agent2.id, eventType: 'AGENT_SPAWNED' });
194
+ const logs = await getLogsByAgent(db, agentId);
192
195
  expect(logs).toHaveLength(3);
193
196
  logs.forEach(log => {
194
197
  expect(log.agent_id).toBe(agentId);
195
198
  });
196
199
  });
197
- it('should return logs in descending timestamp order', () => {
198
- createLog(db, { agentId, eventType: 'AGENT_SPAWNED' });
199
- createLog(db, { agentId, eventType: 'STORY_STARTED' });
200
- createLog(db, { agentId, eventType: 'STORY_COMPLETED' });
201
- const logs = getLogsByAgent(db, agentId);
200
+ it('should return logs in descending timestamp order', async () => {
201
+ await createLog(db, { agentId, eventType: 'AGENT_SPAWNED' });
202
+ await createLog(db, { agentId, eventType: 'STORY_STARTED' });
203
+ await createLog(db, { agentId, eventType: 'STORY_COMPLETED' });
204
+ const logs = await getLogsByAgent(db, agentId);
202
205
  // Should be in descending order (newest first)
203
206
  expect(logs).toHaveLength(3);
204
207
  // Verify timestamps are in descending order
@@ -206,237 +209,237 @@ describe('logs queries', () => {
206
209
  expect(logs[i].timestamp >= logs[i + 1].timestamp).toBe(true);
207
210
  }
208
211
  });
209
- it('should respect the limit parameter', () => {
212
+ it('should respect the limit parameter', async () => {
210
213
  // Create 10 logs
211
214
  for (let i = 0; i < 10; i++) {
212
- createLog(db, { agentId, eventType: 'STORY_PROGRESS_UPDATE' });
215
+ await createLog(db, { agentId, eventType: 'STORY_PROGRESS_UPDATE' });
213
216
  }
214
- const logs = getLogsByAgent(db, agentId, 5);
217
+ const logs = await getLogsByAgent(db, agentId, 5);
215
218
  expect(logs).toHaveLength(5);
216
219
  });
217
- it('should use default limit of 100', () => {
220
+ it('should use default limit of 100', async () => {
218
221
  // Create 5 logs
219
222
  for (let i = 0; i < 5; i++) {
220
- createLog(db, { agentId, eventType: 'STORY_PROGRESS_UPDATE' });
223
+ await createLog(db, { agentId, eventType: 'STORY_PROGRESS_UPDATE' });
221
224
  }
222
- const logs = getLogsByAgent(db, agentId);
225
+ const logs = await getLogsByAgent(db, agentId);
223
226
  expect(logs).toHaveLength(5);
224
227
  });
225
- it('should return empty array for agent with no logs', () => {
226
- const agent2 = createAgent(db, { type: 'junior', teamId });
227
- const logs = getLogsByAgent(db, agent2.id);
228
+ it('should return empty array for agent with no logs', async () => {
229
+ const agent2 = await createAgent(db, { type: 'junior', teamId });
230
+ const logs = await getLogsByAgent(db, agent2.id);
228
231
  expect(logs).toEqual([]);
229
232
  });
230
233
  });
231
234
  describe('getLogsByStory', () => {
232
- it('should retrieve all logs for a story', () => {
233
- createLog(db, { agentId, storyId, eventType: 'STORY_STARTED' });
234
- createLog(db, { agentId, storyId, eventType: 'STORY_PROGRESS_UPDATE' });
235
- createLog(db, { agentId, storyId, eventType: 'STORY_COMPLETED' });
235
+ it('should retrieve all logs for a story', async () => {
236
+ await createLog(db, { agentId, storyId, eventType: 'STORY_STARTED' });
237
+ await createLog(db, { agentId, storyId, eventType: 'STORY_PROGRESS_UPDATE' });
238
+ await createLog(db, { agentId, storyId, eventType: 'STORY_COMPLETED' });
236
239
  // Create log for different story
237
- const story2 = createStory(db, {
240
+ const story2 = await createStory(db, {
238
241
  teamId,
239
242
  title: 'Story 2',
240
243
  description: 'Description',
241
244
  });
242
- createLog(db, { agentId, storyId: story2.id, eventType: 'STORY_STARTED' });
243
- const logs = getLogsByStory(db, storyId);
245
+ await createLog(db, { agentId, storyId: story2.id, eventType: 'STORY_STARTED' });
246
+ const logs = await getLogsByStory(db, storyId);
244
247
  expect(logs).toHaveLength(3);
245
248
  logs.forEach(log => {
246
249
  expect(log.story_id).toBe(storyId);
247
250
  });
248
251
  });
249
- it('should return logs in descending timestamp order', () => {
250
- createLog(db, { agentId, storyId, eventType: 'STORY_STARTED' });
251
- createLog(db, { agentId, storyId, eventType: 'STORY_PROGRESS_UPDATE' });
252
- createLog(db, { agentId, storyId, eventType: 'STORY_COMPLETED' });
253
- const logs = getLogsByStory(db, storyId);
252
+ it('should return logs in descending timestamp order', async () => {
253
+ await createLog(db, { agentId, storyId, eventType: 'STORY_STARTED' });
254
+ await createLog(db, { agentId, storyId, eventType: 'STORY_PROGRESS_UPDATE' });
255
+ await createLog(db, { agentId, storyId, eventType: 'STORY_COMPLETED' });
256
+ const logs = await getLogsByStory(db, storyId);
254
257
  expect(logs).toHaveLength(3);
255
258
  // Verify timestamps are in descending order
256
259
  for (let i = 0; i < logs.length - 1; i++) {
257
260
  expect(logs[i].timestamp >= logs[i + 1].timestamp).toBe(true);
258
261
  }
259
262
  });
260
- it('should return empty array for story with no logs', () => {
261
- const story2 = createStory(db, {
263
+ it('should return empty array for story with no logs', async () => {
264
+ const story2 = await createStory(db, {
262
265
  teamId,
263
266
  title: 'Story 2',
264
267
  description: 'Description',
265
268
  });
266
- const logs = getLogsByStory(db, story2.id);
269
+ const logs = await getLogsByStory(db, story2.id);
267
270
  expect(logs).toEqual([]);
268
271
  });
269
272
  });
270
273
  describe('getLogsByEventType', () => {
271
- it('should retrieve all logs of a specific event type', () => {
272
- createLog(db, { agentId, eventType: 'STORY_STARTED' });
273
- createLog(db, { agentId, eventType: 'STORY_COMPLETED' });
274
- createLog(db, { agentId, eventType: 'STORY_STARTED' });
275
- const logs = getLogsByEventType(db, 'STORY_STARTED');
274
+ it('should retrieve all logs of a specific event type', async () => {
275
+ await createLog(db, { agentId, eventType: 'STORY_STARTED' });
276
+ await createLog(db, { agentId, eventType: 'STORY_COMPLETED' });
277
+ await createLog(db, { agentId, eventType: 'STORY_STARTED' });
278
+ const logs = await getLogsByEventType(db, 'STORY_STARTED');
276
279
  expect(logs).toHaveLength(2);
277
280
  logs.forEach(log => {
278
281
  expect(log.event_type).toBe('STORY_STARTED');
279
282
  });
280
283
  });
281
- it('should respect the limit parameter', () => {
284
+ it('should respect the limit parameter', async () => {
282
285
  for (let i = 0; i < 10; i++) {
283
- createLog(db, { agentId, eventType: 'BUILD_STARTED' });
286
+ await createLog(db, { agentId, eventType: 'BUILD_STARTED' });
284
287
  }
285
- const logs = getLogsByEventType(db, 'BUILD_STARTED', 5);
288
+ const logs = await getLogsByEventType(db, 'BUILD_STARTED', 5);
286
289
  expect(logs).toHaveLength(5);
287
290
  });
288
- it('should return empty array for event type with no logs', () => {
289
- const logs = getLogsByEventType(db, 'PR_REJECTED');
291
+ it('should return empty array for event type with no logs', async () => {
292
+ const logs = await getLogsByEventType(db, 'PR_REJECTED');
290
293
  expect(logs).toEqual([]);
291
294
  });
292
295
  });
293
296
  describe('getRecentLogs', () => {
294
- it('should retrieve recent logs', () => {
295
- createLog(db, { agentId, eventType: 'AGENT_SPAWNED' });
296
- createLog(db, { agentId, eventType: 'STORY_STARTED' });
297
- createLog(db, { agentId, eventType: 'STORY_COMPLETED' });
298
- const logs = getRecentLogs(db);
297
+ it('should retrieve recent logs', async () => {
298
+ await createLog(db, { agentId, eventType: 'AGENT_SPAWNED' });
299
+ await createLog(db, { agentId, eventType: 'STORY_STARTED' });
300
+ await createLog(db, { agentId, eventType: 'STORY_COMPLETED' });
301
+ const logs = await getRecentLogs(db);
299
302
  expect(logs.length).toBeGreaterThan(0);
300
303
  });
301
- it('should respect the limit parameter', () => {
304
+ it('should respect the limit parameter', async () => {
302
305
  for (let i = 0; i < 10; i++) {
303
- createLog(db, { agentId, eventType: 'STORY_PROGRESS_UPDATE' });
306
+ await createLog(db, { agentId, eventType: 'STORY_PROGRESS_UPDATE' });
304
307
  }
305
- const logs = getRecentLogs(db, 5);
308
+ const logs = await getRecentLogs(db, 5);
306
309
  expect(logs).toHaveLength(5);
307
310
  });
308
- it('should return logs in descending timestamp order', () => {
309
- createLog(db, { agentId, eventType: 'AGENT_SPAWNED' });
310
- createLog(db, { agentId, eventType: 'STORY_STARTED' });
311
- createLog(db, { agentId, eventType: 'STORY_COMPLETED' });
312
- const logs = getRecentLogs(db);
311
+ it('should return logs in descending timestamp order', async () => {
312
+ await createLog(db, { agentId, eventType: 'AGENT_SPAWNED' });
313
+ await createLog(db, { agentId, eventType: 'STORY_STARTED' });
314
+ await createLog(db, { agentId, eventType: 'STORY_COMPLETED' });
315
+ const logs = await getRecentLogs(db);
313
316
  expect(logs[0].event_type).toBe('STORY_COMPLETED');
314
317
  expect(logs[2].event_type).toBe('AGENT_SPAWNED');
315
318
  });
316
- it('should use default limit of 50', () => {
319
+ it('should use default limit of 50', async () => {
317
320
  for (let i = 0; i < 60; i++) {
318
- createLog(db, { agentId, eventType: 'STORY_PROGRESS_UPDATE' });
321
+ await createLog(db, { agentId, eventType: 'STORY_PROGRESS_UPDATE' });
319
322
  }
320
- const logs = getRecentLogs(db);
323
+ const logs = await getRecentLogs(db);
321
324
  expect(logs).toHaveLength(50);
322
325
  });
323
326
  });
324
327
  describe('getLogsSince', () => {
325
- it('should retrieve logs since a specific timestamp', () => {
326
- createLog(db, { agentId, eventType: 'AGENT_SPAWNED' });
328
+ it('should retrieve logs since a specific timestamp', async () => {
329
+ await createLog(db, { agentId, eventType: 'AGENT_SPAWNED' });
327
330
  const sinceTime = new Date().toISOString();
328
331
  // Small delay to ensure different timestamps
329
- createLog(db, { agentId, eventType: 'STORY_STARTED' });
330
- createLog(db, { agentId, eventType: 'STORY_COMPLETED' });
331
- const logs = getLogsSince(db, sinceTime);
332
+ await createLog(db, { agentId, eventType: 'STORY_STARTED' });
333
+ await createLog(db, { agentId, eventType: 'STORY_COMPLETED' });
334
+ const logs = await getLogsSince(db, sinceTime);
332
335
  // Should only get logs created after sinceTime
333
336
  expect(logs.length).toBeGreaterThanOrEqual(0);
334
337
  logs.forEach(log => {
335
338
  expect(log.timestamp > sinceTime).toBe(true);
336
339
  });
337
340
  });
338
- it('should return logs in ascending timestamp order', () => {
341
+ it('should return logs in ascending timestamp order', async () => {
339
342
  const sinceTime = new Date().toISOString();
340
- createLog(db, { agentId, eventType: 'AGENT_SPAWNED' });
341
- createLog(db, { agentId, eventType: 'STORY_STARTED' });
342
- createLog(db, { agentId, eventType: 'STORY_COMPLETED' });
343
- const logs = getLogsSince(db, sinceTime);
343
+ await createLog(db, { agentId, eventType: 'AGENT_SPAWNED' });
344
+ await createLog(db, { agentId, eventType: 'STORY_STARTED' });
345
+ await createLog(db, { agentId, eventType: 'STORY_COMPLETED' });
346
+ const logs = await getLogsSince(db, sinceTime);
344
347
  if (logs.length > 1) {
345
348
  for (let i = 0; i < logs.length - 1; i++) {
346
349
  expect(logs[i].timestamp <= logs[i + 1].timestamp).toBe(true);
347
350
  }
348
351
  }
349
352
  });
350
- it('should return empty array if no logs since timestamp', () => {
351
- createLog(db, { agentId, eventType: 'AGENT_SPAWNED' });
353
+ it('should return empty array if no logs since timestamp', async () => {
354
+ await createLog(db, { agentId, eventType: 'AGENT_SPAWNED' });
352
355
  const futureTime = new Date(Date.now() + 1000000).toISOString();
353
- const logs = getLogsSince(db, futureTime);
356
+ const logs = await getLogsSince(db, futureTime);
354
357
  expect(logs).toEqual([]);
355
358
  });
356
359
  });
357
360
  describe('pruneOldLogs', () => {
358
- it('should delete logs older than retention days', () => {
361
+ it('should delete logs older than retention days', async () => {
359
362
  // Create a log with old timestamp (100 days ago)
360
363
  const oldDate = new Date();
361
364
  oldDate.setDate(oldDate.getDate() - 100);
362
365
  // We need to manually insert to set a past timestamp
363
- db.run(`
366
+ db.db.run(`
364
367
  INSERT INTO agent_logs (agent_id, event_type, timestamp)
365
368
  VALUES (?, ?, ?)
366
369
  `, [agentId, 'AGENT_SPAWNED', oldDate.toISOString()]);
367
370
  // Create a recent log
368
- createLog(db, { agentId, eventType: 'STORY_STARTED' });
369
- const deletedCount = pruneOldLogs(db, 30);
371
+ await createLog(db, { agentId, eventType: 'STORY_STARTED' });
372
+ const deletedCount = await pruneOldLogs(db, 30);
370
373
  expect(deletedCount).toBe(1);
371
374
  // Verify recent log still exists
372
- const logs = getLogsByAgent(db, agentId);
375
+ const logs = await getLogsByAgent(db, agentId);
373
376
  expect(logs).toHaveLength(1);
374
377
  expect(logs[0].event_type).toBe('STORY_STARTED');
375
378
  });
376
- it('should return 0 if no logs to prune', () => {
377
- createLog(db, { agentId, eventType: 'AGENT_SPAWNED' });
378
- const deletedCount = pruneOldLogs(db, 30);
379
+ it('should return 0 if no logs to prune', async () => {
380
+ await createLog(db, { agentId, eventType: 'AGENT_SPAWNED' });
381
+ const deletedCount = await pruneOldLogs(db, 30);
379
382
  expect(deletedCount).toBe(0);
380
383
  });
381
- it('should handle different retention periods', () => {
384
+ it('should handle different retention periods', async () => {
382
385
  // Create logs with different ages
383
386
  const date50DaysAgo = new Date();
384
387
  date50DaysAgo.setDate(date50DaysAgo.getDate() - 50);
385
388
  const date20DaysAgo = new Date();
386
389
  date20DaysAgo.setDate(date20DaysAgo.getDate() - 20);
387
- db.run(`
390
+ db.db.run(`
388
391
  INSERT INTO agent_logs (agent_id, event_type, timestamp)
389
392
  VALUES (?, ?, ?)
390
393
  `, [agentId, 'AGENT_SPAWNED', date50DaysAgo.toISOString()]);
391
- db.run(`
394
+ db.db.run(`
392
395
  INSERT INTO agent_logs (agent_id, event_type, timestamp)
393
396
  VALUES (?, ?, ?)
394
397
  `, [agentId, 'STORY_STARTED', date20DaysAgo.toISOString()]);
395
- createLog(db, { agentId, eventType: 'STORY_COMPLETED' });
398
+ await createLog(db, { agentId, eventType: 'STORY_COMPLETED' });
396
399
  // Prune logs older than 30 days
397
- const deletedCount = pruneOldLogs(db, 30);
400
+ const deletedCount = await pruneOldLogs(db, 30);
398
401
  expect(deletedCount).toBe(1);
399
- const remainingLogs = getLogsByAgent(db, agentId);
402
+ const remainingLogs = await getLogsByAgent(db, agentId);
400
403
  expect(remainingLogs).toHaveLength(2);
401
404
  });
402
405
  });
403
406
  describe('countQaFailuresByStory', () => {
404
- it('should count STORY_QA_FAILED events for a specific story', () => {
405
- createLog(db, { agentId, storyId, eventType: 'STORY_QA_FAILED' });
406
- createLog(db, { agentId, storyId, eventType: 'STORY_QA_FAILED' });
407
- createLog(db, { agentId, storyId, eventType: 'STORY_QA_FAILED' });
408
- const count = countQaFailuresByStory(db, storyId);
407
+ it('should count STORY_QA_FAILED events for a specific story', async () => {
408
+ await createLog(db, { agentId, storyId, eventType: 'STORY_QA_FAILED' });
409
+ await createLog(db, { agentId, storyId, eventType: 'STORY_QA_FAILED' });
410
+ await createLog(db, { agentId, storyId, eventType: 'STORY_QA_FAILED' });
411
+ const count = await countQaFailuresByStory(db, storyId);
409
412
  expect(count).toBe(3);
410
413
  });
411
- it('should not count other event types for a story', () => {
412
- createLog(db, { agentId, storyId, eventType: 'STORY_QA_FAILED' });
413
- createLog(db, { agentId, storyId, eventType: 'STORY_QA_PASSED' });
414
- createLog(db, { agentId, storyId, eventType: 'STORY_STARTED' });
415
- const count = countQaFailuresByStory(db, storyId);
414
+ it('should not count other event types for a story', async () => {
415
+ await createLog(db, { agentId, storyId, eventType: 'STORY_QA_FAILED' });
416
+ await createLog(db, { agentId, storyId, eventType: 'STORY_QA_PASSED' });
417
+ await createLog(db, { agentId, storyId, eventType: 'STORY_STARTED' });
418
+ const count = await countQaFailuresByStory(db, storyId);
416
419
  expect(count).toBe(1);
417
420
  });
418
- it('should only count failures for the specified story', () => {
419
- const story2 = createStory(db, {
421
+ it('should only count failures for the specified story', async () => {
422
+ const story2 = await createStory(db, {
420
423
  teamId,
421
424
  title: 'Story 2',
422
425
  description: 'Description',
423
426
  });
424
- createLog(db, { agentId, storyId, eventType: 'STORY_QA_FAILED' });
425
- createLog(db, { agentId, storyId, eventType: 'STORY_QA_FAILED' });
426
- createLog(db, { agentId, storyId: story2.id, eventType: 'STORY_QA_FAILED' });
427
- const count1 = countQaFailuresByStory(db, storyId);
428
- const count2 = countQaFailuresByStory(db, story2.id);
427
+ await createLog(db, { agentId, storyId, eventType: 'STORY_QA_FAILED' });
428
+ await createLog(db, { agentId, storyId, eventType: 'STORY_QA_FAILED' });
429
+ await createLog(db, { agentId, storyId: story2.id, eventType: 'STORY_QA_FAILED' });
430
+ const count1 = await countQaFailuresByStory(db, storyId);
431
+ const count2 = await countQaFailuresByStory(db, story2.id);
429
432
  expect(count1).toBe(2);
430
433
  expect(count2).toBe(1);
431
434
  });
432
- it('should return 0 for story with no QA failures', () => {
433
- createLog(db, { agentId, storyId, eventType: 'STORY_STARTED' });
434
- createLog(db, { agentId, storyId, eventType: 'STORY_COMPLETED' });
435
- const count = countQaFailuresByStory(db, storyId);
435
+ it('should return 0 for story with no QA failures', async () => {
436
+ await createLog(db, { agentId, storyId, eventType: 'STORY_STARTED' });
437
+ await createLog(db, { agentId, storyId, eventType: 'STORY_COMPLETED' });
438
+ const count = await countQaFailuresByStory(db, storyId);
436
439
  expect(count).toBe(0);
437
440
  });
438
- it('should return 0 for non-existent story', () => {
439
- const count = countQaFailuresByStory(db, 'non-existent-story');
441
+ it('should return 0 for non-existent story', async () => {
442
+ const count = await countQaFailuresByStory(db, 'non-existent-story');
440
443
  expect(count).toBe(0);
441
444
  });
442
445
  });