@cleocode/cleo 2026.3.58 → 2026.3.59

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 (705) hide show
  1. package/dist/cli/index.js +1218 -605
  2. package/dist/cli/index.js.map +4 -4
  3. package/dist/mcp/index.js +1061 -604
  4. package/dist/mcp/index.js.map +4 -4
  5. package/package.json +3 -3
  6. package/dist/cli/commander-shim.d.ts +0 -112
  7. package/dist/cli/commander-shim.d.ts.map +0 -1
  8. package/dist/cli/commander-shim.js +0 -233
  9. package/dist/cli/commander-shim.js.map +0 -1
  10. package/dist/cli/commands/add.d.ts +0 -12
  11. package/dist/cli/commands/add.d.ts.map +0 -1
  12. package/dist/cli/commands/add.js +0 -91
  13. package/dist/cli/commands/add.js.map +0 -1
  14. package/dist/cli/commands/adr.d.ts +0 -27
  15. package/dist/cli/commands/adr.d.ts.map +0 -1
  16. package/dist/cli/commands/adr.js +0 -79
  17. package/dist/cli/commands/adr.js.map +0 -1
  18. package/dist/cli/commands/analyze.d.ts +0 -12
  19. package/dist/cli/commands/analyze.d.ts.map +0 -1
  20. package/dist/cli/commands/analyze.js +0 -20
  21. package/dist/cli/commands/analyze.js.map +0 -1
  22. package/dist/cli/commands/archive-stats.d.ts +0 -18
  23. package/dist/cli/commands/archive-stats.d.ts.map +0 -1
  24. package/dist/cli/commands/archive-stats.js +0 -49
  25. package/dist/cli/commands/archive-stats.js.map +0 -1
  26. package/dist/cli/commands/archive.d.ts +0 -12
  27. package/dist/cli/commands/archive.d.ts.map +0 -1
  28. package/dist/cli/commands/archive.js +0 -32
  29. package/dist/cli/commands/archive.js.map +0 -1
  30. package/dist/cli/commands/backup.d.ts +0 -8
  31. package/dist/cli/commands/backup.d.ts.map +0 -1
  32. package/dist/cli/commands/backup.js +0 -35
  33. package/dist/cli/commands/backup.js.map +0 -1
  34. package/dist/cli/commands/blockers.d.ts +0 -7
  35. package/dist/cli/commands/blockers.d.ts.map +0 -1
  36. package/dist/cli/commands/blockers.js +0 -16
  37. package/dist/cli/commands/blockers.js.map +0 -1
  38. package/dist/cli/commands/briefing.d.ts +0 -22
  39. package/dist/cli/commands/briefing.d.ts.map +0 -1
  40. package/dist/cli/commands/briefing.js +0 -45
  41. package/dist/cli/commands/briefing.js.map +0 -1
  42. package/dist/cli/commands/bug.d.ts +0 -12
  43. package/dist/cli/commands/bug.d.ts.map +0 -1
  44. package/dist/cli/commands/bug.js +0 -81
  45. package/dist/cli/commands/bug.js.map +0 -1
  46. package/dist/cli/commands/checkpoint.d.ts +0 -15
  47. package/dist/cli/commands/checkpoint.d.ts.map +0 -1
  48. package/dist/cli/commands/checkpoint.js +0 -91
  49. package/dist/cli/commands/checkpoint.js.map +0 -1
  50. package/dist/cli/commands/commands.d.ts +0 -13
  51. package/dist/cli/commands/commands.d.ts.map +0 -1
  52. package/dist/cli/commands/commands.js +0 -30
  53. package/dist/cli/commands/commands.js.map +0 -1
  54. package/dist/cli/commands/complete.d.ts +0 -12
  55. package/dist/cli/commands/complete.d.ts.map +0 -1
  56. package/dist/cli/commands/complete.js +0 -43
  57. package/dist/cli/commands/complete.js.map +0 -1
  58. package/dist/cli/commands/compliance.d.ts +0 -8
  59. package/dist/cli/commands/compliance.d.ts.map +0 -1
  60. package/dist/cli/commands/compliance.js +0 -85
  61. package/dist/cli/commands/compliance.js.map +0 -1
  62. package/dist/cli/commands/config.d.ts +0 -9
  63. package/dist/cli/commands/config.d.ts.map +0 -1
  64. package/dist/cli/commands/config.js +0 -43
  65. package/dist/cli/commands/config.js.map +0 -1
  66. package/dist/cli/commands/consensus.d.ts +0 -13
  67. package/dist/cli/commands/consensus.d.ts.map +0 -1
  68. package/dist/cli/commands/consensus.js +0 -45
  69. package/dist/cli/commands/consensus.js.map +0 -1
  70. package/dist/cli/commands/context.d.ts +0 -8
  71. package/dist/cli/commands/context.d.ts.map +0 -1
  72. package/dist/cli/commands/context.js +0 -40
  73. package/dist/cli/commands/context.js.map +0 -1
  74. package/dist/cli/commands/contribution.d.ts +0 -13
  75. package/dist/cli/commands/contribution.d.ts.map +0 -1
  76. package/dist/cli/commands/contribution.js +0 -41
  77. package/dist/cli/commands/contribution.js.map +0 -1
  78. package/dist/cli/commands/current.d.ts +0 -13
  79. package/dist/cli/commands/current.d.ts.map +0 -1
  80. package/dist/cli/commands/current.js +0 -20
  81. package/dist/cli/commands/current.js.map +0 -1
  82. package/dist/cli/commands/dash.d.ts +0 -12
  83. package/dist/cli/commands/dash.d.ts.map +0 -1
  84. package/dist/cli/commands/dash.js +0 -24
  85. package/dist/cli/commands/dash.js.map +0 -1
  86. package/dist/cli/commands/decomposition.d.ts +0 -13
  87. package/dist/cli/commands/decomposition.d.ts.map +0 -1
  88. package/dist/cli/commands/decomposition.js +0 -45
  89. package/dist/cli/commands/decomposition.js.map +0 -1
  90. package/dist/cli/commands/delete.d.ts +0 -12
  91. package/dist/cli/commands/delete.d.ts.map +0 -1
  92. package/dist/cli/commands/delete.js +0 -37
  93. package/dist/cli/commands/delete.js.map +0 -1
  94. package/dist/cli/commands/deps.d.ts +0 -9
  95. package/dist/cli/commands/deps.d.ts.map +0 -1
  96. package/dist/cli/commands/deps.js +0 -73
  97. package/dist/cli/commands/deps.js.map +0 -1
  98. package/dist/cli/commands/detect-drift.d.ts +0 -15
  99. package/dist/cli/commands/detect-drift.d.ts.map +0 -1
  100. package/dist/cli/commands/detect-drift.js +0 -386
  101. package/dist/cli/commands/detect-drift.js.map +0 -1
  102. package/dist/cli/commands/detect.d.ts +0 -10
  103. package/dist/cli/commands/detect.d.ts.map +0 -1
  104. package/dist/cli/commands/detect.js +0 -24
  105. package/dist/cli/commands/detect.js.map +0 -1
  106. package/dist/cli/commands/docs.d.ts +0 -13
  107. package/dist/cli/commands/docs.d.ts.map +0 -1
  108. package/dist/cli/commands/docs.js +0 -169
  109. package/dist/cli/commands/docs.js.map +0 -1
  110. package/dist/cli/commands/doctor.d.ts +0 -11
  111. package/dist/cli/commands/doctor.d.ts.map +0 -1
  112. package/dist/cli/commands/doctor.js +0 -54
  113. package/dist/cli/commands/doctor.js.map +0 -1
  114. package/dist/cli/commands/dynamic.d.ts +0 -24
  115. package/dist/cli/commands/dynamic.d.ts.map +0 -1
  116. package/dist/cli/commands/dynamic.js +0 -27
  117. package/dist/cli/commands/dynamic.js.map +0 -1
  118. package/dist/cli/commands/env.d.ts +0 -12
  119. package/dist/cli/commands/env.d.ts.map +0 -1
  120. package/dist/cli/commands/env.js +0 -44
  121. package/dist/cli/commands/env.js.map +0 -1
  122. package/dist/cli/commands/exists.d.ts +0 -7
  123. package/dist/cli/commands/exists.d.ts.map +0 -1
  124. package/dist/cli/commands/exists.js +0 -33
  125. package/dist/cli/commands/exists.js.map +0 -1
  126. package/dist/cli/commands/export-tasks.d.ts +0 -10
  127. package/dist/cli/commands/export-tasks.d.ts.map +0 -1
  128. package/dist/cli/commands/export-tasks.js +0 -47
  129. package/dist/cli/commands/export-tasks.js.map +0 -1
  130. package/dist/cli/commands/export.d.ts +0 -9
  131. package/dist/cli/commands/export.d.ts.map +0 -1
  132. package/dist/cli/commands/export.js +0 -46
  133. package/dist/cli/commands/export.js.map +0 -1
  134. package/dist/cli/commands/find.d.ts +0 -14
  135. package/dist/cli/commands/find.d.ts.map +0 -1
  136. package/dist/cli/commands/find.js +0 -70
  137. package/dist/cli/commands/find.js.map +0 -1
  138. package/dist/cli/commands/generate-changelog.d.ts +0 -14
  139. package/dist/cli/commands/generate-changelog.d.ts.map +0 -1
  140. package/dist/cli/commands/generate-changelog.js +0 -252
  141. package/dist/cli/commands/generate-changelog.js.map +0 -1
  142. package/dist/cli/commands/grade.d.ts +0 -13
  143. package/dist/cli/commands/grade.d.ts.map +0 -1
  144. package/dist/cli/commands/grade.js +0 -26
  145. package/dist/cli/commands/grade.js.map +0 -1
  146. package/dist/cli/commands/history.d.ts +0 -9
  147. package/dist/cli/commands/history.d.ts.map +0 -1
  148. package/dist/cli/commands/history.js +0 -30
  149. package/dist/cli/commands/history.js.map +0 -1
  150. package/dist/cli/commands/implementation.d.ts +0 -13
  151. package/dist/cli/commands/implementation.d.ts.map +0 -1
  152. package/dist/cli/commands/implementation.js +0 -41
  153. package/dist/cli/commands/implementation.js.map +0 -1
  154. package/dist/cli/commands/import-tasks.d.ts +0 -10
  155. package/dist/cli/commands/import-tasks.d.ts.map +0 -1
  156. package/dist/cli/commands/import-tasks.js +0 -38
  157. package/dist/cli/commands/import-tasks.js.map +0 -1
  158. package/dist/cli/commands/import.d.ts +0 -9
  159. package/dist/cli/commands/import.d.ts.map +0 -1
  160. package/dist/cli/commands/import.js +0 -28
  161. package/dist/cli/commands/import.js.map +0 -1
  162. package/dist/cli/commands/init.d.ts +0 -34
  163. package/dist/cli/commands/init.d.ts.map +0 -1
  164. package/dist/cli/commands/init.js +0 -89
  165. package/dist/cli/commands/init.js.map +0 -1
  166. package/dist/cli/commands/inject.d.ts +0 -8
  167. package/dist/cli/commands/inject.d.ts.map +0 -1
  168. package/dist/cli/commands/inject.js +0 -28
  169. package/dist/cli/commands/inject.js.map +0 -1
  170. package/dist/cli/commands/install-global.d.ts +0 -19
  171. package/dist/cli/commands/install-global.d.ts.map +0 -1
  172. package/dist/cli/commands/install-global.js +0 -50
  173. package/dist/cli/commands/install-global.js.map +0 -1
  174. package/dist/cli/commands/issue.d.ts +0 -14
  175. package/dist/cli/commands/issue.d.ts.map +0 -1
  176. package/dist/cli/commands/issue.js +0 -105
  177. package/dist/cli/commands/issue.js.map +0 -1
  178. package/dist/cli/commands/labels.d.ts +0 -13
  179. package/dist/cli/commands/labels.d.ts.map +0 -1
  180. package/dist/cli/commands/labels.js +0 -44
  181. package/dist/cli/commands/labels.js.map +0 -1
  182. package/dist/cli/commands/lifecycle.d.ts +0 -8
  183. package/dist/cli/commands/lifecycle.d.ts.map +0 -1
  184. package/dist/cli/commands/lifecycle.js +0 -72
  185. package/dist/cli/commands/lifecycle.js.map +0 -1
  186. package/dist/cli/commands/list.d.ts +0 -14
  187. package/dist/cli/commands/list.d.ts.map +0 -1
  188. package/dist/cli/commands/list.js +0 -71
  189. package/dist/cli/commands/list.js.map +0 -1
  190. package/dist/cli/commands/log.d.ts +0 -12
  191. package/dist/cli/commands/log.d.ts.map +0 -1
  192. package/dist/cli/commands/log.js +0 -30
  193. package/dist/cli/commands/log.js.map +0 -1
  194. package/dist/cli/commands/map.d.ts +0 -10
  195. package/dist/cli/commands/map.d.ts.map +0 -1
  196. package/dist/cli/commands/map.js +0 -23
  197. package/dist/cli/commands/map.js.map +0 -1
  198. package/dist/cli/commands/mcp-install.d.ts +0 -17
  199. package/dist/cli/commands/mcp-install.d.ts.map +0 -1
  200. package/dist/cli/commands/mcp-install.js +0 -128
  201. package/dist/cli/commands/mcp-install.js.map +0 -1
  202. package/dist/cli/commands/memory-brain.d.ts +0 -14
  203. package/dist/cli/commands/memory-brain.d.ts.map +0 -1
  204. package/dist/cli/commands/memory-brain.js +0 -151
  205. package/dist/cli/commands/memory-brain.js.map +0 -1
  206. package/dist/cli/commands/migrate-claude-mem.d.ts +0 -18
  207. package/dist/cli/commands/migrate-claude-mem.d.ts.map +0 -1
  208. package/dist/cli/commands/migrate-claude-mem.js +0 -60
  209. package/dist/cli/commands/migrate-claude-mem.js.map +0 -1
  210. package/dist/cli/commands/next.d.ts +0 -9
  211. package/dist/cli/commands/next.d.ts.map +0 -1
  212. package/dist/cli/commands/next.js +0 -20
  213. package/dist/cli/commands/next.js.map +0 -1
  214. package/dist/cli/commands/nexus.d.ts +0 -16
  215. package/dist/cli/commands/nexus.d.ts.map +0 -1
  216. package/dist/cli/commands/nexus.js +0 -155
  217. package/dist/cli/commands/nexus.js.map +0 -1
  218. package/dist/cli/commands/observe.d.ts +0 -9
  219. package/dist/cli/commands/observe.d.ts.map +0 -1
  220. package/dist/cli/commands/observe.js +0 -39
  221. package/dist/cli/commands/observe.js.map +0 -1
  222. package/dist/cli/commands/ops.d.ts +0 -10
  223. package/dist/cli/commands/ops.d.ts.map +0 -1
  224. package/dist/cli/commands/ops.js +0 -19
  225. package/dist/cli/commands/ops.js.map +0 -1
  226. package/dist/cli/commands/orchestrate.d.ts +0 -8
  227. package/dist/cli/commands/orchestrate.d.ts.map +0 -1
  228. package/dist/cli/commands/orchestrate.js +0 -58
  229. package/dist/cli/commands/orchestrate.js.map +0 -1
  230. package/dist/cli/commands/otel.d.ts +0 -12
  231. package/dist/cli/commands/otel.d.ts.map +0 -1
  232. package/dist/cli/commands/otel.js +0 -128
  233. package/dist/cli/commands/otel.js.map +0 -1
  234. package/dist/cli/commands/phase.d.ts +0 -12
  235. package/dist/cli/commands/phase.d.ts.map +0 -1
  236. package/dist/cli/commands/phase.js +0 -88
  237. package/dist/cli/commands/phase.js.map +0 -1
  238. package/dist/cli/commands/phases.d.ts +0 -12
  239. package/dist/cli/commands/phases.d.ts.map +0 -1
  240. package/dist/cli/commands/phases.js +0 -37
  241. package/dist/cli/commands/phases.js.map +0 -1
  242. package/dist/cli/commands/plan.d.ts +0 -8
  243. package/dist/cli/commands/plan.d.ts.map +0 -1
  244. package/dist/cli/commands/plan.js +0 -15
  245. package/dist/cli/commands/plan.js.map +0 -1
  246. package/dist/cli/commands/promote.d.ts +0 -7
  247. package/dist/cli/commands/promote.d.ts.map +0 -1
  248. package/dist/cli/commands/promote.js +0 -15
  249. package/dist/cli/commands/promote.js.map +0 -1
  250. package/dist/cli/commands/refresh-memory.d.ts +0 -9
  251. package/dist/cli/commands/refresh-memory.d.ts.map +0 -1
  252. package/dist/cli/commands/refresh-memory.js +0 -24
  253. package/dist/cli/commands/refresh-memory.js.map +0 -1
  254. package/dist/cli/commands/relates.d.ts +0 -12
  255. package/dist/cli/commands/relates.d.ts.map +0 -1
  256. package/dist/cli/commands/relates.js +0 -53
  257. package/dist/cli/commands/relates.js.map +0 -1
  258. package/dist/cli/commands/release.d.ts +0 -8
  259. package/dist/cli/commands/release.d.ts.map +0 -1
  260. package/dist/cli/commands/release.js +0 -72
  261. package/dist/cli/commands/release.js.map +0 -1
  262. package/dist/cli/commands/remote.d.ts +0 -12
  263. package/dist/cli/commands/remote.d.ts.map +0 -1
  264. package/dist/cli/commands/remote.js +0 -207
  265. package/dist/cli/commands/remote.js.map +0 -1
  266. package/dist/cli/commands/reorder.d.ts +0 -7
  267. package/dist/cli/commands/reorder.d.ts.map +0 -1
  268. package/dist/cli/commands/reorder.js +0 -20
  269. package/dist/cli/commands/reorder.js.map +0 -1
  270. package/dist/cli/commands/reparent.d.ts +0 -10
  271. package/dist/cli/commands/reparent.d.ts.map +0 -1
  272. package/dist/cli/commands/reparent.js +0 -19
  273. package/dist/cli/commands/reparent.js.map +0 -1
  274. package/dist/cli/commands/research.d.ts +0 -8
  275. package/dist/cli/commands/research.d.ts.map +0 -1
  276. package/dist/cli/commands/research.js +0 -129
  277. package/dist/cli/commands/research.js.map +0 -1
  278. package/dist/cli/commands/restore.d.ts +0 -11
  279. package/dist/cli/commands/restore.d.ts.map +0 -1
  280. package/dist/cli/commands/restore.js +0 -224
  281. package/dist/cli/commands/restore.js.map +0 -1
  282. package/dist/cli/commands/roadmap.d.ts +0 -8
  283. package/dist/cli/commands/roadmap.d.ts.map +0 -1
  284. package/dist/cli/commands/roadmap.js +0 -21
  285. package/dist/cli/commands/roadmap.js.map +0 -1
  286. package/dist/cli/commands/safestop.d.ts +0 -14
  287. package/dist/cli/commands/safestop.d.ts.map +0 -1
  288. package/dist/cli/commands/safestop.js +0 -32
  289. package/dist/cli/commands/safestop.js.map +0 -1
  290. package/dist/cli/commands/self-update.d.ts +0 -15
  291. package/dist/cli/commands/self-update.d.ts.map +0 -1
  292. package/dist/cli/commands/self-update.js +0 -329
  293. package/dist/cli/commands/self-update.js.map +0 -1
  294. package/dist/cli/commands/sequence.d.ts +0 -8
  295. package/dist/cli/commands/sequence.d.ts.map +0 -1
  296. package/dist/cli/commands/sequence.js +0 -30
  297. package/dist/cli/commands/sequence.js.map +0 -1
  298. package/dist/cli/commands/session.d.ts +0 -12
  299. package/dist/cli/commands/session.d.ts.map +0 -1
  300. package/dist/cli/commands/session.js +0 -160
  301. package/dist/cli/commands/session.js.map +0 -1
  302. package/dist/cli/commands/show.d.ts +0 -13
  303. package/dist/cli/commands/show.d.ts.map +0 -1
  304. package/dist/cli/commands/show.js +0 -20
  305. package/dist/cli/commands/show.js.map +0 -1
  306. package/dist/cli/commands/skills.d.ts +0 -13
  307. package/dist/cli/commands/skills.d.ts.map +0 -1
  308. package/dist/cli/commands/skills.js +0 -131
  309. package/dist/cli/commands/skills.js.map +0 -1
  310. package/dist/cli/commands/snapshot.d.ts +0 -9
  311. package/dist/cli/commands/snapshot.d.ts.map +0 -1
  312. package/dist/cli/commands/snapshot.js +0 -50
  313. package/dist/cli/commands/snapshot.js.map +0 -1
  314. package/dist/cli/commands/specification.d.ts +0 -13
  315. package/dist/cli/commands/specification.d.ts.map +0 -1
  316. package/dist/cli/commands/specification.js +0 -45
  317. package/dist/cli/commands/specification.js.map +0 -1
  318. package/dist/cli/commands/start.d.ts +0 -13
  319. package/dist/cli/commands/start.d.ts.map +0 -1
  320. package/dist/cli/commands/start.js +0 -20
  321. package/dist/cli/commands/start.js.map +0 -1
  322. package/dist/cli/commands/stats.d.ts +0 -12
  323. package/dist/cli/commands/stats.d.ts.map +0 -1
  324. package/dist/cli/commands/stats.js +0 -23
  325. package/dist/cli/commands/stats.js.map +0 -1
  326. package/dist/cli/commands/sticky.d.ts +0 -16
  327. package/dist/cli/commands/sticky.d.ts.map +0 -1
  328. package/dist/cli/commands/sticky.js +0 -211
  329. package/dist/cli/commands/sticky.js.map +0 -1
  330. package/dist/cli/commands/stop.d.ts +0 -13
  331. package/dist/cli/commands/stop.d.ts.map +0 -1
  332. package/dist/cli/commands/stop.js +0 -20
  333. package/dist/cli/commands/stop.js.map +0 -1
  334. package/dist/cli/commands/testing.d.ts +0 -13
  335. package/dist/cli/commands/testing.d.ts.map +0 -1
  336. package/dist/cli/commands/testing.js +0 -64
  337. package/dist/cli/commands/testing.js.map +0 -1
  338. package/dist/cli/commands/token.d.ts +0 -10
  339. package/dist/cli/commands/token.d.ts.map +0 -1
  340. package/dist/cli/commands/token.js +0 -135
  341. package/dist/cli/commands/token.js.map +0 -1
  342. package/dist/cli/commands/update.d.ts +0 -12
  343. package/dist/cli/commands/update.d.ts.map +0 -1
  344. package/dist/cli/commands/update.js +0 -77
  345. package/dist/cli/commands/update.js.map +0 -1
  346. package/dist/cli/commands/upgrade.d.ts +0 -16
  347. package/dist/cli/commands/upgrade.d.ts.map +0 -1
  348. package/dist/cli/commands/upgrade.js +0 -83
  349. package/dist/cli/commands/upgrade.js.map +0 -1
  350. package/dist/cli/commands/validate.d.ts +0 -12
  351. package/dist/cli/commands/validate.d.ts.map +0 -1
  352. package/dist/cli/commands/validate.js +0 -23
  353. package/dist/cli/commands/validate.js.map +0 -1
  354. package/dist/cli/commands/verify.d.ts +0 -8
  355. package/dist/cli/commands/verify.d.ts.map +0 -1
  356. package/dist/cli/commands/verify.js +0 -28
  357. package/dist/cli/commands/verify.js.map +0 -1
  358. package/dist/cli/commands/web.d.ts +0 -13
  359. package/dist/cli/commands/web.d.ts.map +0 -1
  360. package/dist/cli/commands/web.js +0 -264
  361. package/dist/cli/commands/web.js.map +0 -1
  362. package/dist/cli/field-context.d.ts +0 -32
  363. package/dist/cli/field-context.d.ts.map +0 -1
  364. package/dist/cli/field-context.js +0 -47
  365. package/dist/cli/field-context.js.map +0 -1
  366. package/dist/cli/format-context.d.ts +0 -32
  367. package/dist/cli/format-context.d.ts.map +0 -1
  368. package/dist/cli/format-context.js +0 -50
  369. package/dist/cli/format-context.js.map +0 -1
  370. package/dist/cli/index.d.ts +0 -9
  371. package/dist/cli/index.d.ts.map +0 -1
  372. package/dist/cli/logger-bootstrap.d.ts +0 -6
  373. package/dist/cli/logger-bootstrap.d.ts.map +0 -1
  374. package/dist/cli/logger-bootstrap.js +0 -10
  375. package/dist/cli/logger-bootstrap.js.map +0 -1
  376. package/dist/cli/middleware/output-format.d.ts +0 -30
  377. package/dist/cli/middleware/output-format.d.ts.map +0 -1
  378. package/dist/cli/middleware/output-format.js +0 -35
  379. package/dist/cli/middleware/output-format.js.map +0 -1
  380. package/dist/cli/progress.d.ts +0 -84
  381. package/dist/cli/progress.d.ts.map +0 -1
  382. package/dist/cli/progress.js +0 -169
  383. package/dist/cli/progress.js.map +0 -1
  384. package/dist/cli/renderers/colors.d.ts +0 -32
  385. package/dist/cli/renderers/colors.d.ts.map +0 -1
  386. package/dist/cli/renderers/colors.js +0 -141
  387. package/dist/cli/renderers/colors.js.map +0 -1
  388. package/dist/cli/renderers/error.d.ts +0 -13
  389. package/dist/cli/renderers/error.d.ts.map +0 -1
  390. package/dist/cli/renderers/error.js +0 -42
  391. package/dist/cli/renderers/error.js.map +0 -1
  392. package/dist/cli/renderers/index.d.ts +0 -59
  393. package/dist/cli/renderers/index.d.ts.map +0 -1
  394. package/dist/cli/renderers/index.js +0 -184
  395. package/dist/cli/renderers/index.js.map +0 -1
  396. package/dist/cli/renderers/normalizer.d.ts +0 -21
  397. package/dist/cli/renderers/normalizer.d.ts.map +0 -1
  398. package/dist/cli/renderers/normalizer.js +0 -106
  399. package/dist/cli/renderers/normalizer.js.map +0 -1
  400. package/dist/cli/renderers/system.d.ts +0 -25
  401. package/dist/cli/renderers/system.d.ts.map +0 -1
  402. package/dist/cli/renderers/system.js +0 -416
  403. package/dist/cli/renderers/system.js.map +0 -1
  404. package/dist/cli/renderers/tasks.d.ts +0 -28
  405. package/dist/cli/renderers/tasks.d.ts.map +0 -1
  406. package/dist/cli/renderers/tasks.js +0 -306
  407. package/dist/cli/renderers/tasks.js.map +0 -1
  408. package/dist/dispatch/adapters/cli.d.ts +0 -67
  409. package/dist/dispatch/adapters/cli.d.ts.map +0 -1
  410. package/dist/dispatch/adapters/cli.js +0 -205
  411. package/dist/dispatch/adapters/cli.js.map +0 -1
  412. package/dist/dispatch/adapters/mcp.d.ts +0 -37
  413. package/dist/dispatch/adapters/mcp.d.ts.map +0 -1
  414. package/dist/dispatch/adapters/mcp.js +0 -122
  415. package/dist/dispatch/adapters/mcp.js.map +0 -1
  416. package/dist/dispatch/context/session-context.d.ts +0 -54
  417. package/dist/dispatch/context/session-context.d.ts.map +0 -1
  418. package/dist/dispatch/context/session-context.js +0 -61
  419. package/dist/dispatch/context/session-context.js.map +0 -1
  420. package/dist/dispatch/dispatcher.d.ts +0 -23
  421. package/dist/dispatch/dispatcher.d.ts.map +0 -1
  422. package/dist/dispatch/dispatcher.js +0 -84
  423. package/dist/dispatch/dispatcher.js.map +0 -1
  424. package/dist/dispatch/domains/_base.d.ts +0 -59
  425. package/dist/dispatch/domains/_base.d.ts.map +0 -1
  426. package/dist/dispatch/domains/_base.js +0 -77
  427. package/dist/dispatch/domains/_base.js.map +0 -1
  428. package/dist/dispatch/domains/_meta.d.ts +0 -23
  429. package/dist/dispatch/domains/_meta.d.ts.map +0 -1
  430. package/dist/dispatch/domains/_meta.js +0 -25
  431. package/dist/dispatch/domains/_meta.js.map +0 -1
  432. package/dist/dispatch/domains/_routing.d.ts +0 -8
  433. package/dist/dispatch/domains/_routing.d.ts.map +0 -1
  434. package/dist/dispatch/domains/_routing.js +0 -20
  435. package/dist/dispatch/domains/_routing.js.map +0 -1
  436. package/dist/dispatch/domains/admin.d.ts +0 -25
  437. package/dist/dispatch/domains/admin.d.ts.map +0 -1
  438. package/dist/dispatch/domains/admin.js +0 -670
  439. package/dist/dispatch/domains/admin.js.map +0 -1
  440. package/dist/dispatch/domains/check.d.ts +0 -22
  441. package/dist/dispatch/domains/check.d.ts.map +0 -1
  442. package/dist/dispatch/domains/check.js +0 -279
  443. package/dist/dispatch/domains/check.js.map +0 -1
  444. package/dist/dispatch/domains/index.d.ts +0 -26
  445. package/dist/dispatch/domains/index.d.ts.map +0 -1
  446. package/dist/dispatch/domains/index.js +0 -38
  447. package/dist/dispatch/domains/index.js.map +0 -1
  448. package/dist/dispatch/domains/memory.d.ts +0 -22
  449. package/dist/dispatch/domains/memory.d.ts.map +0 -1
  450. package/dist/dispatch/domains/memory.js +0 -303
  451. package/dist/dispatch/domains/memory.js.map +0 -1
  452. package/dist/dispatch/domains/nexus.d.ts +0 -22
  453. package/dist/dispatch/domains/nexus.d.ts.map +0 -1
  454. package/dist/dispatch/domains/nexus.js +0 -286
  455. package/dist/dispatch/domains/nexus.js.map +0 -1
  456. package/dist/dispatch/domains/orchestrate.d.ts +0 -19
  457. package/dist/dispatch/domains/orchestrate.d.ts.map +0 -1
  458. package/dist/dispatch/domains/orchestrate.js +0 -259
  459. package/dist/dispatch/domains/orchestrate.js.map +0 -1
  460. package/dist/dispatch/domains/pipeline.d.ts +0 -35
  461. package/dist/dispatch/domains/pipeline.d.ts.map +0 -1
  462. package/dist/dispatch/domains/pipeline.js +0 -553
  463. package/dist/dispatch/domains/pipeline.js.map +0 -1
  464. package/dist/dispatch/domains/session.d.ts +0 -22
  465. package/dist/dispatch/domains/session.d.ts.map +0 -1
  466. package/dist/dispatch/domains/session.js +0 -255
  467. package/dist/dispatch/domains/session.js.map +0 -1
  468. package/dist/dispatch/domains/sticky.d.ts +0 -20
  469. package/dist/dispatch/domains/sticky.d.ts.map +0 -1
  470. package/dist/dispatch/domains/sticky.js +0 -164
  471. package/dist/dispatch/domains/sticky.js.map +0 -1
  472. package/dist/dispatch/domains/tasks.d.ts +0 -25
  473. package/dist/dispatch/domains/tasks.d.ts.map +0 -1
  474. package/dist/dispatch/domains/tasks.js +0 -323
  475. package/dist/dispatch/domains/tasks.js.map +0 -1
  476. package/dist/dispatch/domains/tools.d.ts +0 -36
  477. package/dist/dispatch/domains/tools.d.ts.map +0 -1
  478. package/dist/dispatch/domains/tools.js +0 -451
  479. package/dist/dispatch/domains/tools.js.map +0 -1
  480. package/dist/dispatch/engines/_error.d.ts +0 -42
  481. package/dist/dispatch/engines/_error.d.ts.map +0 -1
  482. package/dist/dispatch/engines/_error.js +0 -201
  483. package/dist/dispatch/engines/_error.js.map +0 -1
  484. package/dist/dispatch/engines/codebase-map-engine.d.ts +0 -17
  485. package/dist/dispatch/engines/codebase-map-engine.d.ts.map +0 -1
  486. package/dist/dispatch/engines/codebase-map-engine.js +0 -29
  487. package/dist/dispatch/engines/codebase-map-engine.js.map +0 -1
  488. package/dist/dispatch/engines/config-engine.d.ts +0 -21
  489. package/dist/dispatch/engines/config-engine.d.ts.map +0 -1
  490. package/dist/dispatch/engines/config-engine.js +0 -45
  491. package/dist/dispatch/engines/config-engine.js.map +0 -1
  492. package/dist/dispatch/engines/hooks-engine.d.ts +0 -47
  493. package/dist/dispatch/engines/hooks-engine.d.ts.map +0 -1
  494. package/dist/dispatch/engines/hooks-engine.js +0 -57
  495. package/dist/dispatch/engines/hooks-engine.js.map +0 -1
  496. package/dist/dispatch/engines/init-engine.d.ts +0 -43
  497. package/dist/dispatch/engines/init-engine.d.ts.map +0 -1
  498. package/dist/dispatch/engines/init-engine.js +0 -73
  499. package/dist/dispatch/engines/init-engine.js.map +0 -1
  500. package/dist/dispatch/engines/lifecycle-engine.d.ts +0 -66
  501. package/dist/dispatch/engines/lifecycle-engine.d.ts.map +0 -1
  502. package/dist/dispatch/engines/lifecycle-engine.js +0 -213
  503. package/dist/dispatch/engines/lifecycle-engine.js.map +0 -1
  504. package/dist/dispatch/engines/memory-engine.d.ts +0 -10
  505. package/dist/dispatch/engines/memory-engine.d.ts.map +0 -1
  506. package/dist/dispatch/engines/memory-engine.js +0 -10
  507. package/dist/dispatch/engines/memory-engine.js.map +0 -1
  508. package/dist/dispatch/engines/nexus-engine.d.ts +0 -167
  509. package/dist/dispatch/engines/nexus-engine.d.ts.map +0 -1
  510. package/dist/dispatch/engines/nexus-engine.js +0 -356
  511. package/dist/dispatch/engines/nexus-engine.js.map +0 -1
  512. package/dist/dispatch/engines/orchestrate-engine.d.ts +0 -133
  513. package/dist/dispatch/engines/orchestrate-engine.d.ts.map +0 -1
  514. package/dist/dispatch/engines/orchestrate-engine.js +0 -769
  515. package/dist/dispatch/engines/orchestrate-engine.js.map +0 -1
  516. package/dist/dispatch/engines/pipeline-engine.d.ts +0 -51
  517. package/dist/dispatch/engines/pipeline-engine.d.ts.map +0 -1
  518. package/dist/dispatch/engines/pipeline-engine.js +0 -191
  519. package/dist/dispatch/engines/pipeline-engine.js.map +0 -1
  520. package/dist/dispatch/engines/release-engine.d.ts +0 -94
  521. package/dist/dispatch/engines/release-engine.d.ts.map +0 -1
  522. package/dist/dispatch/engines/release-engine.js +0 -669
  523. package/dist/dispatch/engines/release-engine.js.map +0 -1
  524. package/dist/dispatch/engines/session-engine.d.ts +0 -323
  525. package/dist/dispatch/engines/session-engine.d.ts.map +0 -1
  526. package/dist/dispatch/engines/session-engine.js +0 -865
  527. package/dist/dispatch/engines/session-engine.js.map +0 -1
  528. package/dist/dispatch/engines/sticky-engine.d.ts +0 -100
  529. package/dist/dispatch/engines/sticky-engine.d.ts.map +0 -1
  530. package/dist/dispatch/engines/sticky-engine.js +0 -181
  531. package/dist/dispatch/engines/sticky-engine.js.map +0 -1
  532. package/dist/dispatch/engines/system-engine.d.ts +0 -377
  533. package/dist/dispatch/engines/system-engine.d.ts.map +0 -1
  534. package/dist/dispatch/engines/system-engine.js +0 -979
  535. package/dist/dispatch/engines/system-engine.js.map +0 -1
  536. package/dist/dispatch/engines/task-engine.d.ts +0 -612
  537. package/dist/dispatch/engines/task-engine.d.ts.map +0 -1
  538. package/dist/dispatch/engines/task-engine.js +0 -950
  539. package/dist/dispatch/engines/task-engine.js.map +0 -1
  540. package/dist/dispatch/engines/template-parser.d.ts +0 -34
  541. package/dist/dispatch/engines/template-parser.d.ts.map +0 -1
  542. package/dist/dispatch/engines/template-parser.js +0 -57
  543. package/dist/dispatch/engines/template-parser.js.map +0 -1
  544. package/dist/dispatch/engines/tools-engine.d.ts +0 -270
  545. package/dist/dispatch/engines/tools-engine.d.ts.map +0 -1
  546. package/dist/dispatch/engines/tools-engine.js +0 -636
  547. package/dist/dispatch/engines/tools-engine.js.map +0 -1
  548. package/dist/dispatch/engines/validate-engine.d.ts +0 -154
  549. package/dist/dispatch/engines/validate-engine.d.ts.map +0 -1
  550. package/dist/dispatch/engines/validate-engine.js +0 -524
  551. package/dist/dispatch/engines/validate-engine.js.map +0 -1
  552. package/dist/dispatch/index.d.ts +0 -20
  553. package/dist/dispatch/index.d.ts.map +0 -1
  554. package/dist/dispatch/index.js +0 -19
  555. package/dist/dispatch/index.js.map +0 -1
  556. package/dist/dispatch/lib/capability-matrix.d.ts +0 -11
  557. package/dist/dispatch/lib/capability-matrix.d.ts.map +0 -1
  558. package/dist/dispatch/lib/capability-matrix.js +0 -10
  559. package/dist/dispatch/lib/capability-matrix.js.map +0 -1
  560. package/dist/dispatch/lib/config.d.ts +0 -16
  561. package/dist/dispatch/lib/config.d.ts.map +0 -1
  562. package/dist/dispatch/lib/config.js +0 -15
  563. package/dist/dispatch/lib/config.js.map +0 -1
  564. package/dist/dispatch/lib/engine.d.ts +0 -25
  565. package/dist/dispatch/lib/engine.d.ts.map +0 -1
  566. package/dist/dispatch/lib/engine.js +0 -44
  567. package/dist/dispatch/lib/engine.js.map +0 -1
  568. package/dist/dispatch/lib/meta.d.ts +0 -26
  569. package/dist/dispatch/lib/meta.d.ts.map +0 -1
  570. package/dist/dispatch/lib/meta.js +0 -37
  571. package/dist/dispatch/lib/meta.js.map +0 -1
  572. package/dist/dispatch/lib/param-utils.d.ts +0 -11
  573. package/dist/dispatch/lib/param-utils.d.ts.map +0 -1
  574. package/dist/dispatch/lib/param-utils.js +0 -10
  575. package/dist/dispatch/lib/param-utils.js.map +0 -1
  576. package/dist/dispatch/lib/projections.d.ts +0 -23
  577. package/dist/dispatch/lib/projections.d.ts.map +0 -1
  578. package/dist/dispatch/lib/projections.js +0 -48
  579. package/dist/dispatch/lib/projections.js.map +0 -1
  580. package/dist/dispatch/lib/schema-utils.d.ts +0 -42
  581. package/dist/dispatch/lib/schema-utils.d.ts.map +0 -1
  582. package/dist/dispatch/lib/schema-utils.js +0 -93
  583. package/dist/dispatch/lib/schema-utils.js.map +0 -1
  584. package/dist/dispatch/lib/security.d.ts +0 -11
  585. package/dist/dispatch/lib/security.d.ts.map +0 -1
  586. package/dist/dispatch/lib/security.js +0 -10
  587. package/dist/dispatch/lib/security.js.map +0 -1
  588. package/dist/dispatch/middleware/audit.d.ts +0 -23
  589. package/dist/dispatch/middleware/audit.d.ts.map +0 -1
  590. package/dist/dispatch/middleware/audit.js +0 -169
  591. package/dist/dispatch/middleware/audit.js.map +0 -1
  592. package/dist/dispatch/middleware/field-filter.d.ts +0 -24
  593. package/dist/dispatch/middleware/field-filter.d.ts.map +0 -1
  594. package/dist/dispatch/middleware/field-filter.js +0 -65
  595. package/dist/dispatch/middleware/field-filter.js.map +0 -1
  596. package/dist/dispatch/middleware/pipeline.d.ts +0 -20
  597. package/dist/dispatch/middleware/pipeline.d.ts.map +0 -1
  598. package/dist/dispatch/middleware/pipeline.js +0 -47
  599. package/dist/dispatch/middleware/pipeline.js.map +0 -1
  600. package/dist/dispatch/middleware/projection.d.ts +0 -35
  601. package/dist/dispatch/middleware/projection.d.ts.map +0 -1
  602. package/dist/dispatch/middleware/projection.js +0 -145
  603. package/dist/dispatch/middleware/projection.js.map +0 -1
  604. package/dist/dispatch/middleware/protocol-enforcement.d.ts +0 -12
  605. package/dist/dispatch/middleware/protocol-enforcement.d.ts.map +0 -1
  606. package/dist/dispatch/middleware/protocol-enforcement.js +0 -30
  607. package/dist/dispatch/middleware/protocol-enforcement.js.map +0 -1
  608. package/dist/dispatch/middleware/rate-limiter.d.ts +0 -30
  609. package/dist/dispatch/middleware/rate-limiter.d.ts.map +0 -1
  610. package/dist/dispatch/middleware/rate-limiter.js +0 -101
  611. package/dist/dispatch/middleware/rate-limiter.js.map +0 -1
  612. package/dist/dispatch/middleware/sanitizer.d.ts +0 -10
  613. package/dist/dispatch/middleware/sanitizer.d.ts.map +0 -1
  614. package/dist/dispatch/middleware/sanitizer.js +0 -42
  615. package/dist/dispatch/middleware/sanitizer.js.map +0 -1
  616. package/dist/dispatch/middleware/session-resolver.d.ts +0 -26
  617. package/dist/dispatch/middleware/session-resolver.d.ts.map +0 -1
  618. package/dist/dispatch/middleware/session-resolver.js +0 -65
  619. package/dist/dispatch/middleware/session-resolver.js.map +0 -1
  620. package/dist/dispatch/middleware/verification-gates.d.ts +0 -3
  621. package/dist/dispatch/middleware/verification-gates.d.ts.map +0 -1
  622. package/dist/dispatch/middleware/verification-gates.js +0 -40
  623. package/dist/dispatch/middleware/verification-gates.js.map +0 -1
  624. package/dist/dispatch/registry.d.ts +0 -91
  625. package/dist/dispatch/registry.d.ts.map +0 -1
  626. package/dist/dispatch/registry.js +0 -2833
  627. package/dist/dispatch/registry.js.map +0 -1
  628. package/dist/dispatch/types.d.ts +0 -218
  629. package/dist/dispatch/types.d.ts.map +0 -1
  630. package/dist/dispatch/types.js +0 -25
  631. package/dist/dispatch/types.js.map +0 -1
  632. package/dist/mcp/gateways/mutate.d.ts +0 -146
  633. package/dist/mcp/gateways/mutate.d.ts.map +0 -1
  634. package/dist/mcp/gateways/mutate.js +0 -1016
  635. package/dist/mcp/gateways/mutate.js.map +0 -1
  636. package/dist/mcp/gateways/query.d.ts +0 -138
  637. package/dist/mcp/gateways/query.d.ts.map +0 -1
  638. package/dist/mcp/gateways/query.js +0 -186
  639. package/dist/mcp/gateways/query.js.map +0 -1
  640. package/dist/mcp/index.d.ts +0 -16
  641. package/dist/mcp/index.d.ts.map +0 -1
  642. package/dist/mcp/lib/background-jobs.d.ts +0 -86
  643. package/dist/mcp/lib/background-jobs.d.ts.map +0 -1
  644. package/dist/mcp/lib/background-jobs.js +0 -183
  645. package/dist/mcp/lib/background-jobs.js.map +0 -1
  646. package/dist/mcp/lib/budget.d.ts +0 -35
  647. package/dist/mcp/lib/budget.d.ts.map +0 -1
  648. package/dist/mcp/lib/budget.js +0 -102
  649. package/dist/mcp/lib/budget.js.map +0 -1
  650. package/dist/mcp/lib/cache.d.ts +0 -78
  651. package/dist/mcp/lib/cache.d.ts.map +0 -1
  652. package/dist/mcp/lib/cache.js +0 -207
  653. package/dist/mcp/lib/cache.js.map +0 -1
  654. package/dist/mcp/lib/config.d.ts +0 -42
  655. package/dist/mcp/lib/config.d.ts.map +0 -1
  656. package/dist/mcp/lib/config.js +0 -241
  657. package/dist/mcp/lib/config.js.map +0 -1
  658. package/dist/mcp/lib/defaults.d.ts +0 -115
  659. package/dist/mcp/lib/defaults.d.ts.map +0 -1
  660. package/dist/mcp/lib/defaults.js +0 -61
  661. package/dist/mcp/lib/defaults.js.map +0 -1
  662. package/dist/mcp/lib/gate-validators.d.ts +0 -13
  663. package/dist/mcp/lib/gate-validators.d.ts.map +0 -1
  664. package/dist/mcp/lib/gate-validators.js +0 -13
  665. package/dist/mcp/lib/gate-validators.js.map +0 -1
  666. package/dist/mcp/lib/gateway-meta.d.ts +0 -37
  667. package/dist/mcp/lib/gateway-meta.d.ts.map +0 -1
  668. package/dist/mcp/lib/gateway-meta.js +0 -50
  669. package/dist/mcp/lib/gateway-meta.js.map +0 -1
  670. package/dist/mcp/lib/job-manager-accessor.d.ts +0 -10
  671. package/dist/mcp/lib/job-manager-accessor.d.ts.map +0 -1
  672. package/dist/mcp/lib/job-manager-accessor.js +0 -14
  673. package/dist/mcp/lib/job-manager-accessor.js.map +0 -1
  674. package/dist/mcp/lib/protocol-enforcement.d.ts +0 -12
  675. package/dist/mcp/lib/protocol-enforcement.d.ts.map +0 -1
  676. package/dist/mcp/lib/protocol-enforcement.js +0 -12
  677. package/dist/mcp/lib/protocol-enforcement.js.map +0 -1
  678. package/dist/mcp/lib/protocol-rules.d.ts +0 -12
  679. package/dist/mcp/lib/protocol-rules.d.ts.map +0 -1
  680. package/dist/mcp/lib/protocol-rules.js +0 -12
  681. package/dist/mcp/lib/protocol-rules.js.map +0 -1
  682. package/dist/mcp/lib/rate-limiter.d.ts +0 -110
  683. package/dist/mcp/lib/rate-limiter.d.ts.map +0 -1
  684. package/dist/mcp/lib/rate-limiter.js +0 -208
  685. package/dist/mcp/lib/rate-limiter.js.map +0 -1
  686. package/dist/mcp/lib/router.d.ts +0 -58
  687. package/dist/mcp/lib/router.d.ts.map +0 -1
  688. package/dist/mcp/lib/router.js +0 -12
  689. package/dist/mcp/lib/router.js.map +0 -1
  690. package/dist/mcp/lib/security.d.ts +0 -161
  691. package/dist/mcp/lib/security.d.ts.map +0 -1
  692. package/dist/mcp/lib/security.js +0 -360
  693. package/dist/mcp/lib/security.js.map +0 -1
  694. package/dist/mcp/lib/verification-gates.d.ts +0 -13
  695. package/dist/mcp/lib/verification-gates.d.ts.map +0 -1
  696. package/dist/mcp/lib/verification-gates.js +0 -12
  697. package/dist/mcp/lib/verification-gates.js.map +0 -1
  698. package/dist/mcp/resources/budget.d.ts +0 -22
  699. package/dist/mcp/resources/budget.d.ts.map +0 -1
  700. package/dist/mcp/resources/budget.js +0 -46
  701. package/dist/mcp/resources/budget.js.map +0 -1
  702. package/dist/mcp/resources/index.d.ts +0 -53
  703. package/dist/mcp/resources/index.d.ts.map +0 -1
  704. package/dist/mcp/resources/index.js +0 -278
  705. package/dist/mcp/resources/index.js.map +0 -1
package/dist/mcp/index.js CHANGED
@@ -13163,9 +13163,9 @@ async function readSequenceFromDb(cwd, accessor) {
13163
13163
  return isValidSequenceState(value) ? value : null;
13164
13164
  }
13165
13165
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
13166
- const { eq: eq16 } = await import("drizzle-orm");
13166
+ const { eq: eq17 } = await import("drizzle-orm");
13167
13167
  const db = await getDb4(cwd);
13168
- const rows = await db.select().from(schemaMeta).where(eq16(schemaMeta.key, SEQUENCE_META_KEY)).all();
13168
+ const rows = await db.select().from(schemaMeta).where(eq17(schemaMeta.key, SEQUENCE_META_KEY)).all();
13169
13169
  const raw = rows[0]?.value;
13170
13170
  if (!raw) return null;
13171
13171
  try {
@@ -15276,7 +15276,7 @@ async function linkPipelineAdr(projectRoot, taskId) {
15276
15276
  return result;
15277
15277
  }
15278
15278
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
15279
- const { and: and11, eq: eq16 } = await import("drizzle-orm");
15279
+ const { and: and12, eq: eq17 } = await import("drizzle-orm");
15280
15280
  const db = await getDb4(projectRoot);
15281
15281
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
15282
15282
  for (const filePath of matchingFiles) {
@@ -15286,7 +15286,7 @@ async function linkPipelineAdr(projectRoot, taskId) {
15286
15286
  const fm = record2.frontmatter;
15287
15287
  const content = readFileSync5(filePath, "utf-8");
15288
15288
  const relativePath = `.cleo/adrs/${filename}`;
15289
- const existing = await db.select({ id: architectureDecisions.id }).from(architectureDecisions).where(eq16(architectureDecisions.id, record2.id)).all();
15289
+ const existing = await db.select({ id: architectureDecisions.id }).from(architectureDecisions).where(eq17(architectureDecisions.id, record2.id)).all();
15290
15290
  const rowBase = {
15291
15291
  id: record2.id,
15292
15292
  title: record2.title,
@@ -15306,19 +15306,19 @@ async function linkPipelineAdr(projectRoot, taskId) {
15306
15306
  updatedAt: now2
15307
15307
  };
15308
15308
  if (existing.length > 0) {
15309
- await db.update(architectureDecisions).set(rowBase).where(eq16(architectureDecisions.id, record2.id));
15309
+ await db.update(architectureDecisions).set(rowBase).where(eq17(architectureDecisions.id, record2.id));
15310
15310
  } else {
15311
15311
  await db.insert(architectureDecisions).values({ ...rowBase, createdAt: now2 });
15312
15312
  }
15313
15313
  result.synced++;
15314
- await db.delete(adrTaskLinks).where(and11(eq16(adrTaskLinks.adrId, record2.id), eq16(adrTaskLinks.taskId, taskId)));
15314
+ await db.delete(adrTaskLinks).where(and12(eq17(adrTaskLinks.adrId, record2.id), eq17(adrTaskLinks.taskId, taskId)));
15315
15315
  await db.insert(adrTaskLinks).values({ adrId: record2.id, taskId, linkType: "implements" });
15316
15316
  result.linked.push({ adrId: record2.id, taskId });
15317
15317
  if (fm["Related ADRs"]) {
15318
15318
  const relatedIds = fm["Related ADRs"].split(",").map((r) => r.trim()).filter((r) => /^ADR-\d+$/.test(r));
15319
15319
  for (const toId of relatedIds) {
15320
15320
  try {
15321
- const targetExists = await db.select({ id: architectureDecisions.id }).from(architectureDecisions).where(eq16(architectureDecisions.id, toId)).all();
15321
+ const targetExists = await db.select({ id: architectureDecisions.id }).from(architectureDecisions).where(eq17(architectureDecisions.id, toId)).all();
15322
15322
  if (targetExists.length > 0) {
15323
15323
  await db.insert(adrRelations).values({ fromAdrId: record2.id, toAdrId: toId, relationType: "related" }).onConflictDoNothing();
15324
15324
  }
@@ -15479,7 +15479,7 @@ async function syncAdrsToDb(projectRoot) {
15479
15479
  return result;
15480
15480
  }
15481
15481
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
15482
- const { eq: eq16 } = await import("drizzle-orm");
15482
+ const { eq: eq17 } = await import("drizzle-orm");
15483
15483
  const db = await getDb4(projectRoot);
15484
15484
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
15485
15485
  const allFiles = collectAdrFiles(adrsDir);
@@ -15513,15 +15513,15 @@ async function syncAdrsToDb(projectRoot) {
15513
15513
  topics: fm.Topics ?? null,
15514
15514
  updatedAt: now2
15515
15515
  };
15516
- const existing = await db.select({ id: architectureDecisions.id }).from(architectureDecisions).where(eq16(architectureDecisions.id, record2.id)).all();
15516
+ const existing = await db.select({ id: architectureDecisions.id }).from(architectureDecisions).where(eq17(architectureDecisions.id, record2.id)).all();
15517
15517
  if (existing.length > 0) {
15518
- await db.update(architectureDecisions).set(rowBase).where(eq16(architectureDecisions.id, record2.id));
15518
+ await db.update(architectureDecisions).set(rowBase).where(eq17(architectureDecisions.id, record2.id));
15519
15519
  result.updated++;
15520
15520
  } else {
15521
15521
  await db.insert(architectureDecisions).values({ ...rowBase, createdAt: now2 });
15522
15522
  result.inserted++;
15523
15523
  }
15524
- await db.delete(adrTaskLinks).where(eq16(adrTaskLinks.adrId, record2.id));
15524
+ await db.delete(adrTaskLinks).where(eq17(adrTaskLinks.adrId, record2.id));
15525
15525
  if (fm["Related Tasks"]) {
15526
15526
  for (const taskId of parseTaskIds2(fm["Related Tasks"])) {
15527
15527
  await db.insert(adrTaskLinks).values({ adrId: record2.id, taskId, linkType: "related" });
@@ -15657,310 +15657,8 @@ var init_adrs = __esm({
15657
15657
  }
15658
15658
  });
15659
15659
 
15660
- // packages/core/src/agents/registry.ts
15661
- var registry_exports2 = {};
15662
- __export(registry_exports2, {
15663
- checkAgentHealth: () => checkAgentHealth,
15664
- classifyError: () => classifyError,
15665
- deregisterAgent: () => deregisterAgent,
15666
- generateAgentId: () => generateAgentId,
15667
- getAgentErrorHistory: () => getAgentErrorHistory,
15668
- getAgentInstance: () => getAgentInstance,
15669
- getHealthReport: () => getHealthReport,
15670
- heartbeat: () => heartbeat,
15671
- incrementTasksCompleted: () => incrementTasksCompleted,
15672
- listAgentInstances: () => listAgentInstances,
15673
- markCrashed: () => markCrashed,
15674
- registerAgent: () => registerAgent,
15675
- updateAgentStatus: () => updateAgentStatus
15676
- });
15677
- import { randomBytes } from "node:crypto";
15678
- import { and as and3, eq as eq5, inArray as inArray4, lt as lt2, sql as sql8 } from "drizzle-orm";
15679
- function generateAgentId() {
15680
- const now2 = /* @__PURE__ */ new Date();
15681
- const ts = now2.toISOString().replace(/[-:T]/g, "").substring(0, 14);
15682
- const hex = randomBytes(3).toString("hex");
15683
- return `agt_${ts}_${hex}`;
15684
- }
15685
- async function registerAgent(opts, cwd) {
15686
- const db = await getDb(cwd);
15687
- const id = generateAgentId();
15688
- const now2 = (/* @__PURE__ */ new Date()).toISOString();
15689
- const row = {
15690
- id,
15691
- agentType: opts.agentType,
15692
- status: "starting",
15693
- sessionId: opts.sessionId ?? null,
15694
- taskId: opts.taskId ?? null,
15695
- startedAt: now2,
15696
- lastHeartbeat: now2,
15697
- stoppedAt: null,
15698
- errorCount: 0,
15699
- totalTasksCompleted: 0,
15700
- capacity: "1.0",
15701
- metadataJson: opts.metadata ? JSON.stringify(opts.metadata) : "{}",
15702
- parentAgentId: opts.parentAgentId ?? null
15703
- };
15704
- await db.insert(agentInstances).values(row);
15705
- return row;
15706
- }
15707
- async function deregisterAgent(id, cwd) {
15708
- const db = await getDb(cwd);
15709
- const now2 = (/* @__PURE__ */ new Date()).toISOString();
15710
- const existing = await db.select().from(agentInstances).where(eq5(agentInstances.id, id)).get();
15711
- if (!existing) return null;
15712
- if (existing.status === "stopped") return existing;
15713
- await db.update(agentInstances).set({ status: "stopped", stoppedAt: now2 }).where(eq5(agentInstances.id, id));
15714
- return { ...existing, status: "stopped", stoppedAt: now2 };
15715
- }
15716
- async function heartbeat(id, cwd) {
15717
- const db = await getDb(cwd);
15718
- const now2 = (/* @__PURE__ */ new Date()).toISOString();
15719
- const existing = await db.select().from(agentInstances).where(eq5(agentInstances.id, id)).get();
15720
- if (!existing) return null;
15721
- if (existing.status === "stopped" || existing.status === "crashed") {
15722
- return existing.status;
15723
- }
15724
- await db.update(agentInstances).set({ lastHeartbeat: now2 }).where(eq5(agentInstances.id, id));
15725
- return existing.status;
15726
- }
15727
- async function updateAgentStatus(id, opts, cwd) {
15728
- const db = await getDb(cwd);
15729
- const existing = await db.select().from(agentInstances).where(eq5(agentInstances.id, id)).get();
15730
- if (!existing) return null;
15731
- const updates = {
15732
- status: opts.status
15733
- };
15734
- if (opts.taskId !== void 0) {
15735
- updates.taskId = opts.taskId;
15736
- }
15737
- if (opts.status === "active") {
15738
- updates.lastHeartbeat = (/* @__PURE__ */ new Date()).toISOString();
15739
- }
15740
- if (opts.status === "error" || opts.status === "crashed") {
15741
- updates.errorCount = existing.errorCount + 1;
15742
- if (opts.error) {
15743
- const errorType = classifyError(new Error(opts.error));
15744
- await db.insert(agentErrorLog).values({
15745
- agentId: id,
15746
- errorType,
15747
- message: opts.error,
15748
- occurredAt: (/* @__PURE__ */ new Date()).toISOString()
15749
- });
15750
- }
15751
- }
15752
- if (opts.status === "stopped") {
15753
- updates.stoppedAt = (/* @__PURE__ */ new Date()).toISOString();
15754
- }
15755
- await db.update(agentInstances).set(updates).where(eq5(agentInstances.id, id));
15756
- return { ...existing, ...updates };
15757
- }
15758
- async function incrementTasksCompleted(id, cwd) {
15759
- const db = await getDb(cwd);
15760
- await db.update(agentInstances).set({ totalTasksCompleted: sql8`${agentInstances.totalTasksCompleted} + 1` }).where(eq5(agentInstances.id, id));
15761
- }
15762
- async function listAgentInstances(filters, cwd) {
15763
- const db = await getDb(cwd);
15764
- const conditions = [];
15765
- if (filters?.status) {
15766
- const statuses = Array.isArray(filters.status) ? filters.status : [filters.status];
15767
- conditions.push(inArray4(agentInstances.status, statuses));
15768
- }
15769
- if (filters?.agentType) {
15770
- const types = Array.isArray(filters.agentType) ? filters.agentType : [filters.agentType];
15771
- conditions.push(inArray4(agentInstances.agentType, types));
15772
- }
15773
- if (filters?.sessionId) {
15774
- conditions.push(eq5(agentInstances.sessionId, filters.sessionId));
15775
- }
15776
- if (filters?.parentAgentId) {
15777
- conditions.push(eq5(agentInstances.parentAgentId, filters.parentAgentId));
15778
- }
15779
- if (conditions.length === 0) {
15780
- return db.select().from(agentInstances).all();
15781
- }
15782
- return db.select().from(agentInstances).where(and3(...conditions)).all();
15783
- }
15784
- async function getAgentInstance(id, cwd) {
15785
- const db = await getDb(cwd);
15786
- const row = await db.select().from(agentInstances).where(eq5(agentInstances.id, id)).get();
15787
- return row ?? null;
15788
- }
15789
- function classifyError(error40) {
15790
- const message = error40 instanceof Error ? error40.message : String(error40);
15791
- for (const pattern of RETRIABLE_PATTERNS) {
15792
- if (pattern.test(message)) return "retriable";
15793
- }
15794
- for (const pattern of PERMANENT_PATTERNS) {
15795
- if (pattern.test(message)) return "permanent";
15796
- }
15797
- return "unknown";
15798
- }
15799
- async function getAgentErrorHistory(agentId, cwd) {
15800
- const db = await getDb(cwd);
15801
- return db.select().from(agentErrorLog).where(eq5(agentErrorLog.agentId, agentId)).all();
15802
- }
15803
- async function checkAgentHealth(thresholdMs = 3e4, cwd) {
15804
- const db = await getDb(cwd);
15805
- const cutoff = new Date(Date.now() - thresholdMs).toISOString();
15806
- return db.select().from(agentInstances).where(
15807
- and3(
15808
- inArray4(agentInstances.status, ["active", "idle", "starting"]),
15809
- lt2(agentInstances.lastHeartbeat, cutoff)
15810
- )
15811
- ).all();
15812
- }
15813
- async function markCrashed(id, reason, cwd) {
15814
- return updateAgentStatus(
15815
- id,
15816
- { status: "crashed", error: reason ?? "Heartbeat timeout \u2014 agent presumed crashed" },
15817
- cwd
15818
- );
15819
- }
15820
- async function getHealthReport(thresholdMs = 3e4, cwd) {
15821
- const allAgents = await listAgentInstances(void 0, cwd);
15822
- const staleAgents = await checkAgentHealth(thresholdMs, cwd);
15823
- const report = {
15824
- total: allAgents.length,
15825
- active: 0,
15826
- idle: 0,
15827
- starting: 0,
15828
- error: 0,
15829
- crashed: 0,
15830
- stopped: 0,
15831
- totalErrors: 0,
15832
- staleAgents
15833
- };
15834
- for (const agent of allAgents) {
15835
- switch (agent.status) {
15836
- case "active":
15837
- report.active++;
15838
- break;
15839
- case "idle":
15840
- report.idle++;
15841
- break;
15842
- case "starting":
15843
- report.starting++;
15844
- break;
15845
- case "error":
15846
- report.error++;
15847
- break;
15848
- case "crashed":
15849
- report.crashed++;
15850
- break;
15851
- case "stopped":
15852
- report.stopped++;
15853
- break;
15854
- }
15855
- report.totalErrors += agent.errorCount;
15856
- }
15857
- return report;
15858
- }
15859
- var RETRIABLE_PATTERNS, PERMANENT_PATTERNS;
15860
- var init_registry2 = __esm({
15861
- "packages/core/src/agents/registry.ts"() {
15862
- "use strict";
15863
- init_sqlite2();
15864
- init_agent_schema();
15865
- RETRIABLE_PATTERNS = [
15866
- /timeout/i,
15867
- /ECONNREFUSED/,
15868
- /ECONNRESET/,
15869
- /EPIPE/,
15870
- /ETIMEDOUT/,
15871
- /rate.?limit/i,
15872
- /429/,
15873
- /503/,
15874
- /502/,
15875
- /SQLITE_BUSY/i,
15876
- /database is locked/i,
15877
- /temporarily unavailable/i,
15878
- /too many requests/i,
15879
- /network/i,
15880
- /socket hang up/i
15881
- ];
15882
- PERMANENT_PATTERNS = [
15883
- /permission denied/i,
15884
- /EACCES/,
15885
- /authentication/i,
15886
- /unauthorized/i,
15887
- /401/,
15888
- /403/,
15889
- /404/,
15890
- /not found/i,
15891
- /invalid.*token/i,
15892
- /SQLITE_CONSTRAINT/i,
15893
- /syntax error/i,
15894
- /type error/i,
15895
- /reference error/i
15896
- ];
15897
- }
15898
- });
15899
-
15900
- // packages/core/src/agents/capacity.ts
15901
- import { eq as eq6 } from "drizzle-orm";
15902
- async function updateCapacity(id, capacity, cwd) {
15903
- if (capacity < 0 || capacity > 1) {
15904
- throw new Error(`Capacity must be between 0.0 and 1.0, got ${capacity}`);
15905
- }
15906
- const db = await getDb(cwd);
15907
- const existing = await db.select().from(agentInstances).where(eq6(agentInstances.id, id)).get();
15908
- if (!existing) return null;
15909
- const capacityStr = capacity.toFixed(4);
15910
- await db.update(agentInstances).set({ capacity: capacityStr }).where(eq6(agentInstances.id, id));
15911
- return { ...existing, capacity: capacityStr };
15912
- }
15913
- async function getAvailableCapacity(cwd) {
15914
- const agents = await listAgentInstances({ status: ["active", "idle"] }, cwd);
15915
- return agents.reduce((sum, agent) => sum + parseCapacity(agent.capacity), 0);
15916
- }
15917
- async function findLeastLoadedAgent(agentType, cwd) {
15918
- const filters = agentType ? { status: ["active", "idle"], agentType } : { status: ["active", "idle"] };
15919
- const agents = await listAgentInstances(filters, cwd);
15920
- if (agents.length === 0) return null;
15921
- let best = agents[0];
15922
- let bestCapacity = parseCapacity(best.capacity);
15923
- for (let i = 1; i < agents.length; i++) {
15924
- const cap = parseCapacity(agents[i].capacity);
15925
- if (cap > bestCapacity) {
15926
- best = agents[i];
15927
- bestCapacity = cap;
15928
- }
15929
- }
15930
- return best;
15931
- }
15932
- async function isOverloaded(threshold = 0.1, cwd) {
15933
- const capacity = await getAvailableCapacity(cwd);
15934
- return capacity < threshold;
15935
- }
15936
- async function getCapacitySummary(threshold = 0.1, cwd) {
15937
- const agents = await listAgentInstances({ status: ["active", "idle"] }, cwd);
15938
- const totalCapacity = agents.reduce((sum, a) => sum + parseCapacity(a.capacity), 0);
15939
- const activeAgentCount = agents.length;
15940
- return {
15941
- totalCapacity,
15942
- activeAgentCount,
15943
- averageCapacity: activeAgentCount > 0 ? totalCapacity / activeAgentCount : 0,
15944
- overloaded: totalCapacity < threshold,
15945
- threshold
15946
- };
15947
- }
15948
- function parseCapacity(value) {
15949
- if (!value) return 0;
15950
- const parsed = parseFloat(value);
15951
- return Number.isNaN(parsed) ? 0 : Math.max(0, Math.min(1, parsed));
15952
- }
15953
- var init_capacity = __esm({
15954
- "packages/core/src/agents/capacity.ts"() {
15955
- "use strict";
15956
- init_sqlite2();
15957
- init_agent_schema();
15958
- init_registry2();
15959
- }
15960
- });
15961
-
15962
15660
  // packages/core/src/store/brain-accessor.ts
15963
- import { and as and4, asc as asc2, desc as desc2, eq as eq7, gte as gte2, or as or3 } from "drizzle-orm";
15661
+ import { and as and3, asc as asc2, desc as desc2, eq as eq5, gte as gte2, or as or3 } from "drizzle-orm";
15964
15662
  async function getBrainAccessor(cwd) {
15965
15663
  const db = await getBrainDb(cwd);
15966
15664
  return new BrainDataAccessor(db);
@@ -15980,30 +15678,30 @@ var init_brain_accessor = __esm({
15980
15678
  // =========================================================================
15981
15679
  async addDecision(row) {
15982
15680
  await this.db.insert(brainDecisions).values(row);
15983
- const result = await this.db.select().from(brainDecisions).where(eq7(brainDecisions.id, row.id));
15681
+ const result = await this.db.select().from(brainDecisions).where(eq5(brainDecisions.id, row.id));
15984
15682
  return result[0];
15985
15683
  }
15986
15684
  async getDecision(id) {
15987
- const result = await this.db.select().from(brainDecisions).where(eq7(brainDecisions.id, id));
15685
+ const result = await this.db.select().from(brainDecisions).where(eq5(brainDecisions.id, id));
15988
15686
  return result[0] ?? null;
15989
15687
  }
15990
15688
  async findDecisions(params = {}) {
15991
15689
  const conditions = [];
15992
15690
  if (params.type) {
15993
- conditions.push(eq7(brainDecisions.type, params.type));
15691
+ conditions.push(eq5(brainDecisions.type, params.type));
15994
15692
  }
15995
15693
  if (params.confidence) {
15996
- conditions.push(eq7(brainDecisions.confidence, params.confidence));
15694
+ conditions.push(eq5(brainDecisions.confidence, params.confidence));
15997
15695
  }
15998
15696
  if (params.outcome) {
15999
- conditions.push(eq7(brainDecisions.outcome, params.outcome));
15697
+ conditions.push(eq5(brainDecisions.outcome, params.outcome));
16000
15698
  }
16001
15699
  if (params.contextTaskId) {
16002
- conditions.push(eq7(brainDecisions.contextTaskId, params.contextTaskId));
15700
+ conditions.push(eq5(brainDecisions.contextTaskId, params.contextTaskId));
16003
15701
  }
16004
15702
  let query = this.db.select().from(brainDecisions).orderBy(desc2(brainDecisions.createdAt));
16005
15703
  if (conditions.length > 0) {
16006
- query = query.where(and4(...conditions));
15704
+ query = query.where(and3(...conditions));
16007
15705
  }
16008
15706
  if (params.limit) {
16009
15707
  query = query.limit(params.limit);
@@ -16011,34 +15709,34 @@ var init_brain_accessor = __esm({
16011
15709
  return query;
16012
15710
  }
16013
15711
  async updateDecision(id, updates) {
16014
- await this.db.update(brainDecisions).set({ ...updates, updatedAt: (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, 19) }).where(eq7(brainDecisions.id, id));
15712
+ await this.db.update(brainDecisions).set({ ...updates, updatedAt: (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, 19) }).where(eq5(brainDecisions.id, id));
16015
15713
  }
16016
15714
  // =========================================================================
16017
15715
  // Patterns CRUD
16018
15716
  // =========================================================================
16019
15717
  async addPattern(row) {
16020
15718
  await this.db.insert(brainPatterns).values(row);
16021
- const result = await this.db.select().from(brainPatterns).where(eq7(brainPatterns.id, row.id));
15719
+ const result = await this.db.select().from(brainPatterns).where(eq5(brainPatterns.id, row.id));
16022
15720
  return result[0];
16023
15721
  }
16024
15722
  async getPattern(id) {
16025
- const result = await this.db.select().from(brainPatterns).where(eq7(brainPatterns.id, id));
15723
+ const result = await this.db.select().from(brainPatterns).where(eq5(brainPatterns.id, id));
16026
15724
  return result[0] ?? null;
16027
15725
  }
16028
15726
  async findPatterns(params = {}) {
16029
15727
  const conditions = [];
16030
15728
  if (params.type) {
16031
- conditions.push(eq7(brainPatterns.type, params.type));
15729
+ conditions.push(eq5(brainPatterns.type, params.type));
16032
15730
  }
16033
15731
  if (params.impact) {
16034
- conditions.push(eq7(brainPatterns.impact, params.impact));
15732
+ conditions.push(eq5(brainPatterns.impact, params.impact));
16035
15733
  }
16036
15734
  if (params.minFrequency !== void 0) {
16037
15735
  conditions.push(gte2(brainPatterns.frequency, params.minFrequency));
16038
15736
  }
16039
15737
  let query = this.db.select().from(brainPatterns).orderBy(desc2(brainPatterns.frequency));
16040
15738
  if (conditions.length > 0) {
16041
- query = query.where(and4(...conditions));
15739
+ query = query.where(and3(...conditions));
16042
15740
  }
16043
15741
  if (params.limit) {
16044
15742
  query = query.limit(params.limit);
@@ -16046,18 +15744,18 @@ var init_brain_accessor = __esm({
16046
15744
  return query;
16047
15745
  }
16048
15746
  async updatePattern(id, updates) {
16049
- await this.db.update(brainPatterns).set({ ...updates, updatedAt: (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, 19) }).where(eq7(brainPatterns.id, id));
15747
+ await this.db.update(brainPatterns).set({ ...updates, updatedAt: (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, 19) }).where(eq5(brainPatterns.id, id));
16050
15748
  }
16051
15749
  // =========================================================================
16052
15750
  // Learnings CRUD
16053
15751
  // =========================================================================
16054
15752
  async addLearning(row) {
16055
15753
  await this.db.insert(brainLearnings).values(row);
16056
- const result = await this.db.select().from(brainLearnings).where(eq7(brainLearnings.id, row.id));
15754
+ const result = await this.db.select().from(brainLearnings).where(eq5(brainLearnings.id, row.id));
16057
15755
  return result[0];
16058
15756
  }
16059
15757
  async getLearning(id) {
16060
- const result = await this.db.select().from(brainLearnings).where(eq7(brainLearnings.id, id));
15758
+ const result = await this.db.select().from(brainLearnings).where(eq5(brainLearnings.id, id));
16061
15759
  return result[0] ?? null;
16062
15760
  }
16063
15761
  async findLearnings(params = {}) {
@@ -16066,11 +15764,11 @@ var init_brain_accessor = __esm({
16066
15764
  conditions.push(gte2(brainLearnings.confidence, params.minConfidence));
16067
15765
  }
16068
15766
  if (params.actionable !== void 0) {
16069
- conditions.push(eq7(brainLearnings.actionable, params.actionable));
15767
+ conditions.push(eq5(brainLearnings.actionable, params.actionable));
16070
15768
  }
16071
15769
  let query = this.db.select().from(brainLearnings).orderBy(desc2(brainLearnings.confidence));
16072
15770
  if (conditions.length > 0) {
16073
- query = query.where(and4(...conditions));
15771
+ query = query.where(and3(...conditions));
16074
15772
  }
16075
15773
  if (params.limit) {
16076
15774
  query = query.limit(params.limit);
@@ -16078,37 +15776,37 @@ var init_brain_accessor = __esm({
16078
15776
  return query;
16079
15777
  }
16080
15778
  async updateLearning(id, updates) {
16081
- await this.db.update(brainLearnings).set({ ...updates, updatedAt: (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, 19) }).where(eq7(brainLearnings.id, id));
15779
+ await this.db.update(brainLearnings).set({ ...updates, updatedAt: (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, 19) }).where(eq5(brainLearnings.id, id));
16082
15780
  }
16083
15781
  // =========================================================================
16084
15782
  // Observations CRUD
16085
15783
  // =========================================================================
16086
15784
  async addObservation(row) {
16087
15785
  await this.db.insert(brainObservations).values(row);
16088
- const result = await this.db.select().from(brainObservations).where(eq7(brainObservations.id, row.id));
15786
+ const result = await this.db.select().from(brainObservations).where(eq5(brainObservations.id, row.id));
16089
15787
  return result[0];
16090
15788
  }
16091
15789
  async getObservation(id) {
16092
- const result = await this.db.select().from(brainObservations).where(eq7(brainObservations.id, id));
15790
+ const result = await this.db.select().from(brainObservations).where(eq5(brainObservations.id, id));
16093
15791
  return result[0] ?? null;
16094
15792
  }
16095
15793
  async findObservations(params = {}) {
16096
15794
  const conditions = [];
16097
15795
  if (params.type) {
16098
- conditions.push(eq7(brainObservations.type, params.type));
15796
+ conditions.push(eq5(brainObservations.type, params.type));
16099
15797
  }
16100
15798
  if (params.project) {
16101
- conditions.push(eq7(brainObservations.project, params.project));
15799
+ conditions.push(eq5(brainObservations.project, params.project));
16102
15800
  }
16103
15801
  if (params.sourceType) {
16104
- conditions.push(eq7(brainObservations.sourceType, params.sourceType));
15802
+ conditions.push(eq5(brainObservations.sourceType, params.sourceType));
16105
15803
  }
16106
15804
  if (params.sourceSessionId) {
16107
- conditions.push(eq7(brainObservations.sourceSessionId, params.sourceSessionId));
15805
+ conditions.push(eq5(brainObservations.sourceSessionId, params.sourceSessionId));
16108
15806
  }
16109
15807
  let query = this.db.select().from(brainObservations).orderBy(desc2(brainObservations.createdAt));
16110
15808
  if (conditions.length > 0) {
16111
- query = query.where(and4(...conditions));
15809
+ query = query.where(and3(...conditions));
16112
15810
  }
16113
15811
  if (params.limit) {
16114
15812
  query = query.limit(params.limit);
@@ -16116,7 +15814,7 @@ var init_brain_accessor = __esm({
16116
15814
  return query;
16117
15815
  }
16118
15816
  async updateObservation(id, updates) {
16119
- await this.db.update(brainObservations).set({ ...updates, updatedAt: (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, 19) }).where(eq7(brainObservations.id, id));
15817
+ await this.db.update(brainObservations).set({ ...updates, updatedAt: (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, 19) }).where(eq5(brainObservations.id, id));
16120
15818
  }
16121
15819
  // =========================================================================
16122
15820
  // Memory Links CRUD
@@ -16126,22 +15824,22 @@ var init_brain_accessor = __esm({
16126
15824
  }
16127
15825
  async getLinksForMemory(memoryType, memoryId) {
16128
15826
  return this.db.select().from(brainMemoryLinks).where(
16129
- and4(
16130
- eq7(brainMemoryLinks.memoryType, memoryType),
16131
- eq7(brainMemoryLinks.memoryId, memoryId)
15827
+ and3(
15828
+ eq5(brainMemoryLinks.memoryType, memoryType),
15829
+ eq5(brainMemoryLinks.memoryId, memoryId)
16132
15830
  )
16133
15831
  ).orderBy(asc2(brainMemoryLinks.createdAt));
16134
15832
  }
16135
15833
  async getLinksForTask(taskId) {
16136
- return this.db.select().from(brainMemoryLinks).where(eq7(brainMemoryLinks.taskId, taskId)).orderBy(asc2(brainMemoryLinks.createdAt));
15834
+ return this.db.select().from(brainMemoryLinks).where(eq5(brainMemoryLinks.taskId, taskId)).orderBy(asc2(brainMemoryLinks.createdAt));
16137
15835
  }
16138
15836
  async removeLink(memoryType, memoryId, taskId, linkType) {
16139
15837
  await this.db.delete(brainMemoryLinks).where(
16140
- and4(
16141
- eq7(brainMemoryLinks.memoryType, memoryType),
16142
- eq7(brainMemoryLinks.memoryId, memoryId),
16143
- eq7(brainMemoryLinks.taskId, taskId),
16144
- eq7(brainMemoryLinks.linkType, linkType)
15838
+ and3(
15839
+ eq5(brainMemoryLinks.memoryType, memoryType),
15840
+ eq5(brainMemoryLinks.memoryId, memoryId),
15841
+ eq5(brainMemoryLinks.taskId, taskId),
15842
+ eq5(brainMemoryLinks.linkType, linkType)
16145
15843
  )
16146
15844
  );
16147
15845
  }
@@ -16150,27 +15848,27 @@ var init_brain_accessor = __esm({
16150
15848
  // =========================================================================
16151
15849
  async addStickyNote(row) {
16152
15850
  await this.db.insert(brainStickyNotes).values(row);
16153
- const result = await this.db.select().from(brainStickyNotes).where(eq7(brainStickyNotes.id, row.id));
15851
+ const result = await this.db.select().from(brainStickyNotes).where(eq5(brainStickyNotes.id, row.id));
16154
15852
  return result[0];
16155
15853
  }
16156
15854
  async getStickyNote(id) {
16157
- const result = await this.db.select().from(brainStickyNotes).where(eq7(brainStickyNotes.id, id));
15855
+ const result = await this.db.select().from(brainStickyNotes).where(eq5(brainStickyNotes.id, id));
16158
15856
  return result[0] ?? null;
16159
15857
  }
16160
15858
  async findStickyNotes(params = {}) {
16161
15859
  const conditions = [];
16162
15860
  if (params.status) {
16163
- conditions.push(eq7(brainStickyNotes.status, params.status));
15861
+ conditions.push(eq5(brainStickyNotes.status, params.status));
16164
15862
  }
16165
15863
  if (params.color) {
16166
- conditions.push(eq7(brainStickyNotes.color, params.color));
15864
+ conditions.push(eq5(brainStickyNotes.color, params.color));
16167
15865
  }
16168
15866
  if (params.priority) {
16169
- conditions.push(eq7(brainStickyNotes.priority, params.priority));
15867
+ conditions.push(eq5(brainStickyNotes.priority, params.priority));
16170
15868
  }
16171
15869
  let query = this.db.select().from(brainStickyNotes).orderBy(desc2(brainStickyNotes.createdAt));
16172
15870
  if (conditions.length > 0) {
16173
- query = query.where(and4(...conditions));
15871
+ query = query.where(and3(...conditions));
16174
15872
  }
16175
15873
  if (params.limit) {
16176
15874
  query = query.limit(params.limit);
@@ -16178,31 +15876,31 @@ var init_brain_accessor = __esm({
16178
15876
  return query;
16179
15877
  }
16180
15878
  async updateStickyNote(id, updates) {
16181
- await this.db.update(brainStickyNotes).set({ ...updates, updatedAt: (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, 19) }).where(eq7(brainStickyNotes.id, id));
15879
+ await this.db.update(brainStickyNotes).set({ ...updates, updatedAt: (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, 19) }).where(eq5(brainStickyNotes.id, id));
16182
15880
  }
16183
15881
  async deleteStickyNote(id) {
16184
- await this.db.delete(brainStickyNotes).where(eq7(brainStickyNotes.id, id));
15882
+ await this.db.delete(brainStickyNotes).where(eq5(brainStickyNotes.id, id));
16185
15883
  }
16186
15884
  // =========================================================================
16187
15885
  // PageIndex Node CRUD (T5383)
16188
15886
  // =========================================================================
16189
15887
  async addPageNode(node) {
16190
15888
  await this.db.insert(brainPageNodes).values(node);
16191
- const result = await this.db.select().from(brainPageNodes).where(eq7(brainPageNodes.id, node.id));
15889
+ const result = await this.db.select().from(brainPageNodes).where(eq5(brainPageNodes.id, node.id));
16192
15890
  return result[0];
16193
15891
  }
16194
15892
  async getPageNode(id) {
16195
- const result = await this.db.select().from(brainPageNodes).where(eq7(brainPageNodes.id, id));
15893
+ const result = await this.db.select().from(brainPageNodes).where(eq5(brainPageNodes.id, id));
16196
15894
  return result[0] ?? null;
16197
15895
  }
16198
15896
  async findPageNodes(params = {}) {
16199
15897
  const conditions = [];
16200
15898
  if (params.nodeType) {
16201
- conditions.push(eq7(brainPageNodes.nodeType, params.nodeType));
15899
+ conditions.push(eq5(brainPageNodes.nodeType, params.nodeType));
16202
15900
  }
16203
15901
  let query = this.db.select().from(brainPageNodes).orderBy(desc2(brainPageNodes.createdAt));
16204
15902
  if (conditions.length > 0) {
16205
- query = query.where(and4(...conditions));
15903
+ query = query.where(and3(...conditions));
16206
15904
  }
16207
15905
  if (params.limit) {
16208
15906
  query = query.limit(params.limit);
@@ -16211,9 +15909,9 @@ var init_brain_accessor = __esm({
16211
15909
  }
16212
15910
  async removePageNode(id) {
16213
15911
  await this.db.delete(brainPageEdges).where(
16214
- or3(eq7(brainPageEdges.fromId, id), eq7(brainPageEdges.toId, id))
15912
+ or3(eq5(brainPageEdges.fromId, id), eq5(brainPageEdges.toId, id))
16215
15913
  );
16216
- await this.db.delete(brainPageNodes).where(eq7(brainPageNodes.id, id));
15914
+ await this.db.delete(brainPageNodes).where(eq5(brainPageNodes.id, id));
16217
15915
  }
16218
15916
  // =========================================================================
16219
15917
  // PageIndex Edge CRUD (T5383)
@@ -16221,34 +15919,34 @@ var init_brain_accessor = __esm({
16221
15919
  async addPageEdge(edge) {
16222
15920
  await this.db.insert(brainPageEdges).values(edge);
16223
15921
  const result = await this.db.select().from(brainPageEdges).where(
16224
- and4(
16225
- eq7(brainPageEdges.fromId, edge.fromId),
16226
- eq7(brainPageEdges.toId, edge.toId),
16227
- eq7(brainPageEdges.edgeType, edge.edgeType)
15922
+ and3(
15923
+ eq5(brainPageEdges.fromId, edge.fromId),
15924
+ eq5(brainPageEdges.toId, edge.toId),
15925
+ eq5(brainPageEdges.edgeType, edge.edgeType)
16228
15926
  )
16229
15927
  );
16230
15928
  return result[0];
16231
15929
  }
16232
15930
  async getPageEdges(nodeId, direction = "both") {
16233
15931
  if (direction === "out") {
16234
- return this.db.select().from(brainPageEdges).where(eq7(brainPageEdges.fromId, nodeId)).orderBy(asc2(brainPageEdges.createdAt));
15932
+ return this.db.select().from(brainPageEdges).where(eq5(brainPageEdges.fromId, nodeId)).orderBy(asc2(brainPageEdges.createdAt));
16235
15933
  }
16236
15934
  if (direction === "in") {
16237
- return this.db.select().from(brainPageEdges).where(eq7(brainPageEdges.toId, nodeId)).orderBy(asc2(brainPageEdges.createdAt));
15935
+ return this.db.select().from(brainPageEdges).where(eq5(brainPageEdges.toId, nodeId)).orderBy(asc2(brainPageEdges.createdAt));
16238
15936
  }
16239
15937
  return this.db.select().from(brainPageEdges).where(
16240
15938
  or3(
16241
- eq7(brainPageEdges.fromId, nodeId),
16242
- eq7(brainPageEdges.toId, nodeId)
15939
+ eq5(brainPageEdges.fromId, nodeId),
15940
+ eq5(brainPageEdges.toId, nodeId)
16243
15941
  )
16244
15942
  ).orderBy(asc2(brainPageEdges.createdAt));
16245
15943
  }
16246
15944
  async getNeighbors(nodeId, edgeType) {
16247
- const conditions = [eq7(brainPageEdges.fromId, nodeId)];
15945
+ const conditions = [eq5(brainPageEdges.fromId, nodeId)];
16248
15946
  if (edgeType) {
16249
- conditions.push(eq7(brainPageEdges.edgeType, edgeType));
15947
+ conditions.push(eq5(brainPageEdges.edgeType, edgeType));
16250
15948
  }
16251
- const edges = await this.db.select().from(brainPageEdges).where(and4(...conditions));
15949
+ const edges = await this.db.select().from(brainPageEdges).where(and3(...conditions));
16252
15950
  if (edges.length === 0) return [];
16253
15951
  const neighborIds = edges.map((e) => e.toId);
16254
15952
  const nodes = [];
@@ -16260,10 +15958,10 @@ var init_brain_accessor = __esm({
16260
15958
  }
16261
15959
  async removePageEdge(fromId, toId, edgeType) {
16262
15960
  await this.db.delete(brainPageEdges).where(
16263
- and4(
16264
- eq7(brainPageEdges.fromId, fromId),
16265
- eq7(brainPageEdges.toId, toId),
16266
- eq7(brainPageEdges.edgeType, edgeType)
15961
+ and3(
15962
+ eq5(brainPageEdges.fromId, fromId),
15963
+ eq5(brainPageEdges.toId, toId),
15964
+ eq5(brainPageEdges.edgeType, edgeType)
16267
15965
  )
16268
15966
  );
16269
15967
  }
@@ -16272,15 +15970,15 @@ var init_brain_accessor = __esm({
16272
15970
  });
16273
15971
 
16274
15972
  // packages/core/src/agents/execution-learning.ts
16275
- import { randomBytes as randomBytes2 } from "node:crypto";
15973
+ import { randomBytes } from "node:crypto";
16276
15974
  function generateDecisionId() {
16277
- return `AGT-${randomBytes2(5).toString("hex")}`;
15975
+ return `AGT-${randomBytes(5).toString("hex")}`;
16278
15976
  }
16279
15977
  function generatePatternId() {
16280
- return `P-agt-${randomBytes2(4).toString("hex")}`;
15978
+ return `P-agt-${randomBytes(4).toString("hex")}`;
16281
15979
  }
16282
15980
  function generateObservationId() {
16283
- return `O-agt-${randomBytes2(4).toString("hex")}`;
15981
+ return `O-agt-${randomBytes(4).toString("hex")}`;
16284
15982
  }
16285
15983
  function nowSql() {
16286
15984
  return (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, 19);
@@ -16563,6 +16261,473 @@ var init_execution_learning = __esm({
16563
16261
  }
16564
16262
  });
16565
16263
 
16264
+ // packages/core/src/agents/registry.ts
16265
+ var registry_exports2 = {};
16266
+ __export(registry_exports2, {
16267
+ checkAgentHealth: () => checkAgentHealth,
16268
+ classifyError: () => classifyError,
16269
+ deregisterAgent: () => deregisterAgent,
16270
+ generateAgentId: () => generateAgentId,
16271
+ getAgentErrorHistory: () => getAgentErrorHistory,
16272
+ getAgentInstance: () => getAgentInstance,
16273
+ getHealthReport: () => getHealthReport,
16274
+ heartbeat: () => heartbeat,
16275
+ incrementTasksCompleted: () => incrementTasksCompleted,
16276
+ listAgentInstances: () => listAgentInstances,
16277
+ markCrashed: () => markCrashed,
16278
+ registerAgent: () => registerAgent,
16279
+ updateAgentStatus: () => updateAgentStatus
16280
+ });
16281
+ import { randomBytes as randomBytes2 } from "node:crypto";
16282
+ import { and as and4, eq as eq6, inArray as inArray4, lt as lt2, sql as sql8 } from "drizzle-orm";
16283
+ function generateAgentId() {
16284
+ const now2 = /* @__PURE__ */ new Date();
16285
+ const ts = now2.toISOString().replace(/[-:T]/g, "").substring(0, 14);
16286
+ const hex = randomBytes2(3).toString("hex");
16287
+ return `agt_${ts}_${hex}`;
16288
+ }
16289
+ async function registerAgent(opts, cwd) {
16290
+ const db = await getDb(cwd);
16291
+ const id = generateAgentId();
16292
+ const now2 = (/* @__PURE__ */ new Date()).toISOString();
16293
+ const row = {
16294
+ id,
16295
+ agentType: opts.agentType,
16296
+ status: "starting",
16297
+ sessionId: opts.sessionId ?? null,
16298
+ taskId: opts.taskId ?? null,
16299
+ startedAt: now2,
16300
+ lastHeartbeat: now2,
16301
+ stoppedAt: null,
16302
+ errorCount: 0,
16303
+ totalTasksCompleted: 0,
16304
+ capacity: "1.0",
16305
+ metadataJson: opts.metadata ? JSON.stringify(opts.metadata) : "{}",
16306
+ parentAgentId: opts.parentAgentId ?? null
16307
+ };
16308
+ await db.insert(agentInstances).values(row);
16309
+ return row;
16310
+ }
16311
+ async function deregisterAgent(id, cwd) {
16312
+ const db = await getDb(cwd);
16313
+ const now2 = (/* @__PURE__ */ new Date()).toISOString();
16314
+ const existing = await db.select().from(agentInstances).where(eq6(agentInstances.id, id)).get();
16315
+ if (!existing) return null;
16316
+ if (existing.status === "stopped") return existing;
16317
+ await db.update(agentInstances).set({ status: "stopped", stoppedAt: now2 }).where(eq6(agentInstances.id, id));
16318
+ return { ...existing, status: "stopped", stoppedAt: now2 };
16319
+ }
16320
+ async function heartbeat(id, cwd) {
16321
+ const db = await getDb(cwd);
16322
+ const now2 = (/* @__PURE__ */ new Date()).toISOString();
16323
+ const existing = await db.select().from(agentInstances).where(eq6(agentInstances.id, id)).get();
16324
+ if (!existing) return null;
16325
+ if (existing.status === "stopped" || existing.status === "crashed") {
16326
+ return existing.status;
16327
+ }
16328
+ await db.update(agentInstances).set({ lastHeartbeat: now2 }).where(eq6(agentInstances.id, id));
16329
+ return existing.status;
16330
+ }
16331
+ async function updateAgentStatus(id, opts, cwd) {
16332
+ const db = await getDb(cwd);
16333
+ const existing = await db.select().from(agentInstances).where(eq6(agentInstances.id, id)).get();
16334
+ if (!existing) return null;
16335
+ const updates = {
16336
+ status: opts.status
16337
+ };
16338
+ if (opts.taskId !== void 0) {
16339
+ updates.taskId = opts.taskId;
16340
+ }
16341
+ if (opts.status === "active") {
16342
+ updates.lastHeartbeat = (/* @__PURE__ */ new Date()).toISOString();
16343
+ }
16344
+ if (opts.status === "error" || opts.status === "crashed") {
16345
+ updates.errorCount = existing.errorCount + 1;
16346
+ if (opts.error) {
16347
+ const errorType = classifyError(new Error(opts.error));
16348
+ await db.insert(agentErrorLog).values({
16349
+ agentId: id,
16350
+ errorType,
16351
+ message: opts.error,
16352
+ occurredAt: (/* @__PURE__ */ new Date()).toISOString()
16353
+ });
16354
+ }
16355
+ }
16356
+ if (opts.status === "stopped") {
16357
+ updates.stoppedAt = (/* @__PURE__ */ new Date()).toISOString();
16358
+ }
16359
+ await db.update(agentInstances).set(updates).where(eq6(agentInstances.id, id));
16360
+ return { ...existing, ...updates };
16361
+ }
16362
+ async function incrementTasksCompleted(id, cwd) {
16363
+ const db = await getDb(cwd);
16364
+ await db.update(agentInstances).set({ totalTasksCompleted: sql8`${agentInstances.totalTasksCompleted} + 1` }).where(eq6(agentInstances.id, id));
16365
+ }
16366
+ async function listAgentInstances(filters, cwd) {
16367
+ const db = await getDb(cwd);
16368
+ const conditions = [];
16369
+ if (filters?.status) {
16370
+ const statuses = Array.isArray(filters.status) ? filters.status : [filters.status];
16371
+ conditions.push(inArray4(agentInstances.status, statuses));
16372
+ }
16373
+ if (filters?.agentType) {
16374
+ const types = Array.isArray(filters.agentType) ? filters.agentType : [filters.agentType];
16375
+ conditions.push(inArray4(agentInstances.agentType, types));
16376
+ }
16377
+ if (filters?.sessionId) {
16378
+ conditions.push(eq6(agentInstances.sessionId, filters.sessionId));
16379
+ }
16380
+ if (filters?.parentAgentId) {
16381
+ conditions.push(eq6(agentInstances.parentAgentId, filters.parentAgentId));
16382
+ }
16383
+ if (conditions.length === 0) {
16384
+ return db.select().from(agentInstances).all();
16385
+ }
16386
+ return db.select().from(agentInstances).where(and4(...conditions)).all();
16387
+ }
16388
+ async function getAgentInstance(id, cwd) {
16389
+ const db = await getDb(cwd);
16390
+ const row = await db.select().from(agentInstances).where(eq6(agentInstances.id, id)).get();
16391
+ return row ?? null;
16392
+ }
16393
+ function classifyError(error40) {
16394
+ const message = error40 instanceof Error ? error40.message : String(error40);
16395
+ for (const pattern of RETRIABLE_PATTERNS) {
16396
+ if (pattern.test(message)) return "retriable";
16397
+ }
16398
+ for (const pattern of PERMANENT_PATTERNS) {
16399
+ if (pattern.test(message)) return "permanent";
16400
+ }
16401
+ return "unknown";
16402
+ }
16403
+ async function getAgentErrorHistory(agentId, cwd) {
16404
+ const db = await getDb(cwd);
16405
+ return db.select().from(agentErrorLog).where(eq6(agentErrorLog.agentId, agentId)).all();
16406
+ }
16407
+ async function checkAgentHealth(thresholdMs = 3e4, cwd) {
16408
+ const db = await getDb(cwd);
16409
+ const cutoff = new Date(Date.now() - thresholdMs).toISOString();
16410
+ return db.select().from(agentInstances).where(
16411
+ and4(
16412
+ inArray4(agentInstances.status, ["active", "idle", "starting"]),
16413
+ lt2(agentInstances.lastHeartbeat, cutoff)
16414
+ )
16415
+ ).all();
16416
+ }
16417
+ async function markCrashed(id, reason, cwd) {
16418
+ return updateAgentStatus(
16419
+ id,
16420
+ { status: "crashed", error: reason ?? "Heartbeat timeout \u2014 agent presumed crashed" },
16421
+ cwd
16422
+ );
16423
+ }
16424
+ async function getHealthReport(thresholdMs = 3e4, cwd) {
16425
+ const allAgents = await listAgentInstances(void 0, cwd);
16426
+ const staleAgents = await checkAgentHealth(thresholdMs, cwd);
16427
+ const report = {
16428
+ total: allAgents.length,
16429
+ active: 0,
16430
+ idle: 0,
16431
+ starting: 0,
16432
+ error: 0,
16433
+ crashed: 0,
16434
+ stopped: 0,
16435
+ totalErrors: 0,
16436
+ staleAgents
16437
+ };
16438
+ for (const agent of allAgents) {
16439
+ switch (agent.status) {
16440
+ case "active":
16441
+ report.active++;
16442
+ break;
16443
+ case "idle":
16444
+ report.idle++;
16445
+ break;
16446
+ case "starting":
16447
+ report.starting++;
16448
+ break;
16449
+ case "error":
16450
+ report.error++;
16451
+ break;
16452
+ case "crashed":
16453
+ report.crashed++;
16454
+ break;
16455
+ case "stopped":
16456
+ report.stopped++;
16457
+ break;
16458
+ }
16459
+ report.totalErrors += agent.errorCount;
16460
+ }
16461
+ return report;
16462
+ }
16463
+ var RETRIABLE_PATTERNS, PERMANENT_PATTERNS;
16464
+ var init_registry2 = __esm({
16465
+ "packages/core/src/agents/registry.ts"() {
16466
+ "use strict";
16467
+ init_sqlite2();
16468
+ init_agent_schema();
16469
+ RETRIABLE_PATTERNS = [
16470
+ /timeout/i,
16471
+ /ECONNREFUSED/,
16472
+ /ECONNRESET/,
16473
+ /EPIPE/,
16474
+ /ETIMEDOUT/,
16475
+ /rate.?limit/i,
16476
+ /429/,
16477
+ /503/,
16478
+ /502/,
16479
+ /SQLITE_BUSY/i,
16480
+ /database is locked/i,
16481
+ /temporarily unavailable/i,
16482
+ /too many requests/i,
16483
+ /network/i,
16484
+ /socket hang up/i
16485
+ ];
16486
+ PERMANENT_PATTERNS = [
16487
+ /permission denied/i,
16488
+ /EACCES/,
16489
+ /authentication/i,
16490
+ /unauthorized/i,
16491
+ /401/,
16492
+ /403/,
16493
+ /404/,
16494
+ /not found/i,
16495
+ /invalid.*token/i,
16496
+ /SQLITE_CONSTRAINT/i,
16497
+ /syntax error/i,
16498
+ /type error/i,
16499
+ /reference error/i
16500
+ ];
16501
+ }
16502
+ });
16503
+
16504
+ // packages/core/src/agents/agent-registry.ts
16505
+ import { and as and5, eq as eq7, inArray as inArray5 } from "drizzle-orm";
16506
+ async function getAgentCapacity(agentId, cwd) {
16507
+ const db = await getDb(cwd);
16508
+ const agent = await db.select().from(agentInstances).where(eq7(agentInstances.id, agentId)).get();
16509
+ if (!agent) return null;
16510
+ const isTerminal2 = agent.status === "stopped" || agent.status === "crashed";
16511
+ if (isTerminal2) {
16512
+ return {
16513
+ agentId: agent.id,
16514
+ agentType: agent.agentType,
16515
+ status: agent.status,
16516
+ activeTasks: 0,
16517
+ remainingCapacity: 0,
16518
+ maxCapacity: MAX_TASKS_PER_AGENT,
16519
+ available: false
16520
+ };
16521
+ }
16522
+ const children = await db.select({ id: agentInstances.id }).from(agentInstances).where(
16523
+ and5(
16524
+ eq7(agentInstances.parentAgentId, agentId),
16525
+ inArray5(agentInstances.status, ["starting", "active", "idle", "error"])
16526
+ )
16527
+ ).all();
16528
+ const selfTask = agent.taskId != null ? 1 : 0;
16529
+ const activeTasks = selfTask + children.length;
16530
+ const remainingCapacity = Math.max(0, MAX_TASKS_PER_AGENT - activeTasks);
16531
+ return {
16532
+ agentId: agent.id,
16533
+ agentType: agent.agentType,
16534
+ status: agent.status,
16535
+ activeTasks,
16536
+ remainingCapacity,
16537
+ maxCapacity: MAX_TASKS_PER_AGENT,
16538
+ available: remainingCapacity > 0
16539
+ };
16540
+ }
16541
+ async function getAgentsByCapacity(agentType, cwd) {
16542
+ const filters = agentType ? { status: ["active", "idle"], agentType } : { status: ["active", "idle"] };
16543
+ const activeAgents = await listAgentInstances(filters, cwd);
16544
+ const capacities = await Promise.all(
16545
+ activeAgents.map((agent) => getAgentCapacity(agent.id, cwd))
16546
+ );
16547
+ return capacities.filter((c) => c !== null).sort((a, b) => b.remainingCapacity - a.remainingCapacity);
16548
+ }
16549
+ async function getAgentSpecializations(agentId, cwd) {
16550
+ const db = await getDb(cwd);
16551
+ const agent = await db.select({ metadataJson: agentInstances.metadataJson }).from(agentInstances).where(eq7(agentInstances.id, agentId)).get();
16552
+ if (!agent) return [];
16553
+ try {
16554
+ const meta = JSON.parse(agent.metadataJson ?? "{}");
16555
+ const specs = meta.specializations;
16556
+ if (!Array.isArray(specs)) return [];
16557
+ return specs.filter((s) => typeof s === "string");
16558
+ } catch {
16559
+ return [];
16560
+ }
16561
+ }
16562
+ async function updateAgentSpecializations(agentId, specializations, cwd) {
16563
+ const db = await getDb(cwd);
16564
+ const agent = await db.select({ metadataJson: agentInstances.metadataJson }).from(agentInstances).where(eq7(agentInstances.id, agentId)).get();
16565
+ if (!agent) return null;
16566
+ let existing = {};
16567
+ try {
16568
+ existing = JSON.parse(agent.metadataJson ?? "{}");
16569
+ } catch {
16570
+ }
16571
+ const updated = { ...existing, specializations };
16572
+ await db.update(agentInstances).set({ metadataJson: JSON.stringify(updated) }).where(eq7(agentInstances.id, agentId));
16573
+ return specializations;
16574
+ }
16575
+ async function recordAgentPerformance(agentId, metrics, cwd) {
16576
+ const db = await getDb(cwd);
16577
+ const agent = await db.select({ agentType: agentInstances.agentType, sessionId: agentInstances.sessionId }).from(agentInstances).where(eq7(agentInstances.id, agentId)).get();
16578
+ if (!agent) return null;
16579
+ const event = {
16580
+ agentId,
16581
+ agentType: agent.agentType,
16582
+ taskId: metrics.taskId,
16583
+ taskType: metrics.taskType,
16584
+ outcome: metrics.outcome,
16585
+ taskLabels: metrics.taskLabels,
16586
+ sessionId: metrics.sessionId ?? agent.sessionId ?? void 0,
16587
+ durationMs: metrics.durationMs,
16588
+ errorMessage: metrics.errorMessage,
16589
+ errorType: metrics.errorType
16590
+ };
16591
+ const decision = await recordAgentExecution(event, cwd);
16592
+ return decision?.id ?? null;
16593
+ }
16594
+ var MAX_TASKS_PER_AGENT;
16595
+ var init_agent_registry = __esm({
16596
+ "packages/core/src/agents/agent-registry.ts"() {
16597
+ "use strict";
16598
+ init_sqlite2();
16599
+ init_agent_schema();
16600
+ init_execution_learning();
16601
+ init_registry2();
16602
+ MAX_TASKS_PER_AGENT = 5;
16603
+ }
16604
+ });
16605
+
16606
+ // packages/core/src/agents/capacity.ts
16607
+ import { eq as eq8 } from "drizzle-orm";
16608
+ async function updateCapacity(id, capacity, cwd) {
16609
+ if (capacity < 0 || capacity > 1) {
16610
+ throw new Error(`Capacity must be between 0.0 and 1.0, got ${capacity}`);
16611
+ }
16612
+ const db = await getDb(cwd);
16613
+ const existing = await db.select().from(agentInstances).where(eq8(agentInstances.id, id)).get();
16614
+ if (!existing) return null;
16615
+ const capacityStr = capacity.toFixed(4);
16616
+ await db.update(agentInstances).set({ capacity: capacityStr }).where(eq8(agentInstances.id, id));
16617
+ return { ...existing, capacity: capacityStr };
16618
+ }
16619
+ async function getAvailableCapacity(cwd) {
16620
+ const agents = await listAgentInstances({ status: ["active", "idle"] }, cwd);
16621
+ return agents.reduce((sum, agent) => sum + parseCapacity(agent.capacity), 0);
16622
+ }
16623
+ async function findLeastLoadedAgent(agentType, cwd) {
16624
+ const filters = agentType ? { status: ["active", "idle"], agentType } : { status: ["active", "idle"] };
16625
+ const agents = await listAgentInstances(filters, cwd);
16626
+ if (agents.length === 0) return null;
16627
+ let best = agents[0];
16628
+ let bestCapacity = parseCapacity(best.capacity);
16629
+ for (let i = 1; i < agents.length; i++) {
16630
+ const cap = parseCapacity(agents[i].capacity);
16631
+ if (cap > bestCapacity) {
16632
+ best = agents[i];
16633
+ bestCapacity = cap;
16634
+ }
16635
+ }
16636
+ return best;
16637
+ }
16638
+ async function isOverloaded(threshold = 0.1, cwd) {
16639
+ const capacity = await getAvailableCapacity(cwd);
16640
+ return capacity < threshold;
16641
+ }
16642
+ async function getCapacitySummary(threshold = 0.1, cwd) {
16643
+ const agents = await listAgentInstances({ status: ["active", "idle"] }, cwd);
16644
+ const totalCapacity = agents.reduce((sum, a) => sum + parseCapacity(a.capacity), 0);
16645
+ const activeAgentCount = agents.length;
16646
+ return {
16647
+ totalCapacity,
16648
+ activeAgentCount,
16649
+ averageCapacity: activeAgentCount > 0 ? totalCapacity / activeAgentCount : 0,
16650
+ overloaded: totalCapacity < threshold,
16651
+ threshold
16652
+ };
16653
+ }
16654
+ function parseCapacity(value) {
16655
+ if (!value) return 0;
16656
+ const parsed = parseFloat(value);
16657
+ return Number.isNaN(parsed) ? 0 : Math.max(0, Math.min(1, parsed));
16658
+ }
16659
+ var init_capacity = __esm({
16660
+ "packages/core/src/agents/capacity.ts"() {
16661
+ "use strict";
16662
+ init_sqlite2();
16663
+ init_agent_schema();
16664
+ init_registry2();
16665
+ }
16666
+ });
16667
+
16668
+ // packages/core/src/agents/health-monitor.ts
16669
+ async function recordHeartbeat(agentId, cwd) {
16670
+ return heartbeat(agentId, cwd);
16671
+ }
16672
+ async function checkAgentHealth2(agentId, thresholdMs = STALE_THRESHOLD_MS, cwd) {
16673
+ const all = await listAgentInstances(void 0, cwd);
16674
+ const agent = all.find((a) => a.id === agentId);
16675
+ if (!agent) return null;
16676
+ return buildHealthStatus(agent, thresholdMs);
16677
+ }
16678
+ async function detectStaleAgents(thresholdMs = STALE_THRESHOLD_MS, cwd) {
16679
+ const agents = await listAgentInstances({ status: ALIVE_STATUSES }, cwd);
16680
+ return agents.map((a) => buildHealthStatus(a, thresholdMs)).filter((s) => s.stale).sort((a, b) => b.heartbeatAgeMs - a.heartbeatAgeMs);
16681
+ }
16682
+ async function detectCrashedAgents(thresholdMs = STALE_THRESHOLD_MS, cwd) {
16683
+ const activeAgents = await listAgentInstances({ status: "active" }, cwd);
16684
+ const cutoff = new Date(Date.now() - thresholdMs).toISOString();
16685
+ const crashed = [];
16686
+ for (const agent of activeAgents) {
16687
+ if (agent.lastHeartbeat < cutoff) {
16688
+ const updated = await markCrashed(
16689
+ agent.id,
16690
+ `Heartbeat timeout \u2014 no heartbeat for >${Math.round(thresholdMs / 1e3)}s`,
16691
+ cwd
16692
+ );
16693
+ if (updated) {
16694
+ crashed.push(updated);
16695
+ }
16696
+ }
16697
+ }
16698
+ crashed.sort((a, b) => {
16699
+ const aHb = a.lastHeartbeat ?? "";
16700
+ const bHb = b.lastHeartbeat ?? "";
16701
+ return aHb < bHb ? -1 : aHb > bHb ? 1 : 0;
16702
+ });
16703
+ return crashed;
16704
+ }
16705
+ function buildHealthStatus(agent, thresholdMs) {
16706
+ const lastHeartbeatMs = new Date(agent.lastHeartbeat).getTime();
16707
+ const heartbeatAgeMs = Date.now() - lastHeartbeatMs;
16708
+ const stale = ALIVE_STATUSES.includes(agent.status) ? heartbeatAgeMs > thresholdMs : false;
16709
+ const healthy = !stale && ALIVE_STATUSES.includes(agent.status);
16710
+ return {
16711
+ agentId: agent.id,
16712
+ status: agent.status,
16713
+ lastHeartbeat: agent.lastHeartbeat,
16714
+ heartbeatAgeMs,
16715
+ healthy,
16716
+ stale,
16717
+ thresholdMs
16718
+ };
16719
+ }
16720
+ var HEARTBEAT_INTERVAL_MS, STALE_THRESHOLD_MS, ALIVE_STATUSES;
16721
+ var init_health_monitor = __esm({
16722
+ "packages/core/src/agents/health-monitor.ts"() {
16723
+ "use strict";
16724
+ init_registry2();
16725
+ HEARTBEAT_INTERVAL_MS = 3e4;
16726
+ STALE_THRESHOLD_MS = 3 * 6e4;
16727
+ ALIVE_STATUSES = ["starting", "active", "idle"];
16728
+ }
16729
+ });
16730
+
16566
16731
  // packages/core/src/agents/retry.ts
16567
16732
  function createRetryPolicy(overrides) {
16568
16733
  return { ...DEFAULT_RETRY_POLICY, ...overrides };
@@ -16689,18 +16854,27 @@ __export(agents_exports, {
16689
16854
  AGENT_INSTANCE_STATUSES: () => AGENT_INSTANCE_STATUSES,
16690
16855
  AGENT_TYPES: () => AGENT_TYPES,
16691
16856
  DEFAULT_RETRY_POLICY: () => DEFAULT_RETRY_POLICY,
16857
+ HEARTBEAT_INTERVAL_MS: () => HEARTBEAT_INTERVAL_MS,
16858
+ MAX_TASKS_PER_AGENT: () => MAX_TASKS_PER_AGENT,
16859
+ STALE_THRESHOLD_MS: () => STALE_THRESHOLD_MS,
16692
16860
  agentErrorLog: () => agentErrorLog,
16693
16861
  agentInstances: () => agentInstances,
16694
16862
  calculateDelay: () => calculateDelay,
16695
- checkAgentHealth: () => checkAgentHealth,
16863
+ checkAgentHealth: () => checkAgentHealth2,
16696
16864
  classifyError: () => classifyError,
16697
16865
  createRetryPolicy: () => createRetryPolicy,
16698
16866
  deregisterAgent: () => deregisterAgent,
16867
+ detectCrashedAgents: () => detectCrashedAgents,
16868
+ detectStaleAgents: () => detectStaleAgents,
16699
16869
  findLeastLoadedAgent: () => findLeastLoadedAgent,
16870
+ findStaleAgentRows: () => checkAgentHealth,
16700
16871
  generateAgentId: () => generateAgentId,
16872
+ getAgentCapacity: () => getAgentCapacity,
16701
16873
  getAgentErrorHistory: () => getAgentErrorHistory,
16702
16874
  getAgentInstance: () => getAgentInstance,
16703
16875
  getAgentPerformanceHistory: () => getAgentPerformanceHistory,
16876
+ getAgentSpecializations: () => getAgentSpecializations,
16877
+ getAgentsByCapacity: () => getAgentsByCapacity,
16704
16878
  getAvailableCapacity: () => getAvailableCapacity,
16705
16879
  getCapacitySummary: () => getCapacitySummary,
16706
16880
  getHealthReport: () => getHealthReport,
@@ -16712,11 +16886,14 @@ __export(agents_exports, {
16712
16886
  markCrashed: () => markCrashed,
16713
16887
  processAgentLifecycleEvent: () => processAgentLifecycleEvent,
16714
16888
  recordAgentExecution: () => recordAgentExecution,
16889
+ recordAgentPerformance: () => recordAgentPerformance,
16715
16890
  recordFailurePattern: () => recordFailurePattern,
16891
+ recordHeartbeat: () => recordHeartbeat,
16716
16892
  recoverCrashedAgents: () => recoverCrashedAgents,
16717
16893
  registerAgent: () => registerAgent,
16718
16894
  shouldRetry: () => shouldRetry,
16719
16895
  storeHealingStrategy: () => storeHealingStrategy,
16896
+ updateAgentSpecializations: () => updateAgentSpecializations,
16720
16897
  updateAgentStatus: () => updateAgentStatus,
16721
16898
  updateCapacity: () => updateCapacity,
16722
16899
  withRetry: () => withRetry
@@ -16724,9 +16901,11 @@ __export(agents_exports, {
16724
16901
  var init_agents = __esm({
16725
16902
  "packages/core/src/agents/index.ts"() {
16726
16903
  "use strict";
16904
+ init_agent_registry();
16727
16905
  init_agent_schema();
16728
16906
  init_capacity();
16729
16907
  init_execution_learning();
16908
+ init_health_monitor();
16730
16909
  init_registry2();
16731
16910
  init_retry();
16732
16911
  }
@@ -20598,19 +20777,19 @@ async function queryAudit(options) {
20598
20777
  try {
20599
20778
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
20600
20779
  const { auditLog: auditLog2 } = await Promise.resolve().then(() => (init_tasks_schema(), tasks_schema_exports));
20601
- const { and: and11, eq: eq16, gte: gte4, or: or6 } = await import("drizzle-orm");
20780
+ const { and: and12, eq: eq17, gte: gte4, or: or6 } = await import("drizzle-orm");
20602
20781
  const db = await getDb4(process.cwd());
20603
20782
  const conditions = [];
20604
- if (options?.sessionId) conditions.push(eq16(auditLog2.sessionId, options.sessionId));
20605
- if (options?.domain) conditions.push(eq16(auditLog2.domain, options.domain));
20783
+ if (options?.sessionId) conditions.push(eq17(auditLog2.sessionId, options.sessionId));
20784
+ if (options?.domain) conditions.push(eq17(auditLog2.domain, options.domain));
20606
20785
  if (options?.operation)
20607
20786
  conditions.push(
20608
- or6(eq16(auditLog2.operation, options.operation), eq16(auditLog2.action, options.operation))
20787
+ or6(eq17(auditLog2.operation, options.operation), eq17(auditLog2.action, options.operation))
20609
20788
  );
20610
- if (options?.taskId) conditions.push(eq16(auditLog2.taskId, options.taskId));
20789
+ if (options?.taskId) conditions.push(eq17(auditLog2.taskId, options.taskId));
20611
20790
  if (options?.since) conditions.push(gte4(auditLog2.timestamp, options.since));
20612
20791
  const limit = options?.limit ?? 1e3;
20613
- const rows = await db.select().from(auditLog2).where(conditions.length > 0 ? and11(...conditions) : void 0).orderBy(auditLog2.timestamp).limit(limit);
20792
+ const rows = await db.select().from(auditLog2).where(conditions.length > 0 ? and12(...conditions) : void 0).orderBy(auditLog2.timestamp).limit(limit);
20614
20793
  return rows.map((row) => ({
20615
20794
  timestamp: row.timestamp,
20616
20795
  sessionId: row.sessionId,
@@ -34355,6 +34534,116 @@ function generateRecommendation2(changeType, affectedCount, cascadeDepth, taskId
34355
34534
  return `${severity} impact: reprioritizing ${taskId} may reorder ${affectedCount} downstream task(s) across ${cascadeDepth} level(s) of dependencies.`;
34356
34535
  }
34357
34536
  }
34537
+ function scoreTaskMatch(change, task) {
34538
+ const STOP_WORDS3 = /* @__PURE__ */ new Set([
34539
+ "a",
34540
+ "an",
34541
+ "the",
34542
+ "and",
34543
+ "or",
34544
+ "in",
34545
+ "of",
34546
+ "to",
34547
+ "for",
34548
+ "with",
34549
+ "on",
34550
+ "at",
34551
+ "by",
34552
+ "is",
34553
+ "it",
34554
+ "be",
34555
+ "as",
34556
+ "if",
34557
+ "do",
34558
+ "not"
34559
+ ]);
34560
+ const tokenise = (text3) => text3.toLowerCase().split(/\W+/).filter((t) => t.length > 2 && !STOP_WORDS3.has(t));
34561
+ const changeTokens = new Set(tokenise(change));
34562
+ if (changeTokens.size === 0) return 0;
34563
+ const taskText = `${task.title ?? ""} ${task.description ?? ""}`;
34564
+ const taskTokens = new Set(tokenise(taskText));
34565
+ let matches = 0;
34566
+ for (const token of changeTokens) {
34567
+ if (taskTokens.has(token)) matches++;
34568
+ }
34569
+ return matches / changeTokens.size;
34570
+ }
34571
+ async function predictImpact(change, cwd, accessor, matchLimit = 5) {
34572
+ const acc = accessor ?? await getAccessor(cwd);
34573
+ const tasks2 = await loadAllTasks2(acc);
34574
+ const taskMap = new Map(tasks2.map((t) => [t.id, t]));
34575
+ const dependentsMap = buildDependentsMap(tasks2);
34576
+ const scored = tasks2.map((t) => ({ task: t, score: scoreTaskMatch(change, t) })).filter(({ score }) => score > 0).sort((a, b) => b.score - a.score);
34577
+ const seeds = scored.slice(0, matchLimit).map(({ task }) => task);
34578
+ if (seeds.length === 0) {
34579
+ return {
34580
+ change,
34581
+ matchedTasks: [],
34582
+ affectedTasks: [],
34583
+ totalAffected: 0,
34584
+ summary: `No tasks matched the change description "${change}".`
34585
+ };
34586
+ }
34587
+ const directMatchIds = new Set(seeds.map((t) => t.id));
34588
+ const exposureMap = /* @__PURE__ */ new Map();
34589
+ for (const id of directMatchIds) {
34590
+ exposureMap.set(id, "direct");
34591
+ }
34592
+ for (const seed of seeds) {
34593
+ const transitive = collectTransitiveDependents(seed.id, dependentsMap);
34594
+ for (const depId of transitive) {
34595
+ if (!exposureMap.has(depId)) {
34596
+ const isDirectDependent = (dependentsMap.get(seed.id) ?? /* @__PURE__ */ new Set()).has(depId);
34597
+ exposureMap.set(depId, isDirectDependent ? "dependent" : "transitive");
34598
+ }
34599
+ }
34600
+ }
34601
+ const EXPOSURE_ORDER = {
34602
+ direct: 0,
34603
+ dependent: 1,
34604
+ transitive: 2
34605
+ };
34606
+ const affectedTasks = [];
34607
+ for (const [id, exposure] of exposureMap) {
34608
+ const task = taskMap.get(id);
34609
+ if (!task) continue;
34610
+ const downstreamTransitive = collectTransitiveDependents(id, dependentsMap);
34611
+ const downstreamCount = downstreamTransitive.size;
34612
+ let reason;
34613
+ if (exposure === "direct") {
34614
+ reason = `Task title/description matched "${change}".`;
34615
+ } else if (exposure === "dependent") {
34616
+ const seedNames = seeds.filter((s) => (dependentsMap.get(s.id) ?? /* @__PURE__ */ new Set()).has(id)).map((s) => s.id).join(", ");
34617
+ reason = `Directly depends on matched task(s): ${seedNames}.`;
34618
+ } else {
34619
+ reason = "Downstream of a matched task via transitive dependency chain.";
34620
+ }
34621
+ affectedTasks.push({
34622
+ id,
34623
+ title: task.title,
34624
+ status: task.status,
34625
+ priority: task.priority,
34626
+ exposure,
34627
+ downstreamCount,
34628
+ reason
34629
+ });
34630
+ }
34631
+ affectedTasks.sort((a, b) => {
34632
+ const expDiff = EXPOSURE_ORDER[a.exposure] - EXPOSURE_ORDER[b.exposure];
34633
+ if (expDiff !== 0) return expDiff;
34634
+ return b.downstreamCount - a.downstreamCount;
34635
+ });
34636
+ const matchedTasks = affectedTasks.filter((t) => t.exposure === "direct");
34637
+ const totalAffected = affectedTasks.length;
34638
+ const summary = matchedTasks.length === 0 ? `No tasks matched "${change}".` : `${matchedTasks.length} task(s) matched "${change}"; ${totalAffected} total task(s) affected (including downstream).`;
34639
+ return {
34640
+ change,
34641
+ matchedTasks,
34642
+ affectedTasks,
34643
+ totalAffected,
34644
+ summary
34645
+ };
34646
+ }
34358
34647
  var init_impact = __esm({
34359
34648
  "packages/core/src/intelligence/impact.ts"() {
34360
34649
  "use strict";
@@ -34758,6 +35047,7 @@ __export(intelligence_exports, {
34758
35047
  gatherLearningContext: () => gatherLearningContext,
34759
35048
  matchPatterns: () => matchPatterns,
34760
35049
  predictAndStore: () => predictAndStore,
35050
+ predictImpact: () => predictImpact,
34761
35051
  predictValidationOutcome: () => predictValidationOutcome,
34762
35052
  scoreVerificationConfidence: () => scoreVerificationConfidence,
34763
35053
  storeDetectedPattern: () => storeDetectedPattern,
@@ -36506,13 +36796,13 @@ function extractYamlArray(content, field) {
36506
36796
  }
36507
36797
  const lines = content.split("\n");
36508
36798
  const items = [];
36509
- let inArray6 = false;
36799
+ let inArray7 = false;
36510
36800
  for (const line2 of lines) {
36511
36801
  if (line2.match(new RegExp(`^${field}:`))) {
36512
- inArray6 = true;
36802
+ inArray7 = true;
36513
36803
  continue;
36514
36804
  }
36515
- if (inArray6) {
36805
+ if (inArray7) {
36516
36806
  const itemMatch = line2.match(/^\s+-\s+["']?(.+?)["']?\s*$/);
36517
36807
  if (itemMatch) {
36518
36808
  items.push(itemMatch[1].trim());
@@ -36808,6 +37098,71 @@ var init_issue = __esm({
36808
37098
  }
36809
37099
  });
36810
37100
 
37101
+ // packages/core/src/lib/retry.ts
37102
+ async function withRetry2(fn, options) {
37103
+ const maxAttempts = options?.maxAttempts ?? 3;
37104
+ const baseDelayMs = options?.baseDelayMs ?? 2e3;
37105
+ const maxDelayMs = options?.maxDelayMs ?? 3e4;
37106
+ const retryableErrors = options?.retryableErrors;
37107
+ let lastError;
37108
+ let totalDelayMs = 0;
37109
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
37110
+ try {
37111
+ return await fn();
37112
+ } catch (err) {
37113
+ lastError = err;
37114
+ const isLastAttempt = attempt === maxAttempts;
37115
+ if (isLastAttempt) break;
37116
+ if (retryableErrors !== void 0 && !isRetryable(err, retryableErrors)) break;
37117
+ const delay = computeDelay(attempt, baseDelayMs, maxDelayMs);
37118
+ totalDelayMs += delay;
37119
+ await sleep2(delay);
37120
+ }
37121
+ }
37122
+ const context = { attempts: maxAttempts, totalDelayMs };
37123
+ augmentError(lastError, context);
37124
+ throw lastError;
37125
+ }
37126
+ function computeDelay(attempt, baseDelayMs, maxDelayMs) {
37127
+ const exponential = baseDelayMs * 2 ** (attempt - 1);
37128
+ return Math.min(exponential, maxDelayMs);
37129
+ }
37130
+ function isRetryable(err, predicates) {
37131
+ const message = err instanceof Error ? err.message : String(err);
37132
+ return predicates.some((predicate) => {
37133
+ if (predicate instanceof RegExp) return predicate.test(message);
37134
+ return predicate(err);
37135
+ });
37136
+ }
37137
+ function augmentError(err, context) {
37138
+ if (err instanceof Error) {
37139
+ const mutableErr = err;
37140
+ mutableErr.attempts = context.attempts;
37141
+ mutableErr.totalDelayMs = context.totalDelayMs;
37142
+ }
37143
+ }
37144
+ function sleep2(ms) {
37145
+ return new Promise((resolve13) => setTimeout(resolve13, ms));
37146
+ }
37147
+ var init_retry2 = __esm({
37148
+ "packages/core/src/lib/retry.ts"() {
37149
+ "use strict";
37150
+ }
37151
+ });
37152
+
37153
+ // packages/core/src/lib/index.ts
37154
+ var lib_exports = {};
37155
+ __export(lib_exports, {
37156
+ computeDelay: () => computeDelay,
37157
+ withRetry: () => withRetry2
37158
+ });
37159
+ var init_lib = __esm({
37160
+ "packages/core/src/lib/index.ts"() {
37161
+ "use strict";
37162
+ init_retry2();
37163
+ }
37164
+ });
37165
+
36811
37166
  // packages/core/src/lifecycle/evidence.ts
36812
37167
  import { basename as basename5, relative as relative2 } from "node:path";
36813
37168
  async function recordEvidence(epicId, stage, uri, type, options) {
@@ -37647,12 +38002,12 @@ async function getEnforcementMode(cwd) {
37647
38002
  }
37648
38003
  async function getLifecycleStatus(epicId, cwd) {
37649
38004
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
37650
- const { eq: eq16 } = await import("drizzle-orm");
38005
+ const { eq: eq17 } = await import("drizzle-orm");
37651
38006
  const db = await getDb4(cwd);
37652
38007
  const pipelineResult = await db.select({
37653
38008
  pipeline: lifecyclePipelines,
37654
38009
  task: tasks
37655
- }).from(lifecyclePipelines).innerJoin(tasks, eq16(lifecyclePipelines.taskId, tasks.id)).where(eq16(lifecyclePipelines.taskId, epicId)).limit(1);
38010
+ }).from(lifecyclePipelines).innerJoin(tasks, eq17(lifecyclePipelines.taskId, tasks.id)).where(eq17(lifecyclePipelines.taskId, epicId)).limit(1);
37656
38011
  if (pipelineResult.length === 0) {
37657
38012
  return {
37658
38013
  epicId,
@@ -37665,7 +38020,7 @@ async function getLifecycleStatus(epicId, cwd) {
37665
38020
  }
37666
38021
  const task = pipelineResult[0].task;
37667
38022
  const pipelineId = `pipeline-${epicId}`;
37668
- const stageRows = await db.select().from(lifecycleStages).where(eq16(lifecycleStages.pipelineId, pipelineId)).orderBy(lifecycleStages.sequence);
38023
+ const stageRows = await db.select().from(lifecycleStages).where(eq17(lifecycleStages.pipelineId, pipelineId)).orderBy(lifecycleStages.sequence);
37669
38024
  const stageDataMap = /* @__PURE__ */ new Map();
37670
38025
  for (const row of stageRows) {
37671
38026
  let parsedChain;
@@ -37734,10 +38089,10 @@ async function getLifecycleStatus(epicId, cwd) {
37734
38089
  }
37735
38090
  async function getLifecycleHistory(epicId, cwd) {
37736
38091
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
37737
- const { eq: eq16 } = await import("drizzle-orm");
38092
+ const { eq: eq17 } = await import("drizzle-orm");
37738
38093
  const db = await getDb4(cwd);
37739
38094
  const pipelineId = `pipeline-${epicId}`;
37740
- const stages = await db.select().from(lifecycleStages).where(eq16(lifecycleStages.pipelineId, pipelineId));
38095
+ const stages = await db.select().from(lifecycleStages).where(eq17(lifecycleStages.pipelineId, pipelineId));
37741
38096
  if (stages.length === 0) {
37742
38097
  return { epicId, history: [] };
37743
38098
  }
@@ -37767,7 +38122,7 @@ async function getLifecycleHistory(epicId, cwd) {
37767
38122
  }
37768
38123
  const stageIds = stages.map((s) => s.id);
37769
38124
  if (stageIds.length > 0) {
37770
- const gateResults = await db.select().from(lifecycleGateResults).where(eq16(lifecycleGateResults.stageId, stageIds[0]));
38125
+ const gateResults = await db.select().from(lifecycleGateResults).where(eq17(lifecycleGateResults.stageId, stageIds[0]));
37771
38126
  for (const gate of gateResults) {
37772
38127
  const stageName = stageIdToName.get(gate.stageId);
37773
38128
  if (stageName) {
@@ -37780,7 +38135,7 @@ async function getLifecycleHistory(epicId, cwd) {
37780
38135
  }
37781
38136
  }
37782
38137
  for (let i = 1; i < stageIds.length; i++) {
37783
- const additionalGates = await db.select().from(lifecycleGateResults).where(eq16(lifecycleGateResults.stageId, stageIds[i]));
38138
+ const additionalGates = await db.select().from(lifecycleGateResults).where(eq17(lifecycleGateResults.stageId, stageIds[i]));
37784
38139
  for (const gate of additionalGates) {
37785
38140
  const stageName = stageIdToName.get(gate.stageId);
37786
38141
  if (stageName) {
@@ -37799,16 +38154,16 @@ async function getLifecycleHistory(epicId, cwd) {
37799
38154
  }
37800
38155
  async function getLifecycleGates(epicId, cwd) {
37801
38156
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
37802
- const { eq: eq16 } = await import("drizzle-orm");
38157
+ const { eq: eq17 } = await import("drizzle-orm");
37803
38158
  const db = await getDb4(cwd);
37804
38159
  const pipelineId = `pipeline-${epicId}`;
37805
- const stages = await db.select().from(lifecycleStages).where(eq16(lifecycleStages.pipelineId, pipelineId));
38160
+ const stages = await db.select().from(lifecycleStages).where(eq17(lifecycleStages.pipelineId, pipelineId));
37806
38161
  if (stages.length === 0) {
37807
38162
  return {};
37808
38163
  }
37809
38164
  const gates = {};
37810
38165
  for (const stage of stages) {
37811
- const gateRows = await db.select().from(lifecycleGateResults).where(eq16(lifecycleGateResults.stageId, stage.id));
38166
+ const gateRows = await db.select().from(lifecycleGateResults).where(eq17(lifecycleGateResults.stageId, stage.id));
37812
38167
  if (gateRows.length > 0) {
37813
38168
  gates[stage.stageName] = {};
37814
38169
  for (const gateRow of gateRows) {
@@ -37872,7 +38227,7 @@ async function checkStagePrerequisites(epicId, targetStage, cwd) {
37872
38227
  }
37873
38228
  async function ensureLifecycleContext(epicId, stageName, cwd, options) {
37874
38229
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
37875
- const { eq: eq16 } = await import("drizzle-orm");
38230
+ const { eq: eq17 } = await import("drizzle-orm");
37876
38231
  const db = await getDb4(cwd);
37877
38232
  const pipelineId = `pipeline-${epicId}`;
37878
38233
  const stageId = `stage-${epicId}-${stageName}`;
@@ -37880,7 +38235,7 @@ async function ensureLifecycleContext(epicId, stageName, cwd, options) {
37880
38235
  getNativeDb3().prepare(
37881
38236
  `INSERT OR IGNORE INTO tasks (id, title, status, priority, created_at) VALUES (?, ?, 'pending', 'medium', datetime('now'))`
37882
38237
  ).run(epicId, `Task ${epicId}`);
37883
- const existingPipeline = await db.select().from(lifecyclePipelines).where(eq16(lifecyclePipelines.id, pipelineId)).limit(1).all();
38238
+ const existingPipeline = await db.select().from(lifecyclePipelines).where(eq17(lifecyclePipelines.id, pipelineId)).limit(1).all();
37884
38239
  if (existingPipeline.length === 0) {
37885
38240
  await db.insert(lifecyclePipelines).values({
37886
38241
  id: pipelineId,
@@ -37890,7 +38245,7 @@ async function ensureLifecycleContext(epicId, stageName, cwd, options) {
37890
38245
  startedAt: options.now
37891
38246
  }).run();
37892
38247
  }
37893
- const existingStage = await db.select().from(lifecycleStages).where(eq16(lifecycleStages.id, stageId)).limit(1).all();
38248
+ const existingStage = await db.select().from(lifecycleStages).where(eq17(lifecycleStages.id, stageId)).limit(1).all();
37894
38249
  if (existingStage.length === 0) {
37895
38250
  const sequence = isValidStage(stageName) ? STAGE_ORDER[stageName] : 0;
37896
38251
  await db.insert(lifecycleStages).values({
@@ -37903,7 +38258,7 @@ async function ensureLifecycleContext(epicId, stageName, cwd, options) {
37903
38258
  }).run();
37904
38259
  }
37905
38260
  if (options.updateCurrentStage) {
37906
- await db.update(lifecyclePipelines).set({ currentStageId: stageId }).where(eq16(lifecyclePipelines.id, pipelineId)).run();
38261
+ await db.update(lifecyclePipelines).set({ currentStageId: stageId }).where(eq17(lifecyclePipelines.id, pipelineId)).run();
37907
38262
  }
37908
38263
  return { db, pipelineId, stageId };
37909
38264
  }
@@ -37918,7 +38273,7 @@ async function recordStageProgress(epicId, stage, status, notes, cwd) {
37918
38273
  `Invalid status: ${status}. Valid: ${validStatuses.join(", ")}`
37919
38274
  );
37920
38275
  }
37921
- const { eq: eq16 } = await import("drizzle-orm");
38276
+ const { eq: eq17 } = await import("drizzle-orm");
37922
38277
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
37923
38278
  const stageName = stage;
37924
38279
  const { db, stageId, pipelineId } = await ensureLifecycleContext(epicId, stage, cwd, {
@@ -37934,7 +38289,7 @@ async function recordStageProgress(epicId, stage, status, notes, cwd) {
37934
38289
  status,
37935
38290
  related: artifact.related
37936
38291
  };
37937
- const existingStage = await db.select().from(lifecycleStages).where(eq16(lifecycleStages.id, stageId)).limit(1).all();
38292
+ const existingStage = await db.select().from(lifecycleStages).where(eq17(lifecycleStages.id, stageId)).limit(1).all();
37938
38293
  const sequence = STAGE_ORDER[stage];
37939
38294
  const stageValues = {
37940
38295
  status,
@@ -37961,7 +38316,7 @@ async function recordStageProgress(epicId, stage, status, notes, cwd) {
37961
38316
  provenanceChainJson: JSON.stringify(provenanceChain)
37962
38317
  }).run();
37963
38318
  } else {
37964
- await db.update(lifecycleStages).set(stageValues).where(eq16(lifecycleStages.id, stageId)).run();
38319
+ await db.update(lifecycleStages).set(stageValues).where(eq17(lifecycleStages.id, stageId)).run();
37965
38320
  }
37966
38321
  if (status === "completed") {
37967
38322
  await linkProvenance(epicId, stageName, artifact.absolutePath, cwd);
@@ -37981,7 +38336,7 @@ async function resetStage(epicId, stage, reason, cwd) {
37981
38336
  if (!PIPELINE_STAGES.includes(stage)) {
37982
38337
  throw new CleoError(2 /* INVALID_INPUT */, `Invalid stage: ${stage}`);
37983
38338
  }
37984
- const { eq: eq16 } = await import("drizzle-orm");
38339
+ const { eq: eq17 } = await import("drizzle-orm");
37985
38340
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
37986
38341
  const { db, stageId } = await ensureLifecycleContext(epicId, stage, cwd, {
37987
38342
  now: now2,
@@ -37994,11 +38349,11 @@ async function resetStage(epicId, stage, reason, cwd) {
37994
38349
  skippedAt: null,
37995
38350
  skipReason: null,
37996
38351
  notesJson: JSON.stringify([`Reset: ${reason}`])
37997
- }).where(eq16(lifecycleStages.id, stageId)).run();
38352
+ }).where(eq17(lifecycleStages.id, stageId)).run();
37998
38353
  return { epicId, stage, reason };
37999
38354
  }
38000
38355
  async function passGate(epicId, gateName, agent, notes, cwd) {
38001
- const { eq: eq16 } = await import("drizzle-orm");
38356
+ const { eq: eq17 } = await import("drizzle-orm");
38002
38357
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
38003
38358
  const stageName = gateName.split("-")[0];
38004
38359
  const gateId = `gate-${epicId}-${stageName}-${gateName}`;
@@ -38007,7 +38362,7 @@ async function passGate(epicId, gateName, agent, notes, cwd) {
38007
38362
  stageStatusOnCreate: "in_progress",
38008
38363
  updateCurrentStage: true
38009
38364
  });
38010
- const existingGate = await db.select().from(lifecycleGateResults).where(eq16(lifecycleGateResults.id, gateId)).limit(1).all();
38365
+ const existingGate = await db.select().from(lifecycleGateResults).where(eq17(lifecycleGateResults.id, gateId)).limit(1).all();
38011
38366
  const gateValues = {
38012
38367
  id: gateId,
38013
38368
  stageId,
@@ -38019,14 +38374,14 @@ async function passGate(epicId, gateName, agent, notes, cwd) {
38019
38374
  reason: null
38020
38375
  };
38021
38376
  if (existingGate.length > 0) {
38022
- await db.update(lifecycleGateResults).set(gateValues).where(eq16(lifecycleGateResults.id, gateId)).run();
38377
+ await db.update(lifecycleGateResults).set(gateValues).where(eq17(lifecycleGateResults.id, gateId)).run();
38023
38378
  } else {
38024
38379
  await db.insert(lifecycleGateResults).values(gateValues).run();
38025
38380
  }
38026
38381
  return { epicId, gateName, timestamp: now2 };
38027
38382
  }
38028
38383
  async function failGate(epicId, gateName, reason, cwd) {
38029
- const { eq: eq16 } = await import("drizzle-orm");
38384
+ const { eq: eq17 } = await import("drizzle-orm");
38030
38385
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
38031
38386
  const stageName = gateName.split("-")[0];
38032
38387
  const gateId = `gate-${epicId}-${stageName}-${gateName}`;
@@ -38035,7 +38390,7 @@ async function failGate(epicId, gateName, reason, cwd) {
38035
38390
  stageStatusOnCreate: "in_progress",
38036
38391
  updateCurrentStage: true
38037
38392
  });
38038
- const existingGate = await db.select().from(lifecycleGateResults).where(eq16(lifecycleGateResults.id, gateId)).limit(1).all();
38393
+ const existingGate = await db.select().from(lifecycleGateResults).where(eq17(lifecycleGateResults.id, gateId)).limit(1).all();
38039
38394
  const gateValues = {
38040
38395
  id: gateId,
38041
38396
  stageId,
@@ -38047,7 +38402,7 @@ async function failGate(epicId, gateName, reason, cwd) {
38047
38402
  reason: reason ?? null
38048
38403
  };
38049
38404
  if (existingGate.length > 0) {
38050
- await db.update(lifecycleGateResults).set(gateValues).where(eq16(lifecycleGateResults.id, gateId)).run();
38405
+ await db.update(lifecycleGateResults).set(gateValues).where(eq17(lifecycleGateResults.id, gateId)).run();
38051
38406
  } else {
38052
38407
  await db.insert(lifecycleGateResults).values(gateValues).run();
38053
38408
  }
@@ -38121,8 +38476,8 @@ function detectEnvMode() {
38121
38476
  const devKv = {};
38122
38477
  const devLines = devContent.trim().split("\n");
38123
38478
  for (let i = 1; i < devLines.length; i++) {
38124
- const eq16 = devLines[i].indexOf("=");
38125
- if (eq16 > 0) devKv[devLines[i].slice(0, eq16).trim()] = devLines[i].slice(eq16 + 1).trim();
38479
+ const eq17 = devLines[i].indexOf("=");
38480
+ if (eq17 > 0) devKv[devLines[i].slice(0, eq17).trim()] = devLines[i].slice(eq17 + 1).trim();
38126
38481
  }
38127
38482
  if (devKv["mode"] === "dev-ts" && devKv["source"]) {
38128
38483
  const devSource = devKv["source"].replace(/\\/g, "/");
@@ -38435,7 +38790,7 @@ var init_config = __esm({
38435
38790
  "session.autoStart": false,
38436
38791
  "session.requireNotes": true,
38437
38792
  "session.multiSession": false,
38438
- "hierarchy.requireAcceptanceCriteria": true,
38793
+ "enforcement.acceptance.mode": "block",
38439
38794
  "lifecycle.mode": "strict"
38440
38795
  }
38441
38796
  },
@@ -38445,7 +38800,7 @@ var init_config = __esm({
38445
38800
  "session.autoStart": false,
38446
38801
  "session.requireNotes": false,
38447
38802
  "session.multiSession": true,
38448
- "hierarchy.requireAcceptanceCriteria": false,
38803
+ "enforcement.acceptance.mode": "warn",
38449
38804
  "lifecycle.mode": "advisory"
38450
38805
  }
38451
38806
  },
@@ -38455,7 +38810,7 @@ var init_config = __esm({
38455
38810
  "session.autoStart": false,
38456
38811
  "session.requireNotes": false,
38457
38812
  "session.multiSession": true,
38458
- "hierarchy.requireAcceptanceCriteria": false,
38813
+ "enforcement.acceptance.mode": "off",
38459
38814
  "lifecycle.mode": "off"
38460
38815
  }
38461
38816
  }
@@ -38834,13 +39189,13 @@ __export(pipeline_exports, {
38834
39189
  listPipelines: () => listPipelines,
38835
39190
  pipelineExists: () => pipelineExists
38836
39191
  });
38837
- import { and as and5, asc as asc3, desc as desc3, eq as eq8, sql as sql9 } from "drizzle-orm";
39192
+ import { and as and6, asc as asc3, desc as desc3, eq as eq9, sql as sql9 } from "drizzle-orm";
38838
39193
  async function initializePipeline(taskId, options = {}) {
38839
39194
  const db = await getDb();
38840
39195
  const now2 = /* @__PURE__ */ new Date();
38841
39196
  const startStage2 = options.startStage || "research";
38842
39197
  const initialStatus = options.initialStatus || "active";
38843
- const existing = await db.select().from(lifecyclePipelines).where(eq8(lifecyclePipelines.taskId, taskId)).limit(1).all();
39198
+ const existing = await db.select().from(lifecyclePipelines).where(eq9(lifecyclePipelines.taskId, taskId)).limit(1).all();
38844
39199
  if (existing.length > 0) {
38845
39200
  throw new CleoError(101 /* ALREADY_EXISTS */, `Pipeline already exists for task ${taskId}`);
38846
39201
  }
@@ -38889,13 +39244,13 @@ async function initializePipeline(taskId, options = {}) {
38889
39244
  }
38890
39245
  async function getPipeline(taskId) {
38891
39246
  const db = await getDb();
38892
- const result = await db.select().from(lifecyclePipelines).where(eq8(lifecyclePipelines.taskId, taskId)).limit(1).all();
39247
+ const result = await db.select().from(lifecyclePipelines).where(eq9(lifecyclePipelines.taskId, taskId)).limit(1).all();
38893
39248
  if (result.length === 0) {
38894
39249
  return null;
38895
39250
  }
38896
39251
  const row = result[0];
38897
39252
  const isActive = row.status === "active";
38898
- const transitionResult = await db.select({ count: sql9`count(*)` }).from(lifecycleTransitions).where(eq8(lifecycleTransitions.pipelineId, row.id)).all();
39253
+ const transitionResult = await db.select({ count: sql9`count(*)` }).from(lifecycleTransitions).where(eq9(lifecycleTransitions.pipelineId, row.id)).all();
38899
39254
  const transitionCount = Number(transitionResult[0]?.count || 0);
38900
39255
  return {
38901
39256
  id: taskId,
@@ -38918,7 +39273,7 @@ async function advanceStage(taskId, options) {
38918
39273
  if (!options.initiatedBy) {
38919
39274
  throw new CleoError(2 /* INVALID_INPUT */, "advanceStage() requires initiatedBy agent/user");
38920
39275
  }
38921
- const pipelineResult = await db.select().from(lifecyclePipelines).where(eq8(lifecyclePipelines.taskId, taskId)).limit(1).all();
39276
+ const pipelineResult = await db.select().from(lifecyclePipelines).where(eq9(lifecyclePipelines.taskId, taskId)).limit(1).all();
38922
39277
  if (pipelineResult.length === 0) {
38923
39278
  throw new CleoError(4 /* NOT_FOUND */, `No pipeline found for task ${taskId}`);
38924
39279
  }
@@ -38926,9 +39281,9 @@ async function advanceStage(taskId, options) {
38926
39281
  const fromStage = pipeline2.currentStageId;
38927
39282
  const toStage = options.toStage;
38928
39283
  const currentStageResult = await db.select().from(lifecycleStages).where(
38929
- and5(
38930
- eq8(lifecycleStages.pipelineId, pipeline2.id),
38931
- eq8(lifecycleStages.stageName, fromStage)
39284
+ and6(
39285
+ eq9(lifecycleStages.pipelineId, pipeline2.id),
39286
+ eq9(lifecycleStages.stageName, fromStage)
38932
39287
  )
38933
39288
  ).limit(1).all();
38934
39289
  if (currentStageResult.length === 0) {
@@ -38939,9 +39294,9 @@ async function advanceStage(taskId, options) {
38939
39294
  }
38940
39295
  const currentStageRecord = currentStageResult[0];
38941
39296
  const targetStageResult = await db.select().from(lifecycleStages).where(
38942
- and5(
38943
- eq8(lifecycleStages.pipelineId, pipeline2.id),
38944
- eq8(lifecycleStages.stageName, toStage)
39297
+ and6(
39298
+ eq9(lifecycleStages.pipelineId, pipeline2.id),
39299
+ eq9(lifecycleStages.stageName, toStage)
38945
39300
  )
38946
39301
  ).limit(1).all();
38947
39302
  if (targetStageResult.length === 0) {
@@ -38954,14 +39309,14 @@ async function advanceStage(taskId, options) {
38954
39309
  await db.update(lifecycleStages).set({
38955
39310
  status: "completed",
38956
39311
  completedAt: now2.toISOString()
38957
- }).where(eq8(lifecycleStages.id, currentStageRecord.id)).run();
39312
+ }).where(eq9(lifecycleStages.id, currentStageRecord.id)).run();
38958
39313
  await db.update(lifecycleStages).set({
38959
39314
  status: "in_progress",
38960
39315
  startedAt: now2.toISOString()
38961
- }).where(eq8(lifecycleStages.id, targetStageRecord.id)).run();
39316
+ }).where(eq9(lifecycleStages.id, targetStageRecord.id)).run();
38962
39317
  await db.update(lifecyclePipelines).set({
38963
39318
  currentStageId: toStage
38964
- }).where(eq8(lifecyclePipelines.id, pipeline2.id)).run();
39319
+ }).where(eq9(lifecyclePipelines.id, pipeline2.id)).run();
38965
39320
  await db.insert(lifecycleTransitions).values({
38966
39321
  id: `${pipeline2.id}_${now2.getTime()}_${Math.random().toString(36).slice(2, 7)}`,
38967
39322
  pipelineId: pipeline2.id,
@@ -38978,7 +39333,7 @@ async function advanceStage(taskId, options) {
38978
39333
  }
38979
39334
  async function getCurrentStage(taskId) {
38980
39335
  const db = await getDb();
38981
- const result = await db.select({ currentStageId: lifecyclePipelines.currentStageId }).from(lifecyclePipelines).where(eq8(lifecyclePipelines.taskId, taskId)).limit(1).all();
39336
+ const result = await db.select({ currentStageId: lifecyclePipelines.currentStageId }).from(lifecyclePipelines).where(eq9(lifecyclePipelines.taskId, taskId)).limit(1).all();
38982
39337
  if (result.length === 0) {
38983
39338
  throw new CleoError(4 /* NOT_FOUND */, `No pipeline found for task ${taskId}`);
38984
39339
  }
@@ -38990,43 +39345,43 @@ async function listPipelines(options = {}) {
38990
39345
  const conditions = [];
38991
39346
  if (options.status) {
38992
39347
  conditions.push(
38993
- eq8(
39348
+ eq9(
38994
39349
  lifecyclePipelines.status,
38995
39350
  options.status
38996
39351
  )
38997
39352
  );
38998
39353
  }
38999
39354
  if (options.currentStage) {
39000
- conditions.push(eq8(lifecyclePipelines.currentStageId, options.currentStage));
39355
+ conditions.push(eq9(lifecyclePipelines.currentStageId, options.currentStage));
39001
39356
  }
39002
39357
  if (conditions.length > 0) {
39003
- const whereClause = conditions.length === 1 ? conditions[0] : and5(...conditions);
39358
+ const whereClause = conditions.length === 1 ? conditions[0] : and6(...conditions);
39004
39359
  query = db.select().from(lifecyclePipelines).where(whereClause);
39005
39360
  }
39006
39361
  if (options.orderBy) {
39007
39362
  const order = options.order === "asc" ? asc3 : desc3;
39008
39363
  switch (options.orderBy) {
39009
39364
  case "createdAt":
39010
- query = db.select().from(lifecyclePipelines).where(conditions.length > 0 ? and5(...conditions) : void 0).orderBy(order(lifecyclePipelines.startedAt));
39365
+ query = db.select().from(lifecyclePipelines).where(conditions.length > 0 ? and6(...conditions) : void 0).orderBy(order(lifecyclePipelines.startedAt));
39011
39366
  break;
39012
39367
  case "currentStage":
39013
- query = db.select().from(lifecyclePipelines).where(conditions.length > 0 ? and5(...conditions) : void 0).orderBy(order(lifecyclePipelines.currentStageId));
39368
+ query = db.select().from(lifecyclePipelines).where(conditions.length > 0 ? and6(...conditions) : void 0).orderBy(order(lifecyclePipelines.currentStageId));
39014
39369
  break;
39015
39370
  }
39016
39371
  } else {
39017
- query = db.select().from(lifecyclePipelines).where(conditions.length > 0 ? and5(...conditions) : void 0).orderBy(desc3(lifecyclePipelines.startedAt));
39372
+ query = db.select().from(lifecyclePipelines).where(conditions.length > 0 ? and6(...conditions) : void 0).orderBy(desc3(lifecyclePipelines.startedAt));
39018
39373
  }
39019
39374
  if (options.limit) {
39020
- query = db.select().from(lifecyclePipelines).where(conditions.length > 0 ? and5(...conditions) : void 0).orderBy(desc3(lifecyclePipelines.startedAt)).limit(options.limit);
39375
+ query = db.select().from(lifecyclePipelines).where(conditions.length > 0 ? and6(...conditions) : void 0).orderBy(desc3(lifecyclePipelines.startedAt)).limit(options.limit);
39021
39376
  }
39022
39377
  if (options.offset) {
39023
- query = db.select().from(lifecyclePipelines).where(conditions.length > 0 ? and5(...conditions) : void 0).orderBy(desc3(lifecyclePipelines.startedAt)).limit(options.limit || 100).offset(options.offset);
39378
+ query = db.select().from(lifecyclePipelines).where(conditions.length > 0 ? and6(...conditions) : void 0).orderBy(desc3(lifecyclePipelines.startedAt)).limit(options.limit || 100).offset(options.offset);
39024
39379
  }
39025
39380
  const results = await query.all();
39026
39381
  return Promise.all(
39027
39382
  results.map(async (row) => {
39028
39383
  const isActive = row.status === "active";
39029
- const transitionResult = await db.select({ count: sql9`count(*)` }).from(lifecycleTransitions).where(eq8(lifecycleTransitions.pipelineId, row.id)).all();
39384
+ const transitionResult = await db.select({ count: sql9`count(*)` }).from(lifecycleTransitions).where(eq9(lifecycleTransitions.pipelineId, row.id)).all();
39030
39385
  const transitionCount = Number(transitionResult[0]?.count || 0);
39031
39386
  return {
39032
39387
  id: row.taskId,
@@ -39045,7 +39400,7 @@ async function listPipelines(options = {}) {
39045
39400
  async function completePipeline(taskId, reason) {
39046
39401
  const db = await getDb();
39047
39402
  const now2 = /* @__PURE__ */ new Date();
39048
- const pipelineResult = await db.select().from(lifecyclePipelines).where(eq8(lifecyclePipelines.taskId, taskId)).limit(1).all();
39403
+ const pipelineResult = await db.select().from(lifecyclePipelines).where(eq9(lifecyclePipelines.taskId, taskId)).limit(1).all();
39049
39404
  if (pipelineResult.length === 0) {
39050
39405
  throw new CleoError(4 /* NOT_FOUND */, `No pipeline found for task ${taskId}`);
39051
39406
  }
@@ -39060,21 +39415,21 @@ async function completePipeline(taskId, reason) {
39060
39415
  stageUpdate.metadataJson = JSON.stringify({ completionReason: reason });
39061
39416
  }
39062
39417
  await db.update(lifecycleStages).set(stageUpdate).where(
39063
- and5(
39064
- eq8(lifecycleStages.pipelineId, pipeline2.id),
39065
- eq8(lifecycleStages.stageName, pipeline2.currentStageId)
39418
+ and6(
39419
+ eq9(lifecycleStages.pipelineId, pipeline2.id),
39420
+ eq9(lifecycleStages.stageName, pipeline2.currentStageId)
39066
39421
  )
39067
39422
  ).run();
39068
39423
  }
39069
39424
  await db.update(lifecyclePipelines).set({
39070
39425
  status: "completed",
39071
39426
  completedAt: now2.toISOString()
39072
- }).where(eq8(lifecyclePipelines.id, pipeline2.id)).run();
39427
+ }).where(eq9(lifecyclePipelines.id, pipeline2.id)).run();
39073
39428
  }
39074
39429
  async function cancelPipeline(taskId, reason) {
39075
39430
  const db = await getDb();
39076
39431
  const now2 = /* @__PURE__ */ new Date();
39077
- const pipelineResult = await db.select().from(lifecyclePipelines).where(eq8(lifecyclePipelines.taskId, taskId)).limit(1).all();
39432
+ const pipelineResult = await db.select().from(lifecyclePipelines).where(eq9(lifecyclePipelines.taskId, taskId)).limit(1).all();
39078
39433
  if (pipelineResult.length === 0) {
39079
39434
  throw new CleoError(4 /* NOT_FOUND */, `No pipeline found for task ${taskId}`);
39080
39435
  }
@@ -39091,20 +39446,20 @@ async function cancelPipeline(taskId, reason) {
39091
39446
  blockedAt: now2.toISOString(),
39092
39447
  blockReason: `Pipeline cancelled: ${reason}`
39093
39448
  }).where(
39094
- and5(
39095
- eq8(lifecycleStages.pipelineId, pipeline2.id),
39096
- eq8(lifecycleStages.stageName, pipeline2.currentStageId)
39449
+ and6(
39450
+ eq9(lifecycleStages.pipelineId, pipeline2.id),
39451
+ eq9(lifecycleStages.stageName, pipeline2.currentStageId)
39097
39452
  )
39098
39453
  ).run();
39099
39454
  }
39100
39455
  await db.update(lifecyclePipelines).set({
39101
39456
  status: "cancelled",
39102
39457
  completedAt: now2.toISOString()
39103
- }).where(eq8(lifecyclePipelines.id, pipeline2.id)).run();
39458
+ }).where(eq9(lifecyclePipelines.id, pipeline2.id)).run();
39104
39459
  }
39105
39460
  async function pipelineExists(taskId) {
39106
39461
  const db = await getDb();
39107
- const result = await db.select({ count: sql9`count(*)` }).from(lifecyclePipelines).where(eq8(lifecyclePipelines.taskId, taskId)).all();
39462
+ const result = await db.select({ count: sql9`count(*)` }).from(lifecyclePipelines).where(eq9(lifecyclePipelines.taskId, taskId)).all();
39108
39463
  return (result[0]?.count || 0) > 0;
39109
39464
  }
39110
39465
  async function getPipelineStatistics() {
@@ -39148,12 +39503,12 @@ async function getPipelineStatistics() {
39148
39503
  }
39149
39504
  async function getPipelineStages(taskId) {
39150
39505
  const db = await getDb();
39151
- const pipelineResult = await db.select({ id: lifecyclePipelines.id }).from(lifecyclePipelines).where(eq8(lifecyclePipelines.taskId, taskId)).limit(1).all();
39506
+ const pipelineResult = await db.select({ id: lifecyclePipelines.id }).from(lifecyclePipelines).where(eq9(lifecyclePipelines.taskId, taskId)).limit(1).all();
39152
39507
  if (pipelineResult.length === 0) {
39153
39508
  throw new CleoError(4 /* NOT_FOUND */, `No pipeline found for task ${taskId}`);
39154
39509
  }
39155
39510
  const pipelineId = pipelineResult[0].id;
39156
- const stages = await db.select().from(lifecycleStages).where(eq8(lifecycleStages.pipelineId, pipelineId)).orderBy(asc3(lifecycleStages.sequence)).all();
39511
+ const stages = await db.select().from(lifecycleStages).where(eq9(lifecycleStages.pipelineId, pipelineId)).orderBy(asc3(lifecycleStages.sequence)).all();
39157
39512
  return stages.map((stage) => ({
39158
39513
  id: stage.id,
39159
39514
  pipelineId: stage.pipelineId,
@@ -45454,9 +45809,9 @@ async function nexusRegister(projectPath, name2, permissions = "read") {
45454
45809
  const projectHash = generateProjectHash(projectPath);
45455
45810
  await nexusInit();
45456
45811
  const { getNexusDb: getNexusDb2 } = await Promise.resolve().then(() => (init_nexus_sqlite(), nexus_sqlite_exports));
45457
- const { eq: eq16 } = await import("drizzle-orm");
45812
+ const { eq: eq17 } = await import("drizzle-orm");
45458
45813
  const db = await getNexusDb2();
45459
- const existingRows = await db.select().from(projectRegistry).where(eq16(projectRegistry.projectHash, projectHash));
45814
+ const existingRows = await db.select().from(projectRegistry).where(eq17(projectRegistry.projectHash, projectHash));
45460
45815
  const existing = existingRows[0];
45461
45816
  if (existing?.permissions) {
45462
45817
  throw new CleoError(
@@ -45465,7 +45820,7 @@ async function nexusRegister(projectPath, name2, permissions = "read") {
45465
45820
  );
45466
45821
  }
45467
45822
  if (!existing) {
45468
- const nameConflictRows = await db.select().from(projectRegistry).where(eq16(projectRegistry.name, projectName));
45823
+ const nameConflictRows = await db.select().from(projectRegistry).where(eq17(projectRegistry.name, projectName));
45469
45824
  if (nameConflictRows.length > 0) {
45470
45825
  throw new CleoError(
45471
45826
  6 /* VALIDATION_ERROR */,
@@ -45483,7 +45838,7 @@ async function nexusRegister(projectPath, name2, permissions = "read") {
45483
45838
  taskCount: meta.taskCount,
45484
45839
  labelsJson: JSON.stringify(meta.labels),
45485
45840
  lastSeen: now2
45486
- }).where(eq16(projectRegistry.projectHash, projectHash));
45841
+ }).where(eq17(projectRegistry.projectHash, projectHash));
45487
45842
  } else {
45488
45843
  if (!projectId) {
45489
45844
  projectId = randomUUID3();
@@ -45521,9 +45876,9 @@ async function nexusUnregister(nameOrHash) {
45521
45876
  throw new CleoError(4 /* NOT_FOUND */, `Project not found in registry: ${nameOrHash}`);
45522
45877
  }
45523
45878
  const { getNexusDb: getNexusDb2 } = await Promise.resolve().then(() => (init_nexus_sqlite(), nexus_sqlite_exports));
45524
- const { eq: eq16 } = await import("drizzle-orm");
45879
+ const { eq: eq17 } = await import("drizzle-orm");
45525
45880
  const db = await getNexusDb2();
45526
- await db.delete(projectRegistry).where(eq16(projectRegistry.projectHash, project.hash));
45881
+ await db.delete(projectRegistry).where(eq17(projectRegistry.projectHash, project.hash));
45527
45882
  await writeNexusAudit({
45528
45883
  action: "unregister",
45529
45884
  projectHash: project.hash,
@@ -45545,9 +45900,9 @@ async function nexusList() {
45545
45900
  async function nexusGetProject(nameOrHash) {
45546
45901
  try {
45547
45902
  const { getNexusDb: getNexusDb2 } = await Promise.resolve().then(() => (init_nexus_sqlite(), nexus_sqlite_exports));
45548
- const { eq: eq16, or: or6 } = await import("drizzle-orm");
45903
+ const { eq: eq17, or: or6 } = await import("drizzle-orm");
45549
45904
  const db = await getNexusDb2();
45550
- const rows = await db.select().from(projectRegistry).where(or6(eq16(projectRegistry.projectHash, nameOrHash), eq16(projectRegistry.name, nameOrHash)));
45905
+ const rows = await db.select().from(projectRegistry).where(or6(eq17(projectRegistry.projectHash, nameOrHash), eq17(projectRegistry.name, nameOrHash)));
45551
45906
  const row = rows[0];
45552
45907
  if (!row) return null;
45553
45908
  return rowToProject(row);
@@ -45570,14 +45925,14 @@ async function nexusSync(nameOrHash) {
45570
45925
  const meta = await readProjectMeta(project.path);
45571
45926
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
45572
45927
  const { getNexusDb: getNexusDb2 } = await Promise.resolve().then(() => (init_nexus_sqlite(), nexus_sqlite_exports));
45573
- const { eq: eq16 } = await import("drizzle-orm");
45928
+ const { eq: eq17 } = await import("drizzle-orm");
45574
45929
  const db = await getNexusDb2();
45575
45930
  await db.update(projectRegistry).set({
45576
45931
  taskCount: meta.taskCount,
45577
45932
  labelsJson: JSON.stringify(meta.labels),
45578
45933
  lastSync: now2,
45579
45934
  lastSeen: now2
45580
- }).where(eq16(projectRegistry.projectHash, project.hash));
45935
+ }).where(eq17(projectRegistry.projectHash, project.hash));
45581
45936
  await writeNexusAudit({
45582
45937
  action: "sync",
45583
45938
  projectHash: project.hash,
@@ -45591,7 +45946,7 @@ async function nexusSyncAll() {
45591
45946
  let synced = 0;
45592
45947
  let failed = 0;
45593
45948
  const { getNexusDb: getNexusDb2 } = await Promise.resolve().then(() => (init_nexus_sqlite(), nexus_sqlite_exports));
45594
- const { eq: eq16 } = await import("drizzle-orm");
45949
+ const { eq: eq17 } = await import("drizzle-orm");
45595
45950
  const db = await getNexusDb2();
45596
45951
  for (const project of projects) {
45597
45952
  try {
@@ -45602,7 +45957,7 @@ async function nexusSyncAll() {
45602
45957
  labelsJson: JSON.stringify(meta.labels),
45603
45958
  lastSync: now2,
45604
45959
  lastSeen: now2
45605
- }).where(eq16(projectRegistry.projectHash, project.hash));
45960
+ }).where(eq17(projectRegistry.projectHash, project.hash));
45606
45961
  synced++;
45607
45962
  } catch {
45608
45963
  failed++;
@@ -45622,9 +45977,9 @@ async function nexusSetPermission(nameOrHash, permission) {
45622
45977
  throw new CleoError(4 /* NOT_FOUND */, `Project not found in registry: ${nameOrHash}`);
45623
45978
  }
45624
45979
  const { getNexusDb: getNexusDb2 } = await Promise.resolve().then(() => (init_nexus_sqlite(), nexus_sqlite_exports));
45625
- const { eq: eq16 } = await import("drizzle-orm");
45980
+ const { eq: eq17 } = await import("drizzle-orm");
45626
45981
  const db = await getNexusDb2();
45627
- await db.update(projectRegistry).set({ permissions: permission }).where(eq16(projectRegistry.projectHash, project.hash));
45982
+ await db.update(projectRegistry).set({ permissions: permission }).where(eq17(projectRegistry.projectHash, project.hash));
45628
45983
  await writeNexusAudit({
45629
45984
  action: "set-permission",
45630
45985
  projectHash: project.hash,
@@ -45640,12 +45995,12 @@ async function nexusReconcile(projectRoot) {
45640
45995
  }
45641
45996
  await nexusInit();
45642
45997
  const { getNexusDb: getNexusDb2 } = await Promise.resolve().then(() => (init_nexus_sqlite(), nexus_sqlite_exports));
45643
- const { eq: eq16 } = await import("drizzle-orm");
45998
+ const { eq: eq17 } = await import("drizzle-orm");
45644
45999
  const db = await getNexusDb2();
45645
46000
  const projectId = await readProjectId(projectRoot);
45646
46001
  const currentHash = generateProjectHash(projectRoot);
45647
46002
  if (projectId) {
45648
- const hashRows2 = await db.select().from(projectRegistry).where(eq16(projectRegistry.projectHash, currentHash));
46003
+ const hashRows2 = await db.select().from(projectRegistry).where(eq17(projectRegistry.projectHash, currentHash));
45649
46004
  const hashMatch2 = hashRows2[0];
45650
46005
  if (hashMatch2 && hashMatch2.projectId !== projectId) {
45651
46006
  await writeNexusAudit({
@@ -45664,12 +46019,12 @@ async function nexusReconcile(projectRoot) {
45664
46019
  }
45665
46020
  }
45666
46021
  if (projectId) {
45667
- const idRows = await db.select().from(projectRegistry).where(eq16(projectRegistry.projectId, projectId));
46022
+ const idRows = await db.select().from(projectRegistry).where(eq17(projectRegistry.projectId, projectId));
45668
46023
  const existing = idRows[0];
45669
46024
  if (existing) {
45670
46025
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
45671
46026
  if (existing.projectPath === projectRoot) {
45672
- await db.update(projectRegistry).set({ lastSeen: now2 }).where(eq16(projectRegistry.projectId, projectId));
46027
+ await db.update(projectRegistry).set({ lastSeen: now2 }).where(eq17(projectRegistry.projectId, projectId));
45673
46028
  await writeNexusAudit({
45674
46029
  action: "reconcile",
45675
46030
  projectHash: currentHash,
@@ -45685,7 +46040,7 @@ async function nexusReconcile(projectRoot) {
45685
46040
  projectPath: projectRoot,
45686
46041
  projectHash: currentHash,
45687
46042
  lastSeen: now2
45688
- }).where(eq16(projectRegistry.projectId, projectId));
46043
+ }).where(eq17(projectRegistry.projectId, projectId));
45689
46044
  await writeNexusAudit({
45690
46045
  action: "reconcile",
45691
46046
  projectHash: currentHash,
@@ -45697,11 +46052,11 @@ async function nexusReconcile(projectRoot) {
45697
46052
  return { status: "path_updated", oldPath, newPath: projectRoot };
45698
46053
  }
45699
46054
  }
45700
- const hashRows = await db.select().from(projectRegistry).where(eq16(projectRegistry.projectHash, currentHash));
46055
+ const hashRows = await db.select().from(projectRegistry).where(eq17(projectRegistry.projectHash, currentHash));
45701
46056
  const hashMatch = hashRows[0];
45702
46057
  if (hashMatch) {
45703
46058
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
45704
- await db.update(projectRegistry).set({ lastSeen: now2 }).where(eq16(projectRegistry.projectHash, currentHash));
46059
+ await db.update(projectRegistry).set({ lastSeen: now2 }).where(eq17(projectRegistry.projectHash, currentHash));
45705
46060
  await writeNexusAudit({
45706
46061
  action: "reconcile",
45707
46062
  projectHash: currentHash,
@@ -46556,6 +46911,30 @@ function collectCleoFiles(cleoDir) {
46556
46911
  walk(cleoDir);
46557
46912
  return files.sort();
46558
46913
  }
46914
+ async function getCleoGitRemotes(cleoDir) {
46915
+ const result = await cleoGitCommand(["remote"], cleoDir);
46916
+ if (!result.success || !result.stdout) return [];
46917
+ return result.stdout.split("\n").map((r) => r.trim()).filter(Boolean);
46918
+ }
46919
+ async function hasCleoGitPendingChanges(cleoDir) {
46920
+ const result = await cleoGitCommand(["status", "--porcelain"], cleoDir);
46921
+ if (!result.success) return false;
46922
+ return result.stdout.length > 0;
46923
+ }
46924
+ async function getLastSyncTimestamp(cleoDir) {
46925
+ const result = await cleoGitCommand(["reflog", "--format=%gs %ci", "HEAD"], cleoDir);
46926
+ if (!result.success || !result.stdout) return null;
46927
+ for (const line2 of result.stdout.split("\n")) {
46928
+ const trimmed = line2.trim();
46929
+ if (/^(fetch|push|pull)\b/i.test(trimmed)) {
46930
+ const isoMatch = trimmed.match(/(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [+-]\d{4})$/);
46931
+ if (isoMatch?.[1]) {
46932
+ return new Date(isoMatch[1]).toISOString();
46933
+ }
46934
+ }
46935
+ }
46936
+ return null;
46937
+ }
46559
46938
  async function getSharingStatus(cwd) {
46560
46939
  const config2 = await loadConfig(cwd);
46561
46940
  const sharing = config2.sharing;
@@ -46572,12 +46951,27 @@ async function getSharingStatus(cwd) {
46572
46951
  ignored.push(file2);
46573
46952
  }
46574
46953
  }
46954
+ const hasGit = isCleoGitInitialized(cleoDir);
46955
+ let remotes = [];
46956
+ let pendingChanges = false;
46957
+ let lastSync = null;
46958
+ if (hasGit) {
46959
+ [remotes, pendingChanges, lastSync] = await Promise.all([
46960
+ getCleoGitRemotes(cleoDir),
46961
+ hasCleoGitPendingChanges(cleoDir),
46962
+ getLastSyncTimestamp(cleoDir)
46963
+ ]);
46964
+ }
46575
46965
  return {
46576
46966
  mode: sharing.mode,
46577
46967
  allowlist: sharing.commitAllowlist,
46578
46968
  denylist: sharing.denylist,
46579
46969
  tracked,
46580
- ignored
46970
+ ignored,
46971
+ hasGit,
46972
+ remotes,
46973
+ pendingChanges,
46974
+ lastSync
46581
46975
  };
46582
46976
  }
46583
46977
  function generateGitignoreEntries(sharing) {
@@ -46629,6 +47023,7 @@ var init_sharing = __esm({
46629
47023
  "use strict";
46630
47024
  init_config();
46631
47025
  init_paths();
47026
+ init_git_checkpoint();
46632
47027
  GITIGNORE_START = "# CLEO:SHARING:START - Auto-managed by cleo sharing sync";
46633
47028
  GITIGNORE_END = "# CLEO:SHARING:END";
46634
47029
  }
@@ -46636,25 +47031,25 @@ var init_sharing = __esm({
46636
47031
 
46637
47032
  // packages/core/src/reconciliation/link-store.ts
46638
47033
  import { randomUUID as randomUUID4 } from "node:crypto";
46639
- import { and as and6, eq as eq9 } from "drizzle-orm";
47034
+ import { and as and7, eq as eq10 } from "drizzle-orm";
46640
47035
  async function getLinksByProvider(providerId, cwd) {
46641
47036
  const db = await getDb(cwd);
46642
- const rows = await db.select().from(externalTaskLinks).where(eq9(externalTaskLinks.providerId, providerId));
47037
+ const rows = await db.select().from(externalTaskLinks).where(eq10(externalTaskLinks.providerId, providerId));
46643
47038
  return rows.map(rowToLink);
46644
47039
  }
46645
47040
  async function getLinkByExternalId(providerId, externalId, cwd) {
46646
47041
  const db = await getDb(cwd);
46647
47042
  const rows = await db.select().from(externalTaskLinks).where(
46648
- and6(
46649
- eq9(externalTaskLinks.providerId, providerId),
46650
- eq9(externalTaskLinks.externalId, externalId)
47043
+ and7(
47044
+ eq10(externalTaskLinks.providerId, providerId),
47045
+ eq10(externalTaskLinks.externalId, externalId)
46651
47046
  )
46652
47047
  );
46653
47048
  return rows.length > 0 ? rowToLink(rows[0]) : null;
46654
47049
  }
46655
47050
  async function getLinksByTaskId(taskId, cwd) {
46656
47051
  const db = await getDb(cwd);
46657
- const rows = await db.select().from(externalTaskLinks).where(eq9(externalTaskLinks.taskId, taskId));
47052
+ const rows = await db.select().from(externalTaskLinks).where(eq10(externalTaskLinks.taskId, taskId));
46658
47053
  return rows.map(rowToLink);
46659
47054
  }
46660
47055
  async function createLink(params, cwd) {
@@ -46698,11 +47093,11 @@ async function touchLink(linkId, updates, cwd) {
46698
47093
  if (updates?.metadata !== void 0) {
46699
47094
  values.metadataJson = JSON.stringify(updates.metadata);
46700
47095
  }
46701
- await db.update(externalTaskLinks).set(values).where(eq9(externalTaskLinks.id, linkId));
47096
+ await db.update(externalTaskLinks).set(values).where(eq10(externalTaskLinks.id, linkId));
46702
47097
  }
46703
47098
  async function removeLinksByProvider(providerId, cwd) {
46704
47099
  const db = await getDb(cwd);
46705
- const result = await db.delete(externalTaskLinks).where(eq9(externalTaskLinks.providerId, providerId));
47100
+ const result = await db.delete(externalTaskLinks).where(eq10(externalTaskLinks.providerId, providerId));
46706
47101
  return Number(result.changes);
46707
47102
  }
46708
47103
  function rowToLink(row) {
@@ -50656,7 +51051,7 @@ import { execFileSync as execFileSync7 } from "node:child_process";
50656
51051
  import { existsSync as existsSync64, renameSync as renameSync5 } from "node:fs";
50657
51052
  import { readFile as readFile12 } from "node:fs/promises";
50658
51053
  import { join as join67 } from "node:path";
50659
- import { and as and7, count, desc as desc4, eq as eq10 } from "drizzle-orm";
51054
+ import { and as and8, count, desc as desc4, eq as eq11 } from "drizzle-orm";
50660
51055
  async function getDb2(cwd) {
50661
51056
  const { getDb: _getDb } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
50662
51057
  return _getDb(cwd);
@@ -50725,7 +51120,7 @@ function rowToManifest(row) {
50725
51120
  }
50726
51121
  async function findLatestPushedVersion(cwd) {
50727
51122
  const db = await getDb2(cwd);
50728
- const rows = await db.select({ version: releaseManifests.version }).from(releaseManifests).where(eq10(releaseManifests.status, "pushed")).orderBy(desc4(releaseManifests.pushedAt)).limit(1).all();
51123
+ const rows = await db.select({ version: releaseManifests.version }).from(releaseManifests).where(eq11(releaseManifests.status, "pushed")).orderBy(desc4(releaseManifests.pushedAt)).limit(1).all();
50729
51124
  return rows[0]?.version;
50730
51125
  }
50731
51126
  async function prepareRelease(version2, tasks2, notes, loadTasksFn, cwd) {
@@ -50737,7 +51132,7 @@ async function prepareRelease(version2, tasks2, notes, loadTasksFn, cwd) {
50737
51132
  }
50738
51133
  const normalizedVersion = normalizeVersion(version2);
50739
51134
  const db = await getDb2(cwd);
50740
- const existing = await db.select().from(releaseManifests).where(eq10(releaseManifests.version, normalizedVersion)).limit(1).all();
51135
+ const existing = await db.select().from(releaseManifests).where(eq11(releaseManifests.version, normalizedVersion)).limit(1).all();
50741
51136
  if (existing.length > 0) {
50742
51137
  throw new Error(`Release ${normalizedVersion} already exists (status: ${existing[0].status})`);
50743
51138
  }
@@ -50777,7 +51172,7 @@ async function generateReleaseChangelog(version2, loadTasksFn, cwd) {
50777
51172
  }
50778
51173
  const normalizedVersion = normalizeVersion(version2);
50779
51174
  const db = await getDb2(cwd);
50780
- const rows = await db.select().from(releaseManifests).where(eq10(releaseManifests.version, normalizedVersion)).limit(1).all();
51175
+ const rows = await db.select().from(releaseManifests).where(eq11(releaseManifests.version, normalizedVersion)).limit(1).all();
50781
51176
  if (rows.length === 0) {
50782
51177
  throw new Error(`Release ${normalizedVersion} not found`);
50783
51178
  }
@@ -50914,7 +51309,7 @@ async function generateReleaseChangelog(version2, loadTasksFn, cwd) {
50914
51309
  sections.push("");
50915
51310
  }
50916
51311
  const changelog = sections.join("\n");
50917
- await db.update(releaseManifests).set({ changelog }).where(eq10(releaseManifests.version, normalizedVersion)).run();
51312
+ await db.update(releaseManifests).set({ changelog }).where(eq11(releaseManifests.version, normalizedVersion)).run();
50918
51313
  const changelogPath = join67(cwd ?? process.cwd(), "CHANGELOG.md");
50919
51314
  let existingChangelogContent = "";
50920
51315
  try {
@@ -50952,8 +51347,8 @@ async function listManifestReleases(optionsOrCwd, cwd) {
50952
51347
  const db = await getDb2(effectiveCwd);
50953
51348
  const totalRow = await db.select({ count: count() }).from(releaseManifests).get();
50954
51349
  const total = totalRow?.count ?? 0;
50955
- const conditions = options.status ? [eq10(releaseManifests.status, options.status)] : [];
50956
- const whereClause = conditions.length > 0 ? and7(...conditions) : void 0;
51350
+ const conditions = options.status ? [eq11(releaseManifests.status, options.status)] : [];
51351
+ const whereClause = conditions.length > 0 ? and8(...conditions) : void 0;
50957
51352
  const filteredRow = await db.select({ count: count() }).from(releaseManifests).where(whereClause).get();
50958
51353
  const filtered = filteredRow?.count ?? 0;
50959
51354
  let query = db.select().from(releaseManifests).where(whereClause).orderBy(desc4(releaseManifests.createdAt));
@@ -50984,7 +51379,7 @@ async function showManifestRelease(version2, cwd) {
50984
51379
  }
50985
51380
  const normalizedVersion = normalizeVersion(version2);
50986
51381
  const db = await getDb2(cwd);
50987
- const rows = await db.select().from(releaseManifests).where(eq10(releaseManifests.version, normalizedVersion)).limit(1).all();
51382
+ const rows = await db.select().from(releaseManifests).where(eq11(releaseManifests.version, normalizedVersion)).limit(1).all();
50988
51383
  if (rows.length === 0) {
50989
51384
  throw new Error(`Release ${normalizedVersion} not found`);
50990
51385
  }
@@ -50996,7 +51391,7 @@ async function commitRelease(version2, cwd) {
50996
51391
  }
50997
51392
  const normalizedVersion = normalizeVersion(version2);
50998
51393
  const db = await getDb2(cwd);
50999
- const rows = await db.select().from(releaseManifests).where(eq10(releaseManifests.version, normalizedVersion)).limit(1).all();
51394
+ const rows = await db.select().from(releaseManifests).where(eq11(releaseManifests.version, normalizedVersion)).limit(1).all();
51000
51395
  if (rows.length === 0) {
51001
51396
  throw new Error(`Release ${normalizedVersion} not found`);
51002
51397
  }
@@ -51006,7 +51401,7 @@ async function commitRelease(version2, cwd) {
51006
51401
  );
51007
51402
  }
51008
51403
  const committedAt = (/* @__PURE__ */ new Date()).toISOString();
51009
- await db.update(releaseManifests).set({ status: "committed", committedAt }).where(eq10(releaseManifests.version, normalizedVersion)).run();
51404
+ await db.update(releaseManifests).set({ status: "committed", committedAt }).where(eq11(releaseManifests.version, normalizedVersion)).run();
51010
51405
  return { version: normalizedVersion, status: "committed", committedAt };
51011
51406
  }
51012
51407
  async function tagRelease(version2, cwd) {
@@ -51015,12 +51410,12 @@ async function tagRelease(version2, cwd) {
51015
51410
  }
51016
51411
  const normalizedVersion = normalizeVersion(version2);
51017
51412
  const db = await getDb2(cwd);
51018
- const rows = await db.select().from(releaseManifests).where(eq10(releaseManifests.version, normalizedVersion)).limit(1).all();
51413
+ const rows = await db.select().from(releaseManifests).where(eq11(releaseManifests.version, normalizedVersion)).limit(1).all();
51019
51414
  if (rows.length === 0) {
51020
51415
  throw new Error(`Release ${normalizedVersion} not found`);
51021
51416
  }
51022
51417
  const taggedAt = (/* @__PURE__ */ new Date()).toISOString();
51023
- await db.update(releaseManifests).set({ status: "tagged", taggedAt }).where(eq10(releaseManifests.version, normalizedVersion)).run();
51418
+ await db.update(releaseManifests).set({ status: "tagged", taggedAt }).where(eq11(releaseManifests.version, normalizedVersion)).run();
51024
51419
  return { version: normalizedVersion, status: "tagged", taggedAt };
51025
51420
  }
51026
51421
  async function runReleaseGates(version2, loadTasksFn, cwd, opts) {
@@ -51029,7 +51424,7 @@ async function runReleaseGates(version2, loadTasksFn, cwd, opts) {
51029
51424
  }
51030
51425
  const normalizedVersion = normalizeVersion(version2);
51031
51426
  const db = await getDb2(cwd);
51032
- const rows = await db.select().from(releaseManifests).where(eq10(releaseManifests.version, normalizedVersion)).limit(1).all();
51427
+ const rows = await db.select().from(releaseManifests).where(eq11(releaseManifests.version, normalizedVersion)).limit(1).all();
51033
51428
  if (rows.length === 0) {
51034
51429
  throw new Error(`Release ${normalizedVersion} not found`);
51035
51430
  }
@@ -51177,7 +51572,7 @@ async function cancelRelease(version2, projectRoot) {
51177
51572
  }
51178
51573
  const normalizedVersion = normalizeVersion(version2);
51179
51574
  const db = await getDb2(projectRoot);
51180
- const rows = await db.select().from(releaseManifests).where(eq10(releaseManifests.version, normalizedVersion)).limit(1).all();
51575
+ const rows = await db.select().from(releaseManifests).where(eq11(releaseManifests.version, normalizedVersion)).limit(1).all();
51181
51576
  if (rows.length === 0) {
51182
51577
  return {
51183
51578
  success: false,
@@ -51194,7 +51589,7 @@ async function cancelRelease(version2, projectRoot) {
51194
51589
  version: normalizedVersion
51195
51590
  };
51196
51591
  }
51197
- await db.delete(releaseManifests).where(eq10(releaseManifests.version, normalizedVersion)).run();
51592
+ await db.delete(releaseManifests).where(eq11(releaseManifests.version, normalizedVersion)).run();
51198
51593
  return {
51199
51594
  success: true,
51200
51595
  message: `Release ${normalizedVersion} cancelled and removed`,
@@ -51207,12 +51602,12 @@ async function rollbackRelease(version2, reason, cwd) {
51207
51602
  }
51208
51603
  const normalizedVersion = normalizeVersion(version2);
51209
51604
  const db = await getDb2(cwd);
51210
- const rows = await db.select().from(releaseManifests).where(eq10(releaseManifests.version, normalizedVersion)).limit(1).all();
51605
+ const rows = await db.select().from(releaseManifests).where(eq11(releaseManifests.version, normalizedVersion)).limit(1).all();
51211
51606
  if (rows.length === 0) {
51212
51607
  throw new Error(`Release ${normalizedVersion} not found`);
51213
51608
  }
51214
51609
  const previousStatus = rows[0].status;
51215
- await db.update(releaseManifests).set({ status: "rolled_back" }).where(eq10(releaseManifests.version, normalizedVersion)).run();
51610
+ await db.update(releaseManifests).set({ status: "rolled_back" }).where(eq11(releaseManifests.version, normalizedVersion)).run();
51216
51611
  return {
51217
51612
  version: normalizedVersion,
51218
51613
  previousStatus,
@@ -51322,7 +51717,7 @@ async function markReleasePushed(version2, pushedAt, cwd, provenance) {
51322
51717
  pushedAt,
51323
51718
  ...provenance?.commitSha != null ? { commitSha: provenance.commitSha } : {},
51324
51719
  ...provenance?.gitTag != null ? { gitTag: provenance.gitTag } : {}
51325
- }).where(eq10(releaseManifests.version, normalizedVersion)).run();
51720
+ }).where(eq11(releaseManifests.version, normalizedVersion)).run();
51326
51721
  }
51327
51722
  async function migrateReleasesJsonToSqlite(projectRoot) {
51328
51723
  const releasesPath = join67(getCleoDirAbsolute(projectRoot), "releases.json");
@@ -51342,7 +51737,7 @@ async function migrateReleasesJsonToSqlite(projectRoot) {
51342
51737
  const db = await getDb2(projectRoot);
51343
51738
  let migrated = 0;
51344
51739
  for (const r of raw.releases) {
51345
- const existing = await db.select({ id: releaseManifests.id }).from(releaseManifests).where(eq10(releaseManifests.version, r.version)).limit(1).all();
51740
+ const existing = await db.select({ id: releaseManifests.id }).from(releaseManifests).where(eq11(releaseManifests.version, r.version)).limit(1).all();
51346
51741
  if (existing.length > 0) continue;
51347
51742
  const id = `rel-${r.version.replace(/[^a-z0-9]/gi, "-")}`;
51348
51743
  await db.insert(releaseManifests).values({
@@ -57098,7 +57493,7 @@ async function queryTasks(cwd, since) {
57098
57493
  try {
57099
57494
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
57100
57495
  const { tasks: tasks2 } = await Promise.resolve().then(() => (init_tasks_schema(), tasks_schema_exports));
57101
- const { and: and11, gte: gte4 } = await import("drizzle-orm");
57496
+ const { and: and12, gte: gte4 } = await import("drizzle-orm");
57102
57497
  const db = await getDb4(cwd);
57103
57498
  const conditions = [];
57104
57499
  if (since) {
@@ -57112,7 +57507,7 @@ async function queryTasks(cwd, since) {
57112
57507
  sessionId: tasks2.sessionId,
57113
57508
  completedAt: tasks2.completedAt,
57114
57509
  createdAt: tasks2.createdAt
57115
- }).from(tasks2).where(conditions.length > 0 ? and11(...conditions) : void 0).all();
57510
+ }).from(tasks2).where(conditions.length > 0 ? and12(...conditions) : void 0).all();
57116
57511
  return rows;
57117
57512
  } catch (err) {
57118
57513
  log7.warn({ err }, "Failed to query tasks for workflow telemetry");
@@ -57123,7 +57518,7 @@ async function queryCompletionAuditRows(cwd, since) {
57123
57518
  try {
57124
57519
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
57125
57520
  const { auditLog: auditLog2 } = await Promise.resolve().then(() => (init_tasks_schema(), tasks_schema_exports));
57126
- const { and: and11, gte: gte4 } = await import("drizzle-orm");
57521
+ const { and: and12, gte: gte4 } = await import("drizzle-orm");
57127
57522
  const db = await getDb4(cwd);
57128
57523
  const conditions = [];
57129
57524
  if (since) conditions.push(gte4(auditLog2.timestamp, since));
@@ -57135,7 +57530,7 @@ async function queryCompletionAuditRows(cwd, since) {
57135
57530
  afterJson: auditLog2.afterJson,
57136
57531
  operation: auditLog2.operation,
57137
57532
  domain: auditLog2.domain
57138
- }).from(auditLog2).where(conditions.length > 0 ? and11(...conditions) : void 0).orderBy(auditLog2.timestamp).all();
57533
+ }).from(auditLog2).where(conditions.length > 0 ? and12(...conditions) : void 0).orderBy(auditLog2.timestamp).all();
57139
57534
  return allRows.filter((row) => {
57140
57535
  const isComplete = row.action === "task_completed" || row.action === "complete" || row.operation === "complete" && row.domain === "tasks";
57141
57536
  if (!isComplete && row.afterJson) {
@@ -67037,6 +67432,7 @@ var init_src2 = __esm({
67037
67432
  init_inject();
67038
67433
  init_intelligence();
67039
67434
  init_issue();
67435
+ init_lib();
67040
67436
  init_lifecycle2();
67041
67437
  init_mcp();
67042
67438
  init_memory();
@@ -68426,9 +68822,9 @@ async function addChain(chain, projectRoot) {
68426
68822
  }
68427
68823
  async function showChain(id, projectRoot) {
68428
68824
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
68429
- const { eq: eq16 } = await import("drizzle-orm");
68825
+ const { eq: eq17 } = await import("drizzle-orm");
68430
68826
  const db = await getDb4(projectRoot);
68431
- const rows = await db.select().from(warpChains).where(eq16(warpChains.id, id));
68827
+ const rows = await db.select().from(warpChains).where(eq17(warpChains.id, id));
68432
68828
  if (rows.length === 0) return null;
68433
68829
  return JSON.parse(rows[0].definition);
68434
68830
  }
@@ -68475,9 +68871,9 @@ async function createInstance(params, projectRoot) {
68475
68871
  }
68476
68872
  async function showInstance(id, projectRoot) {
68477
68873
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
68478
- const { eq: eq16 } = await import("drizzle-orm");
68874
+ const { eq: eq17 } = await import("drizzle-orm");
68479
68875
  const db = await getDb4(projectRoot);
68480
- const rows = await db.select().from(warpChainInstances).where(eq16(warpChainInstances.id, id));
68876
+ const rows = await db.select().from(warpChainInstances).where(eq17(warpChainInstances.id, id));
68481
68877
  if (rows.length === 0) return null;
68482
68878
  const row = rows[0];
68483
68879
  return {
@@ -68523,11 +68919,11 @@ async function advanceInstance(id, nextStage, gateResults, projectRoot) {
68523
68919
  }
68524
68920
  }
68525
68921
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
68526
- const { eq: eq16 } = await import("drizzle-orm");
68922
+ const { eq: eq17 } = await import("drizzle-orm");
68527
68923
  const db = await getDb4(projectRoot);
68528
68924
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
68529
68925
  const existingResults = [];
68530
- const row = (await db.select().from(warpChainInstances).where(eq16(warpChainInstances.id, id)))[0];
68926
+ const row = (await db.select().from(warpChainInstances).where(eq17(warpChainInstances.id, id)))[0];
68531
68927
  if (row?.gateResults) {
68532
68928
  existingResults.push(...JSON.parse(row.gateResults));
68533
68929
  }
@@ -68537,7 +68933,7 @@ async function advanceInstance(id, nextStage, gateResults, projectRoot) {
68537
68933
  gateResults: JSON.stringify(allResults),
68538
68934
  status: "active",
68539
68935
  updatedAt: now2
68540
- }).where(eq16(warpChainInstances.id, id));
68936
+ }).where(eq17(warpChainInstances.id, id));
68541
68937
  return {
68542
68938
  ...instance,
68543
68939
  currentStage: nextStage,
@@ -70229,7 +70625,7 @@ var init_engine_compat = __esm({
70229
70625
  import { createHash as createHash12 } from "node:crypto";
70230
70626
  import { existsSync as existsSync106, readFileSync as readFileSync78, renameSync as renameSync7 } from "node:fs";
70231
70627
  import { join as join105 } from "node:path";
70232
- import { and as and8, count as count2, desc as desc5, eq as eq11, gte as gte3, isNull as isNull3, like as like3, lte as lte2, or as or4 } from "drizzle-orm";
70628
+ import { and as and9, count as count2, desc as desc5, eq as eq12, gte as gte3, isNull as isNull3, like as like3, lte as lte2, or as or4 } from "drizzle-orm";
70233
70629
  async function getDb3(cwd) {
70234
70630
  const { getDb: _getDb } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
70235
70631
  return _getDb(cwd);
@@ -70251,10 +70647,10 @@ function buildManifestSqlFilters(filter) {
70251
70647
  const conditions = [isNull3(pipelineManifest.archivedAt)];
70252
70648
  if (filter.status) {
70253
70649
  const storedStatus = filter.status === "completed" ? "active" : filter.status;
70254
- conditions.push(eq11(pipelineManifest.status, storedStatus));
70650
+ conditions.push(eq12(pipelineManifest.status, storedStatus));
70255
70651
  }
70256
70652
  if (filter.agent_type) {
70257
- conditions.push(eq11(pipelineManifest.type, filter.agent_type));
70653
+ conditions.push(eq12(pipelineManifest.type, filter.agent_type));
70258
70654
  }
70259
70655
  if (filter.dateAfter) {
70260
70656
  conditions.push(gte3(pipelineManifest.createdAt, `${filter.dateAfter} 00:00:00`));
@@ -70347,7 +70743,7 @@ async function pipelineManifestShow(researchId, projectRoot) {
70347
70743
  }
70348
70744
  try {
70349
70745
  const db = await getDb3(projectRoot);
70350
- const rows = await db.select().from(pipelineManifest).where(eq11(pipelineManifest.id, researchId)).limit(1);
70746
+ const rows = await db.select().from(pipelineManifest).where(eq12(pipelineManifest.id, researchId)).limit(1);
70351
70747
  if (rows.length === 0) {
70352
70748
  return {
70353
70749
  success: false,
@@ -70389,7 +70785,7 @@ async function pipelineManifestList(params, projectRoot) {
70389
70785
  const offset = normalizeOffset2(params.offset);
70390
70786
  const pageLimit = effectivePageLimit2(limit, offset);
70391
70787
  const { conditions, requiresInMemoryFiltering } = buildManifestSqlFilters(filter);
70392
- const whereClause = and8(...conditions);
70788
+ const whereClause = and9(...conditions);
70393
70789
  const totalRow = await db.select({ count: count2() }).from(pipelineManifest).where(isNull3(pipelineManifest.archivedAt)).get();
70394
70790
  const total = totalRow?.count ?? 0;
70395
70791
  if (!requiresInMemoryFiltering) {
@@ -70437,7 +70833,7 @@ async function pipelineManifestFind(query, options, projectRoot) {
70437
70833
  const db = await getDb3(projectRoot);
70438
70834
  const likePattern = `%${query}%`;
70439
70835
  const rows = await db.select().from(pipelineManifest).where(
70440
- and8(
70836
+ and9(
70441
70837
  isNull3(pipelineManifest.archivedAt),
70442
70838
  or4(like3(pipelineManifest.content, likePattern), like3(pipelineManifest.type, likePattern))
70443
70839
  )
@@ -70630,7 +71026,7 @@ async function pipelineManifestArchive(beforeDate, projectRoot) {
70630
71026
  }
70631
71027
  const archivedAt = now();
70632
71028
  for (const row of toArchive) {
70633
- await db.update(pipelineManifest).set({ archivedAt }).where(eq11(pipelineManifest.id, row.id));
71029
+ await db.update(pipelineManifest).set({ archivedAt }).where(eq12(pipelineManifest.id, row.id));
70634
71030
  }
70635
71031
  const remaining = rows.length - toArchive.length;
70636
71032
  return { success: true, data: { archived: toArchive.length, remaining } };
@@ -70979,25 +71375,25 @@ async function measureTokenExchange(input) {
70979
71375
  );
70980
71376
  }
70981
71377
  async function whereClauses(filters) {
70982
- const { eq: eq16, gte: gte4, lte: lte3 } = await import("drizzle-orm");
71378
+ const { eq: eq17, gte: gte4, lte: lte3 } = await import("drizzle-orm");
70983
71379
  const clauses = [];
70984
- if (filters.provider) clauses.push(eq16(tokenUsage.provider, filters.provider));
70985
- if (filters.transport) clauses.push(eq16(tokenUsage.transport, filters.transport));
70986
- if (filters.gateway) clauses.push(eq16(tokenUsage.gateway, filters.gateway));
70987
- if (filters.domain) clauses.push(eq16(tokenUsage.domain, filters.domain));
70988
- if (filters.operation) clauses.push(eq16(tokenUsage.operation, filters.operation));
70989
- if (filters.sessionId) clauses.push(eq16(tokenUsage.sessionId, filters.sessionId));
70990
- if (filters.taskId) clauses.push(eq16(tokenUsage.taskId, filters.taskId));
70991
- if (filters.method) clauses.push(eq16(tokenUsage.method, filters.method));
70992
- if (filters.confidence) clauses.push(eq16(tokenUsage.confidence, filters.confidence));
70993
- if (filters.requestId) clauses.push(eq16(tokenUsage.requestId, filters.requestId));
71380
+ if (filters.provider) clauses.push(eq17(tokenUsage.provider, filters.provider));
71381
+ if (filters.transport) clauses.push(eq17(tokenUsage.transport, filters.transport));
71382
+ if (filters.gateway) clauses.push(eq17(tokenUsage.gateway, filters.gateway));
71383
+ if (filters.domain) clauses.push(eq17(tokenUsage.domain, filters.domain));
71384
+ if (filters.operation) clauses.push(eq17(tokenUsage.operation, filters.operation));
71385
+ if (filters.sessionId) clauses.push(eq17(tokenUsage.sessionId, filters.sessionId));
71386
+ if (filters.taskId) clauses.push(eq17(tokenUsage.taskId, filters.taskId));
71387
+ if (filters.method) clauses.push(eq17(tokenUsage.method, filters.method));
71388
+ if (filters.confidence) clauses.push(eq17(tokenUsage.confidence, filters.confidence));
71389
+ if (filters.requestId) clauses.push(eq17(tokenUsage.requestId, filters.requestId));
70994
71390
  if (filters.since) clauses.push(gte4(tokenUsage.createdAt, filters.since));
70995
71391
  if (filters.until) clauses.push(lte3(tokenUsage.createdAt, filters.until));
70996
71392
  return clauses;
70997
71393
  }
70998
71394
  async function recordTokenExchange(input) {
70999
71395
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
71000
- const { eq: eq16 } = await import("drizzle-orm");
71396
+ const { eq: eq17 } = await import("drizzle-orm");
71001
71397
  const measurement = await measureTokenExchange(input);
71002
71398
  const db = await getDb4(input.cwd);
71003
71399
  const row = {
@@ -71026,22 +71422,22 @@ async function recordTokenExchange(input) {
71026
71422
  })
71027
71423
  };
71028
71424
  await db.insert(tokenUsage).values(row);
71029
- const inserted = await db.select().from(tokenUsage).where(eq16(tokenUsage.id, row.id)).limit(1);
71425
+ const inserted = await db.select().from(tokenUsage).where(eq17(tokenUsage.id, row.id)).limit(1);
71030
71426
  return inserted[0];
71031
71427
  }
71032
71428
  async function showTokenUsage(id, cwd) {
71033
71429
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
71034
- const { eq: eq16 } = await import("drizzle-orm");
71430
+ const { eq: eq17 } = await import("drizzle-orm");
71035
71431
  const db = await getDb4(cwd);
71036
- const rows = await db.select().from(tokenUsage).where(eq16(tokenUsage.id, id)).limit(1);
71432
+ const rows = await db.select().from(tokenUsage).where(eq17(tokenUsage.id, id)).limit(1);
71037
71433
  return rows[0] ?? null;
71038
71434
  }
71039
71435
  async function listTokenUsage(filters = {}, cwd) {
71040
71436
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
71041
- const { and: and11, count: count4, desc: desc7 } = await import("drizzle-orm");
71437
+ const { and: and12, count: count4, desc: desc7 } = await import("drizzle-orm");
71042
71438
  const db = await getDb4(cwd);
71043
71439
  const clauses = await whereClauses(filters);
71044
- const where = clauses.length > 0 ? and11(...clauses) : void 0;
71440
+ const where = clauses.length > 0 ? and12(...clauses) : void 0;
71045
71441
  const totalRows = await db.select({ count: count4() }).from(tokenUsage);
71046
71442
  const filteredRows = await db.select({ count: count4() }).from(tokenUsage).where(where);
71047
71443
  let query = db.select().from(tokenUsage).orderBy(desc7(tokenUsage.createdAt));
@@ -71057,10 +71453,10 @@ async function listTokenUsage(filters = {}, cwd) {
71057
71453
  }
71058
71454
  async function summarizeTokenUsage(filters = {}, cwd) {
71059
71455
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
71060
- const { and: and11, desc: desc7 } = await import("drizzle-orm");
71456
+ const { and: and12, desc: desc7 } = await import("drizzle-orm");
71061
71457
  const db = await getDb4(cwd);
71062
71458
  const clauses = await whereClauses(filters);
71063
- const where = clauses.length > 0 ? and11(...clauses) : void 0;
71459
+ const where = clauses.length > 0 ? and12(...clauses) : void 0;
71064
71460
  const rows = await db.select().from(tokenUsage).where(where).orderBy(desc7(tokenUsage.createdAt));
71065
71461
  const byMethod = /* @__PURE__ */ new Map();
71066
71462
  const byTransport = /* @__PURE__ */ new Map();
@@ -71101,17 +71497,17 @@ async function summarizeTokenUsage(filters = {}, cwd) {
71101
71497
  }
71102
71498
  async function deleteTokenUsage(id, cwd) {
71103
71499
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
71104
- const { eq: eq16 } = await import("drizzle-orm");
71500
+ const { eq: eq17 } = await import("drizzle-orm");
71105
71501
  const db = await getDb4(cwd);
71106
- await db.delete(tokenUsage).where(eq16(tokenUsage.id, id));
71502
+ await db.delete(tokenUsage).where(eq17(tokenUsage.id, id));
71107
71503
  return { deleted: true, id };
71108
71504
  }
71109
71505
  async function clearTokenUsage(filters = {}, cwd) {
71110
71506
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
71111
- const { and: and11, count: count4 } = await import("drizzle-orm");
71507
+ const { and: and12, count: count4 } = await import("drizzle-orm");
71112
71508
  const db = await getDb4(cwd);
71113
71509
  const clauses = await whereClauses(filters);
71114
- const where = clauses.length > 0 ? and11(...clauses) : void 0;
71510
+ const where = clauses.length > 0 ? and12(...clauses) : void 0;
71115
71511
  const countRows = await db.select({ count: count4() }).from(tokenUsage).where(where);
71116
71512
  await db.delete(tokenUsage).where(where);
71117
71513
  return { deleted: countRows[0]?.count ?? 0 };
@@ -71522,7 +71918,7 @@ __export(session_store_exports, {
71522
71918
  updateSession: () => updateSession,
71523
71919
  workHistory: () => workHistory
71524
71920
  });
71525
- import { and as and9, desc as desc6, eq as eq12, isNull as isNull4 } from "drizzle-orm";
71921
+ import { and as and10, desc as desc6, eq as eq13, isNull as isNull4 } from "drizzle-orm";
71526
71922
  async function createSession(session, cwd) {
71527
71923
  const db = await getDb(cwd);
71528
71924
  const tw = session.taskWork;
@@ -71544,7 +71940,7 @@ async function createSession(session, cwd) {
71544
71940
  }
71545
71941
  async function getSession(sessionId, cwd) {
71546
71942
  const db = await getDb(cwd);
71547
- const rows = await db.select().from(sessions).where(eq12(sessions.id, sessionId)).all();
71943
+ const rows = await db.select().from(sessions).where(eq13(sessions.id, sessionId)).all();
71548
71944
  if (rows.length === 0) return null;
71549
71945
  return rowToSession(rows[0]);
71550
71946
  }
@@ -71573,16 +71969,16 @@ async function updateSession(sessionId, updates, cwd) {
71573
71969
  updateRow.handoffConsumedBy = updates.handoffConsumedBy;
71574
71970
  if (updates.debriefJson !== void 0) updateRow.debriefJson = updates.debriefJson;
71575
71971
  if (updates.handoffJson !== void 0) updateRow.handoffJson = updates.handoffJson;
71576
- db.update(sessions).set(updateRow).where(eq12(sessions.id, sessionId)).run();
71972
+ db.update(sessions).set(updateRow).where(eq13(sessions.id, sessionId)).run();
71577
71973
  return getSession(sessionId, cwd);
71578
71974
  }
71579
71975
  async function listSessions2(filters, cwd) {
71580
71976
  const db = await getDb(cwd);
71581
71977
  const conditions = [];
71582
71978
  if (filters?.active) {
71583
- conditions.push(eq12(sessions.status, "active"));
71979
+ conditions.push(eq13(sessions.status, "active"));
71584
71980
  }
71585
- const query = db.select().from(sessions).where(conditions.length > 0 ? and9(...conditions) : void 0).orderBy(desc6(sessions.startedAt));
71981
+ const query = db.select().from(sessions).where(conditions.length > 0 ? and10(...conditions) : void 0).orderBy(desc6(sessions.startedAt));
71586
71982
  const rows = filters?.limit ? await query.limit(filters.limit).all() : await query.all();
71587
71983
  return rows.map(rowToSession);
71588
71984
  }
@@ -71604,20 +72000,20 @@ async function startTask2(sessionId, taskId, cwd) {
71604
72000
  const db = await getDb(cwd);
71605
72001
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
71606
72002
  db.update(taskWorkHistory).set({ clearedAt: now2 }).where(
71607
- and9(
71608
- eq12(taskWorkHistory.sessionId, sessionId),
72003
+ and10(
72004
+ eq13(taskWorkHistory.sessionId, sessionId),
71609
72005
  isNull4(taskWorkHistory.clearedAt)
71610
72006
  )
71611
72007
  ).run();
71612
72008
  db.insert(taskWorkHistory).values({ sessionId, taskId, setAt: now2 }).run();
71613
- db.update(sessions).set({ currentTask: taskId, taskStartedAt: now2 }).where(eq12(sessions.id, sessionId)).run();
72009
+ db.update(sessions).set({ currentTask: taskId, taskStartedAt: now2 }).where(eq13(sessions.id, sessionId)).run();
71614
72010
  }
71615
72011
  async function getCurrentTask(sessionId, cwd) {
71616
72012
  const db = await getDb(cwd);
71617
72013
  const rows = await db.select({
71618
72014
  currentTask: sessions.currentTask,
71619
72015
  taskStartedAt: sessions.taskStartedAt
71620
- }).from(sessions).where(eq12(sessions.id, sessionId)).all();
72016
+ }).from(sessions).where(eq13(sessions.id, sessionId)).all();
71621
72017
  if (rows.length === 0) return { taskId: null, since: null };
71622
72018
  return { taskId: rows[0].currentTask, since: rows[0].taskStartedAt };
71623
72019
  }
@@ -71625,16 +72021,16 @@ async function stopTask2(sessionId, cwd) {
71625
72021
  const db = await getDb(cwd);
71626
72022
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
71627
72023
  db.update(taskWorkHistory).set({ clearedAt: now2 }).where(
71628
- and9(
71629
- eq12(taskWorkHistory.sessionId, sessionId),
72024
+ and10(
72025
+ eq13(taskWorkHistory.sessionId, sessionId),
71630
72026
  isNull4(taskWorkHistory.clearedAt)
71631
72027
  )
71632
72028
  ).run();
71633
- db.update(sessions).set({ currentTask: null, taskStartedAt: null }).where(eq12(sessions.id, sessionId)).run();
72029
+ db.update(sessions).set({ currentTask: null, taskStartedAt: null }).where(eq13(sessions.id, sessionId)).run();
71634
72030
  }
71635
72031
  async function workHistory(sessionId, limit = 50, cwd) {
71636
72032
  const db = await getDb(cwd);
71637
- const rows = await db.select().from(taskWorkHistory).where(eq12(taskWorkHistory.sessionId, sessionId)).orderBy(desc6(taskWorkHistory.setAt), desc6(taskWorkHistory.id)).limit(limit).all();
72033
+ const rows = await db.select().from(taskWorkHistory).where(eq13(taskWorkHistory.sessionId, sessionId)).orderBy(desc6(taskWorkHistory.setAt), desc6(taskWorkHistory.id)).limit(limit).all();
71638
72034
  return rows.map((r) => ({
71639
72035
  taskId: r.taskId,
71640
72036
  setAt: r.setAt,
@@ -71645,16 +72041,16 @@ async function gcSessions2(maxAgeDays = 30, cwd) {
71645
72041
  const db = await getDb(cwd);
71646
72042
  const threshold = /* @__PURE__ */ new Date();
71647
72043
  threshold.setDate(threshold.getDate() - maxAgeDays);
71648
- const before = await db.select({ id: sessions.id }).from(sessions).where(and9(eq12(sessions.status, "ended"))).all();
72044
+ const before = await db.select({ id: sessions.id }).from(sessions).where(and10(eq13(sessions.status, "ended"))).all();
71649
72045
  const toUpdate = before;
71650
72046
  if (toUpdate.length > 0) {
71651
- db.update(sessions).set({ status: "orphaned" }).where(eq12(sessions.status, "ended")).run();
72047
+ db.update(sessions).set({ status: "orphaned" }).where(eq13(sessions.status, "ended")).run();
71652
72048
  }
71653
72049
  return toUpdate.length;
71654
72050
  }
71655
72051
  async function getActiveSession(cwd) {
71656
72052
  const db = await getDb(cwd);
71657
- const rows = await db.select().from(sessions).where(eq12(sessions.status, "active")).orderBy(desc6(sessions.startedAt)).limit(1).all();
72053
+ const rows = await db.select().from(sessions).where(eq13(sessions.status, "active")).orderBy(desc6(sessions.startedAt)).limit(1).all();
71658
72054
  if (rows.length === 0) return null;
71659
72055
  return rowToSession(rows[0]);
71660
72056
  }
@@ -71668,7 +72064,7 @@ var init_session_store = __esm({
71668
72064
  });
71669
72065
 
71670
72066
  // packages/core/src/store/cross-db-cleanup.ts
71671
- import { eq as eq13, or as or5 } from "drizzle-orm";
72067
+ import { eq as eq14, or as or5 } from "drizzle-orm";
71672
72068
  async function cleanupBrainRefsOnTaskDelete(taskId, cwd) {
71673
72069
  let brainDb = null;
71674
72070
  try {
@@ -71678,16 +72074,16 @@ async function cleanupBrainRefsOnTaskDelete(taskId, cwd) {
71678
72074
  }
71679
72075
  const nodeId = `task:${taskId}`;
71680
72076
  try {
71681
- await brainDb.update(brainDecisions).set({ contextEpicId: null }).where(eq13(brainDecisions.contextEpicId, taskId));
71682
- await brainDb.update(brainDecisions).set({ contextTaskId: null }).where(eq13(brainDecisions.contextTaskId, taskId));
71683
- await brainDb.delete(brainMemoryLinks).where(eq13(brainMemoryLinks.taskId, taskId));
72077
+ await brainDb.update(brainDecisions).set({ contextEpicId: null }).where(eq14(brainDecisions.contextEpicId, taskId));
72078
+ await brainDb.update(brainDecisions).set({ contextTaskId: null }).where(eq14(brainDecisions.contextTaskId, taskId));
72079
+ await brainDb.delete(brainMemoryLinks).where(eq14(brainMemoryLinks.taskId, taskId));
71684
72080
  await brainDb.delete(brainPageEdges).where(
71685
72081
  or5(
71686
- eq13(brainPageEdges.fromId, nodeId),
71687
- eq13(brainPageEdges.toId, nodeId)
72082
+ eq14(brainPageEdges.fromId, nodeId),
72083
+ eq14(brainPageEdges.toId, nodeId)
71688
72084
  )
71689
72085
  );
71690
- await brainDb.delete(brainPageNodes).where(eq13(brainPageNodes.id, nodeId));
72086
+ await brainDb.delete(brainPageNodes).where(eq14(brainPageNodes.id, nodeId));
71691
72087
  } catch {
71692
72088
  }
71693
72089
  }
@@ -71700,12 +72096,12 @@ var init_cross_db_cleanup = __esm({
71700
72096
  });
71701
72097
 
71702
72098
  // packages/core/src/store/data-safety.ts
71703
- import { eq as eq14 } from "drizzle-orm";
72099
+ import { eq as eq15 } from "drizzle-orm";
71704
72100
  async function checkTaskExists(taskId, cwd, config2 = {}) {
71705
72101
  const cfg = { ...DEFAULT_CONFIG2, ...config2 };
71706
72102
  if (!cfg.detectCollisions) return false;
71707
72103
  const db = await getDb(cwd);
71708
- const existing = await db.select().from(tasks).where(eq14(tasks.id, taskId)).all();
72104
+ const existing = await db.select().from(tasks).where(eq15(tasks.id, taskId)).all();
71709
72105
  const exists2 = existing.length > 0;
71710
72106
  if (exists2 && cfg.strictMode) {
71711
72107
  throw new SafetyError(
@@ -71853,7 +72249,7 @@ __export(task_store_exports, {
71853
72249
  updateTask: () => updateTask2,
71854
72250
  updateTaskSafe: () => updateTaskSafe
71855
72251
  });
71856
- import { and as and10, asc as asc4, count as count3, eq as eq15, inArray as inArray5, isNull as isNull5, ne as ne3, sql as sql11 } from "drizzle-orm";
72252
+ import { and as and11, asc as asc4, count as count3, eq as eq16, inArray as inArray6, isNull as isNull5, ne as ne3, sql as sql11 } from "drizzle-orm";
71857
72253
  async function insertTaskRow(task, cwd) {
71858
72254
  const db = await getDb(cwd);
71859
72255
  const row = taskToRow(task);
@@ -71867,10 +72263,10 @@ async function insertTaskRow(task, cwd) {
71867
72263
  }
71868
72264
  async function getTask(taskId, cwd) {
71869
72265
  const db = await getDb(cwd);
71870
- const rows = await db.select().from(tasks).where(eq15(tasks.id, taskId)).all();
72266
+ const rows = await db.select().from(tasks).where(eq16(tasks.id, taskId)).all();
71871
72267
  if (rows.length === 0) return null;
71872
72268
  const task = rowToTask(rows[0]);
71873
- const deps = await db.select().from(taskDependencies).where(eq15(taskDependencies.taskId, taskId)).all();
72269
+ const deps = await db.select().from(taskDependencies).where(eq16(taskDependencies.taskId, taskId)).all();
71874
72270
  if (deps.length > 0) {
71875
72271
  task.depends = deps.map((d) => d.dependsOn);
71876
72272
  }
@@ -71906,9 +72302,9 @@ async function updateTask2(taskId, updates, cwd) {
71906
72302
  updateRow.cancellationReason = updates.cancellationReason;
71907
72303
  if (updates.verification !== void 0)
71908
72304
  updateRow.verificationJson = JSON.stringify(updates.verification);
71909
- db.update(tasks).set(updateRow).where(eq15(tasks.id, taskId)).run();
72305
+ db.update(tasks).set(updateRow).where(eq16(tasks.id, taskId)).run();
71910
72306
  if (updates.depends !== void 0) {
71911
- db.delete(taskDependencies).where(eq15(taskDependencies.taskId, taskId)).run();
72307
+ db.delete(taskDependencies).where(eq16(taskDependencies.taskId, taskId)).run();
71912
72308
  for (const depId of updates.depends) {
71913
72309
  db.insert(taskDependencies).values({ taskId, dependsOn: depId }).run();
71914
72310
  }
@@ -71917,9 +72313,9 @@ async function updateTask2(taskId, updates, cwd) {
71917
72313
  }
71918
72314
  async function deleteTask2(taskId, cwd) {
71919
72315
  const db = await getDb(cwd);
71920
- const existing = await db.select({ id: tasks.id }).from(tasks).where(eq15(tasks.id, taskId)).all();
72316
+ const existing = await db.select({ id: tasks.id }).from(tasks).where(eq16(tasks.id, taskId)).all();
71921
72317
  if (existing.length === 0) return false;
71922
- db.delete(tasks).where(eq15(tasks.id, taskId)).run();
72318
+ db.delete(tasks).where(eq16(tasks.id, taskId)).run();
71923
72319
  void cleanupBrainRefsOnTaskDelete(taskId, cwd);
71924
72320
  return true;
71925
72321
  }
@@ -71927,17 +72323,17 @@ async function listTasks2(filters, cwd) {
71927
72323
  const db = await getDb(cwd);
71928
72324
  const conditions = [];
71929
72325
  conditions.push(ne3(tasks.status, "archived"));
71930
- if (filters?.status) conditions.push(eq15(tasks.status, filters.status));
72326
+ if (filters?.status) conditions.push(eq16(tasks.status, filters.status));
71931
72327
  if (filters?.parentId !== void 0) {
71932
72328
  if (filters.parentId === null) {
71933
72329
  conditions.push(isNull5(tasks.parentId));
71934
72330
  } else {
71935
- conditions.push(eq15(tasks.parentId, filters.parentId));
72331
+ conditions.push(eq16(tasks.parentId, filters.parentId));
71936
72332
  }
71937
72333
  }
71938
- if (filters?.type) conditions.push(eq15(tasks.type, filters.type));
71939
- if (filters?.phase) conditions.push(eq15(tasks.phase, filters.phase));
71940
- const query = db.select().from(tasks).where(conditions.length > 0 ? and10(...conditions) : void 0).orderBy(asc4(tasks.position), asc4(tasks.createdAt));
72334
+ if (filters?.type) conditions.push(eq16(tasks.type, filters.type));
72335
+ if (filters?.phase) conditions.push(eq16(tasks.phase, filters.phase));
72336
+ const query = db.select().from(tasks).where(conditions.length > 0 ? and11(...conditions) : void 0).orderBy(asc4(tasks.position), asc4(tasks.createdAt));
71941
72337
  const rows = filters?.limit ? await query.limit(filters.limit).all() : await query.all();
71942
72338
  const tasks2 = rows.map(rowToTask);
71943
72339
  await loadDependencies(tasks2, cwd);
@@ -71947,7 +72343,7 @@ async function findTasks2(query, limit = 20, cwd) {
71947
72343
  const db = await getDb(cwd);
71948
72344
  const pattern = `%${query}%`;
71949
72345
  const rows = await db.select().from(tasks).where(
71950
- and10(
72346
+ and11(
71951
72347
  ne3(tasks.status, "archived"),
71952
72348
  sql11`(${tasks.id} LIKE ${pattern} OR ${tasks.title} LIKE ${pattern} OR ${tasks.description} LIKE ${pattern})`
71953
72349
  )
@@ -71966,14 +72362,14 @@ async function archiveTask(taskId, reason, cwd) {
71966
72362
  archiveReason: reason ?? "completed",
71967
72363
  cycleTimeDays: cycleTime,
71968
72364
  updatedAt: now2
71969
- }).where(eq15(tasks.id, taskId)).run();
72365
+ }).where(eq16(tasks.id, taskId)).run();
71970
72366
  return true;
71971
72367
  }
71972
72368
  async function loadDependencies(tasks2, cwd) {
71973
72369
  if (tasks2.length === 0) return;
71974
72370
  const db = await getDb(cwd);
71975
72371
  const taskIds = tasks2.map((t) => t.id);
71976
- const deps = await db.select().from(taskDependencies).where(inArray5(taskDependencies.taskId, taskIds)).all();
72372
+ const deps = await db.select().from(taskDependencies).where(inArray6(taskDependencies.taskId, taskIds)).all();
71977
72373
  const depMap = /* @__PURE__ */ new Map();
71978
72374
  for (const dep of deps) {
71979
72375
  if (!depMap.has(dep.taskId)) depMap.set(dep.taskId, []);
@@ -71993,9 +72389,9 @@ async function addDependency(taskId, dependsOn, cwd) {
71993
72389
  async function removeDependency(taskId, dependsOn, cwd) {
71994
72390
  const db = await getDb(cwd);
71995
72391
  db.delete(taskDependencies).where(
71996
- and10(
71997
- eq15(taskDependencies.taskId, taskId),
71998
- eq15(taskDependencies.dependsOn, dependsOn)
72392
+ and11(
72393
+ eq16(taskDependencies.taskId, taskId),
72394
+ eq16(taskDependencies.dependsOn, dependsOn)
71999
72395
  )
72000
72396
  ).run();
72001
72397
  }
@@ -72005,7 +72401,7 @@ async function addRelation(taskId, relatedTo, relationType = "related", cwd, rea
72005
72401
  }
72006
72402
  async function getRelations(taskId, cwd) {
72007
72403
  const db = await getDb(cwd);
72008
- const rows = await db.select().from(taskRelations).where(eq15(taskRelations.taskId, taskId)).all();
72404
+ const rows = await db.select().from(taskRelations).where(eq16(taskRelations.taskId, taskId)).all();
72009
72405
  return rows.map((r) => ({
72010
72406
  relatedTo: r.relatedTo,
72011
72407
  type: r.relationType,
@@ -72029,7 +72425,7 @@ async function getBlockerChain(taskId, cwd) {
72029
72425
  }
72030
72426
  async function getChildren2(parentId, cwd) {
72031
72427
  const db = await getDb(cwd);
72032
- const rows = await db.select().from(tasks).where(eq15(tasks.parentId, parentId)).orderBy(asc4(tasks.position), asc4(tasks.createdAt)).all();
72428
+ const rows = await db.select().from(tasks).where(eq16(tasks.parentId, parentId)).orderBy(asc4(tasks.position), asc4(tasks.createdAt)).all();
72033
72429
  return rows.map(rowToTask);
72034
72430
  }
72035
72431
  async function getSubtree(rootId, cwd) {
@@ -73634,10 +74030,10 @@ async function migrateJsonToSqlite2(cwd, options) {
73634
74030
  const jsonCounts = countJsonRecords(cleoDir);
73635
74031
  result.jsonCounts = jsonCounts;
73636
74032
  if (dbExists(cwd)) {
73637
- const { ne: ne4, eq: eq16, count: count4 } = await import("drizzle-orm");
74033
+ const { ne: ne4, eq: eq17, count: count4 } = await import("drizzle-orm");
73638
74034
  const db2 = await getDb(cwd);
73639
74035
  const tasksResult = await db2.select({ count: count4() }).from(tasks).where(ne4(tasks.status, "archived")).get();
73640
- const archivedResult = await db2.select({ count: count4() }).from(tasks).where(eq16(tasks.status, "archived")).get();
74036
+ const archivedResult = await db2.select({ count: count4() }).from(tasks).where(eq17(tasks.status, "archived")).get();
73641
74037
  const sessionsResult = await db2.select({ count: count4() }).from(sessions).get();
73642
74038
  const existingCounts = {
73643
74039
  tasks: tasksResult?.count ?? 0,
@@ -73821,10 +74217,10 @@ async function migrateJsonToSqlite2(cwd, options) {
73821
74217
  async function exportToJson(cwd) {
73822
74218
  const { listTasks: listTasks3 } = await Promise.resolve().then(() => (init_task_store(), task_store_exports));
73823
74219
  const { listSessions: listSessions3 } = await Promise.resolve().then(() => (init_session_store(), session_store_exports));
73824
- const { eq: eq16 } = await import("drizzle-orm");
74220
+ const { eq: eq17 } = await import("drizzle-orm");
73825
74221
  const tasks2 = await listTasks3(void 0, cwd);
73826
74222
  const db = await getDb(cwd);
73827
- const archivedRows = await db.select().from(tasks).where(eq16(tasks.status, "archived")).all();
74223
+ const archivedRows = await db.select().from(tasks).where(eq17(tasks.status, "archived")).all();
73828
74224
  const archived = archivedRows.map((row) => ({
73829
74225
  id: row.id,
73830
74226
  title: row.title,
@@ -76408,7 +76804,7 @@ async function validateSqliteRows(type, projectRoot) {
76408
76804
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
76409
76805
  const schemaTable = await Promise.resolve().then(() => (init_tasks_schema(), tasks_schema_exports));
76410
76806
  const zodSchemas = await Promise.resolve().then(() => (init_validation_schemas(), validation_schemas_exports));
76411
- const { ne: ne4, eq: eq16 } = await import("drizzle-orm");
76807
+ const { ne: ne4, eq: eq17 } = await import("drizzle-orm");
76412
76808
  const db = await getDb4(projectRoot);
76413
76809
  const errors = [];
76414
76810
  switch (type) {
@@ -76420,7 +76816,7 @@ async function validateSqliteRows(type, projectRoot) {
76420
76816
  break;
76421
76817
  }
76422
76818
  case "archive": {
76423
- const rows = await db.select().from(schemaTable.tasks).where(eq16(schemaTable.tasks.status, "archived"));
76819
+ const rows = await db.select().from(schemaTable.tasks).where(eq17(schemaTable.tasks.status, "archived"));
76424
76820
  for (const row of rows) {
76425
76821
  errors.push(...collectZodErrors(zodSchemas.selectTaskSchema.safeParse(row), row.id));
76426
76822
  }
@@ -77496,6 +77892,7 @@ __export(internal_exports, {
77496
77892
  GATE_VALIDATION_RULES: () => GATE_VALIDATION_RULES,
77497
77893
  GateLayer: () => GateLayer,
77498
77894
  GateStatus: () => GateStatus,
77895
+ HEARTBEAT_INTERVAL_MS: () => HEARTBEAT_INTERVAL_MS,
77499
77896
  HookRegistry: () => HookRegistry,
77500
77897
  LIFECYCLE_PIPELINE_STATUSES: () => LIFECYCLE_PIPELINE_STATUSES,
77501
77898
  LIFECYCLE_STAGE_STATUSES: () => LIFECYCLE_STAGE_STATUSES,
@@ -77509,6 +77906,7 @@ __export(internal_exports, {
77509
77906
  RateLimiter: () => RateLimiter,
77510
77907
  SESSION_STATUSES: () => SESSION_STATUSES,
77511
77908
  STAGE_STATUS_ICONS: () => STAGE_STATUS_ICONS,
77909
+ STALE_THRESHOLD_MS: () => STALE_THRESHOLD_MS,
77512
77910
  STATUS_REGISTRY: () => STATUS_REGISTRY,
77513
77911
  STRICTNESS_PRESETS: () => STRICTNESS_PRESETS,
77514
77912
  SecurityError: () => SecurityError,
@@ -77588,7 +77986,7 @@ __export(internal_exports, {
77588
77986
  canRunNatively: () => canRunNatively,
77589
77987
  cancelRelease: () => cancelRelease,
77590
77988
  channelToDistTag: () => channelToDistTag,
77591
- checkAgentHealth: () => checkAgentHealth,
77989
+ checkAgentHealth: () => checkAgentHealth2,
77592
77990
  checkConsensusManifest: () => checkConsensusManifest,
77593
77991
  checkContributionManifest: () => checkContributionManifest,
77594
77992
  checkDecompositionManifest: () => checkDecompositionManifest,
@@ -77620,6 +78018,7 @@ __export(internal_exports, {
77620
78018
  computeBriefing: () => computeBriefing,
77621
78019
  computeChecksum: () => computeChecksum,
77622
78020
  computeDebrief: () => computeDebrief,
78021
+ computeDelay: () => computeDelay,
77623
78022
  computeEpicStatus: () => computeEpicStatus,
77624
78023
  computeHandoff: () => computeHandoff,
77625
78024
  computeHelp: () => computeHelp,
@@ -77692,9 +78091,11 @@ __export(internal_exports, {
77692
78091
  deleteTokenUsage: () => deleteTokenUsage,
77693
78092
  deregisterAgent: () => deregisterAgent,
77694
78093
  describeChannel: () => describeChannel,
78094
+ detectCrashedAgents: () => detectCrashedAgents,
77695
78095
  detectEnvMode: () => detectEnvMode,
77696
78096
  detectPlatform: () => detectPlatform,
77697
78097
  detectProjectType: () => detectProjectType,
78098
+ detectStaleAgents: () => detectStaleAgents,
77698
78099
  detectVersion: () => detectVersion,
77699
78100
  determineInstallationTargets: () => determineInstallationTargets,
77700
78101
  discoverRelated: () => discoverRelated2,
@@ -77724,6 +78125,7 @@ __export(internal_exports, {
77724
78125
  findAdrs: () => findAdrs,
77725
78126
  findLeastLoadedAgent: () => findLeastLoadedAgent,
77726
78127
  findSessions: () => findSessions,
78128
+ findStaleAgentRows: () => checkAgentHealth,
77727
78129
  findTasks: () => findTasks,
77728
78130
  formatError: () => formatError3,
77729
78131
  formatOutput: () => formatOutput,
@@ -77883,6 +78285,7 @@ __export(internal_exports, {
77883
78285
  isValidStatus: () => isValidStatus,
77884
78286
  isValidWorkflowGateName: () => isValidWorkflowGateName,
77885
78287
  issue: () => issue_exports,
78288
+ lib: () => lib_exports,
77886
78289
  lifecycle: () => lifecycle_exports,
77887
78290
  lifecycleEvidenceTypeSchema: () => lifecycleEvidenceTypeSchema,
77888
78291
  lifecycleGateResultSchema: () => lifecycleGateResultSchema,
@@ -77983,6 +78386,7 @@ __export(internal_exports, {
77983
78386
  pipelineManifestPending: () => pipelineManifestPending,
77984
78387
  pipelineManifestShow: () => pipelineManifestShow,
77985
78388
  pipelineManifestStats: () => pipelineManifestStats,
78389
+ predictImpact: () => predictImpact,
77986
78390
  predictValidationOutcome: () => predictValidationOutcome,
77987
78391
  prepareRelease: () => prepareRelease,
77988
78392
  prepareSpawn: () => prepareSpawn,
@@ -78007,6 +78411,7 @@ __export(internal_exports, {
78007
78411
  recordAssumption: () => recordAssumption,
78008
78412
  recordDecision: () => recordDecision,
78009
78413
  recordFailurePattern: () => recordFailurePattern,
78414
+ recordHeartbeat: () => recordHeartbeat,
78010
78415
  recordStageProgress: () => recordStageProgress,
78011
78416
  recordTokenExchange: () => recordTokenExchange,
78012
78417
  recoverCrashedAgents: () => recoverCrashedAgents,
@@ -78143,6 +78548,7 @@ __export(internal_exports, {
78143
78548
  validateWorkflowGateUpdate: () => validateWorkflowGateUpdate,
78144
78549
  validation: () => validation_exports,
78145
78550
  withRetry: () => withRetry,
78551
+ withRetryShared: () => withRetry2,
78146
78552
  writeMemoryBridge: () => writeMemoryBridge,
78147
78553
  writeSnapshot: () => writeSnapshot
78148
78554
  });
@@ -78167,6 +78573,7 @@ var init_internal = __esm({
78167
78573
  init_patterns2();
78168
78574
  init_prediction();
78169
78575
  init_diagnostics();
78576
+ init_retry2();
78170
78577
  init_chain_store();
78171
78578
  init_lifecycle2();
78172
78579
  init_tessera_engine();
@@ -82054,6 +82461,30 @@ var OPERATIONS = [
82054
82461
  sessionRequired: false,
82055
82462
  requiredParams: []
82056
82463
  },
82464
+ {
82465
+ gateway: "query",
82466
+ domain: "tasks",
82467
+ operation: "impact",
82468
+ description: "tasks.impact (query) \u2014 predict downstream effects of a free-text change description using keyword matching and reverse dependency graph traversal",
82469
+ tier: 1,
82470
+ idempotent: true,
82471
+ sessionRequired: false,
82472
+ requiredParams: ["change"],
82473
+ params: [
82474
+ {
82475
+ name: "change",
82476
+ type: "string",
82477
+ required: true,
82478
+ description: 'Free-text description of the proposed change (e.g. "Modify authentication flow")'
82479
+ },
82480
+ {
82481
+ name: "matchLimit",
82482
+ type: "number",
82483
+ required: false,
82484
+ description: "Maximum number of seed tasks to match by keyword (default: 5)"
82485
+ }
82486
+ ]
82487
+ },
82057
82488
  {
82058
82489
  gateway: "query",
82059
82490
  domain: "tasks",
@@ -86406,10 +86837,10 @@ async function releaseShip(params, projectRoot) {
86406
86837
  );
86407
86838
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_internal(), internal_exports));
86408
86839
  const { releaseManifests: releaseManifests2 } = await Promise.resolve().then(() => (init_internal(), internal_exports));
86409
- const { eq: eq16 } = await import("drizzle-orm");
86840
+ const { eq: eq17 } = await import("drizzle-orm");
86410
86841
  const normalizedVer = version2.startsWith("v") ? version2 : `v${version2}`;
86411
86842
  const db = await getDb4(cwd);
86412
- await db.update(releaseManifests2).set({ epicId }).where(eq16(releaseManifests2.version, normalizedVer)).run();
86843
+ await db.update(releaseManifests2).set({ epicId }).where(eq17(releaseManifests2.version, normalizedVer)).run();
86413
86844
  await generateReleaseChangelog(version2, () => loadTasks2(projectRoot), cwd);
86414
86845
  }
86415
86846
  logStep(0, 8, "Auto-prepare release record", true);
@@ -87641,6 +88072,15 @@ async function taskAnalyze(projectRoot, taskId, params) {
87641
88072
  return engineError("E_GENERAL", `Task analysis failed: ${message}`);
87642
88073
  }
87643
88074
  }
88075
+ async function taskImpact(projectRoot, change, matchLimit) {
88076
+ try {
88077
+ const result = await predictImpact(change, projectRoot, void 0, matchLimit);
88078
+ return { success: true, data: result };
88079
+ } catch (err) {
88080
+ const message = err instanceof Error ? err.message : String(err);
88081
+ return engineError("E_GENERAL", `Impact prediction failed: ${message}`);
88082
+ }
88083
+ }
87644
88084
  async function taskRestore(projectRoot, taskId, params) {
87645
88085
  try {
87646
88086
  const result = await coreTaskRestore(projectRoot, taskId, params);
@@ -92539,6 +92979,22 @@ var TasksHandler = class {
92539
92979
  const result = await taskAnalyze(projectRoot, taskId, { tierLimit });
92540
92980
  return wrapResult(result, "query", "tasks", operation, startTime);
92541
92981
  }
92982
+ case "impact": {
92983
+ const change = params?.change;
92984
+ if (!change) {
92985
+ return errorResult(
92986
+ "query",
92987
+ "tasks",
92988
+ operation,
92989
+ "E_INVALID_INPUT",
92990
+ "change is required (free-text description of the proposed change)",
92991
+ startTime
92992
+ );
92993
+ }
92994
+ const matchLimit = params?.matchLimit;
92995
+ const result = await taskImpact(projectRoot, change, matchLimit);
92996
+ return wrapResult(result, "query", "tasks", operation, startTime);
92997
+ }
92542
92998
  case "next": {
92543
92999
  const result = await taskNext(
92544
93000
  projectRoot,
@@ -92787,6 +93243,7 @@ var TasksHandler = class {
92787
93243
  "blockers",
92788
93244
  "depends",
92789
93245
  "analyze",
93246
+ "impact",
92790
93247
  "next",
92791
93248
  "plan",
92792
93249
  "relates",