@cleocode/cleo 2026.4.10 → 2026.4.11

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 (693) hide show
  1. package/dist/cli/commander-shim.d.ts +112 -0
  2. package/dist/cli/commander-shim.d.ts.map +1 -0
  3. package/dist/cli/commander-shim.js +233 -0
  4. package/dist/cli/commander-shim.js.map +1 -0
  5. package/dist/cli/commands/add.d.ts +12 -0
  6. package/dist/cli/commands/add.d.ts.map +1 -0
  7. package/dist/cli/commands/add.js +98 -0
  8. package/dist/cli/commands/add.js.map +1 -0
  9. package/dist/cli/commands/admin.d.ts +12 -0
  10. package/dist/cli/commands/admin.d.ts.map +1 -0
  11. package/dist/cli/commands/admin.js +59 -0
  12. package/dist/cli/commands/admin.js.map +1 -0
  13. package/dist/cli/commands/adr.d.ts +27 -0
  14. package/dist/cli/commands/adr.d.ts.map +1 -0
  15. package/dist/cli/commands/adr.js +79 -0
  16. package/dist/cli/commands/adr.js.map +1 -0
  17. package/dist/cli/commands/agent-profile-status.d.ts +98 -0
  18. package/dist/cli/commands/agent-profile-status.d.ts.map +1 -0
  19. package/dist/cli/commands/agent-profile-status.js +71 -0
  20. package/dist/cli/commands/agent-profile-status.js.map +1 -0
  21. package/dist/cli/commands/agent.d.ts +38 -0
  22. package/dist/cli/commands/agent.d.ts.map +1 -0
  23. package/dist/cli/commands/agent.js +1125 -0
  24. package/dist/cli/commands/agent.js.map +1 -0
  25. package/dist/cli/commands/agents.d.ts +17 -0
  26. package/dist/cli/commands/agents.d.ts.map +1 -0
  27. package/dist/cli/commands/agents.js +20 -0
  28. package/dist/cli/commands/agents.js.map +1 -0
  29. package/dist/cli/commands/analyze.d.ts +12 -0
  30. package/dist/cli/commands/analyze.d.ts.map +1 -0
  31. package/dist/cli/commands/analyze.js +20 -0
  32. package/dist/cli/commands/analyze.js.map +1 -0
  33. package/dist/cli/commands/archive-stats.d.ts +18 -0
  34. package/dist/cli/commands/archive-stats.d.ts.map +1 -0
  35. package/dist/cli/commands/archive-stats.js +49 -0
  36. package/dist/cli/commands/archive-stats.js.map +1 -0
  37. package/dist/cli/commands/archive.d.ts +12 -0
  38. package/dist/cli/commands/archive.d.ts.map +1 -0
  39. package/dist/cli/commands/archive.js +32 -0
  40. package/dist/cli/commands/archive.js.map +1 -0
  41. package/dist/cli/commands/backfill.d.ts +38 -0
  42. package/dist/cli/commands/backfill.d.ts.map +1 -0
  43. package/dist/cli/commands/backfill.js +147 -0
  44. package/dist/cli/commands/backfill.js.map +1 -0
  45. package/dist/cli/commands/backup.d.ts +8 -0
  46. package/dist/cli/commands/backup.d.ts.map +1 -0
  47. package/dist/cli/commands/backup.js +35 -0
  48. package/dist/cli/commands/backup.js.map +1 -0
  49. package/dist/cli/commands/blockers.d.ts +7 -0
  50. package/dist/cli/commands/blockers.d.ts.map +1 -0
  51. package/dist/cli/commands/blockers.js +16 -0
  52. package/dist/cli/commands/blockers.js.map +1 -0
  53. package/dist/cli/commands/brain.d.ts +29 -0
  54. package/dist/cli/commands/brain.d.ts.map +1 -0
  55. package/dist/cli/commands/brain.js +107 -0
  56. package/dist/cli/commands/brain.js.map +1 -0
  57. package/dist/cli/commands/briefing.d.ts +22 -0
  58. package/dist/cli/commands/briefing.d.ts.map +1 -0
  59. package/dist/cli/commands/briefing.js +45 -0
  60. package/dist/cli/commands/briefing.js.map +1 -0
  61. package/dist/cli/commands/bug.d.ts +12 -0
  62. package/dist/cli/commands/bug.d.ts.map +1 -0
  63. package/dist/cli/commands/bug.js +81 -0
  64. package/dist/cli/commands/bug.js.map +1 -0
  65. package/dist/cli/commands/cant.d.ts +32 -0
  66. package/dist/cli/commands/cant.d.ts.map +1 -0
  67. package/dist/cli/commands/cant.js +281 -0
  68. package/dist/cli/commands/cant.js.map +1 -0
  69. package/dist/cli/commands/check.d.ts +22 -0
  70. package/dist/cli/commands/check.d.ts.map +1 -0
  71. package/dist/cli/commands/check.js +164 -0
  72. package/dist/cli/commands/check.js.map +1 -0
  73. package/dist/cli/commands/checkpoint.d.ts +15 -0
  74. package/dist/cli/commands/checkpoint.d.ts.map +1 -0
  75. package/dist/cli/commands/checkpoint.js +91 -0
  76. package/dist/cli/commands/checkpoint.js.map +1 -0
  77. package/dist/cli/commands/code.d.ts +11 -0
  78. package/dist/cli/commands/code.d.ts.map +1 -0
  79. package/dist/cli/commands/code.js +114 -0
  80. package/dist/cli/commands/code.js.map +1 -0
  81. package/dist/cli/commands/commands.d.ts +13 -0
  82. package/dist/cli/commands/commands.d.ts.map +1 -0
  83. package/dist/cli/commands/commands.js +29 -0
  84. package/dist/cli/commands/commands.js.map +1 -0
  85. package/dist/cli/commands/complete.d.ts +12 -0
  86. package/dist/cli/commands/complete.d.ts.map +1 -0
  87. package/dist/cli/commands/complete.js +43 -0
  88. package/dist/cli/commands/complete.js.map +1 -0
  89. package/dist/cli/commands/compliance.d.ts +8 -0
  90. package/dist/cli/commands/compliance.d.ts.map +1 -0
  91. package/dist/cli/commands/compliance.js +85 -0
  92. package/dist/cli/commands/compliance.js.map +1 -0
  93. package/dist/cli/commands/config.d.ts +10 -0
  94. package/dist/cli/commands/config.d.ts.map +1 -0
  95. package/dist/cli/commands/config.js +69 -0
  96. package/dist/cli/commands/config.js.map +1 -0
  97. package/dist/cli/commands/consensus.d.ts +13 -0
  98. package/dist/cli/commands/consensus.d.ts.map +1 -0
  99. package/dist/cli/commands/consensus.js +45 -0
  100. package/dist/cli/commands/consensus.js.map +1 -0
  101. package/dist/cli/commands/context.d.ts +8 -0
  102. package/dist/cli/commands/context.d.ts.map +1 -0
  103. package/dist/cli/commands/context.js +40 -0
  104. package/dist/cli/commands/context.js.map +1 -0
  105. package/dist/cli/commands/contribution.d.ts +13 -0
  106. package/dist/cli/commands/contribution.d.ts.map +1 -0
  107. package/dist/cli/commands/contribution.js +41 -0
  108. package/dist/cli/commands/contribution.js.map +1 -0
  109. package/dist/cli/commands/current.d.ts +13 -0
  110. package/dist/cli/commands/current.d.ts.map +1 -0
  111. package/dist/cli/commands/current.js +20 -0
  112. package/dist/cli/commands/current.js.map +1 -0
  113. package/dist/cli/commands/dash.d.ts +12 -0
  114. package/dist/cli/commands/dash.d.ts.map +1 -0
  115. package/dist/cli/commands/dash.js +24 -0
  116. package/dist/cli/commands/dash.js.map +1 -0
  117. package/dist/cli/commands/decomposition.d.ts +13 -0
  118. package/dist/cli/commands/decomposition.d.ts.map +1 -0
  119. package/dist/cli/commands/decomposition.js +45 -0
  120. package/dist/cli/commands/decomposition.js.map +1 -0
  121. package/dist/cli/commands/delete.d.ts +12 -0
  122. package/dist/cli/commands/delete.d.ts.map +1 -0
  123. package/dist/cli/commands/delete.js +37 -0
  124. package/dist/cli/commands/delete.js.map +1 -0
  125. package/dist/cli/commands/deps.d.ts +24 -0
  126. package/dist/cli/commands/deps.d.ts.map +1 -0
  127. package/dist/cli/commands/deps.js +98 -0
  128. package/dist/cli/commands/deps.js.map +1 -0
  129. package/dist/cli/commands/detect-drift.d.ts +15 -0
  130. package/dist/cli/commands/detect-drift.d.ts.map +1 -0
  131. package/dist/cli/commands/detect-drift.js +424 -0
  132. package/dist/cli/commands/detect-drift.js.map +1 -0
  133. package/dist/cli/commands/detect.d.ts +10 -0
  134. package/dist/cli/commands/detect.d.ts.map +1 -0
  135. package/dist/cli/commands/detect.js +24 -0
  136. package/dist/cli/commands/detect.js.map +1 -0
  137. package/dist/cli/commands/docs.d.ts +13 -0
  138. package/dist/cli/commands/docs.d.ts.map +1 -0
  139. package/dist/cli/commands/docs.js +169 -0
  140. package/dist/cli/commands/docs.js.map +1 -0
  141. package/dist/cli/commands/doctor.d.ts +15 -0
  142. package/dist/cli/commands/doctor.d.ts.map +1 -0
  143. package/dist/cli/commands/doctor.js +133 -0
  144. package/dist/cli/commands/doctor.js.map +1 -0
  145. package/dist/cli/commands/dynamic.d.ts +24 -0
  146. package/dist/cli/commands/dynamic.d.ts.map +1 -0
  147. package/dist/cli/commands/dynamic.js +27 -0
  148. package/dist/cli/commands/dynamic.js.map +1 -0
  149. package/dist/cli/commands/env.d.ts +12 -0
  150. package/dist/cli/commands/env.d.ts.map +1 -0
  151. package/dist/cli/commands/env.js +44 -0
  152. package/dist/cli/commands/env.js.map +1 -0
  153. package/dist/cli/commands/exists.d.ts +22 -0
  154. package/dist/cli/commands/exists.d.ts.map +1 -0
  155. package/dist/cli/commands/exists.js +51 -0
  156. package/dist/cli/commands/exists.js.map +1 -0
  157. package/dist/cli/commands/export-tasks.d.ts +10 -0
  158. package/dist/cli/commands/export-tasks.d.ts.map +1 -0
  159. package/dist/cli/commands/export-tasks.js +47 -0
  160. package/dist/cli/commands/export-tasks.js.map +1 -0
  161. package/dist/cli/commands/export.d.ts +9 -0
  162. package/dist/cli/commands/export.d.ts.map +1 -0
  163. package/dist/cli/commands/export.js +46 -0
  164. package/dist/cli/commands/export.js.map +1 -0
  165. package/dist/cli/commands/find.d.ts +14 -0
  166. package/dist/cli/commands/find.d.ts.map +1 -0
  167. package/dist/cli/commands/find.js +70 -0
  168. package/dist/cli/commands/find.js.map +1 -0
  169. package/dist/cli/commands/generate-changelog.d.ts +14 -0
  170. package/dist/cli/commands/generate-changelog.d.ts.map +1 -0
  171. package/dist/cli/commands/generate-changelog.js +252 -0
  172. package/dist/cli/commands/generate-changelog.js.map +1 -0
  173. package/dist/cli/commands/grade.d.ts +13 -0
  174. package/dist/cli/commands/grade.d.ts.map +1 -0
  175. package/dist/cli/commands/grade.js +26 -0
  176. package/dist/cli/commands/grade.js.map +1 -0
  177. package/dist/cli/commands/history.d.ts +9 -0
  178. package/dist/cli/commands/history.d.ts.map +1 -0
  179. package/dist/cli/commands/history.js +30 -0
  180. package/dist/cli/commands/history.js.map +1 -0
  181. package/dist/cli/commands/implementation.d.ts +13 -0
  182. package/dist/cli/commands/implementation.d.ts.map +1 -0
  183. package/dist/cli/commands/implementation.js +41 -0
  184. package/dist/cli/commands/implementation.js.map +1 -0
  185. package/dist/cli/commands/import-tasks.d.ts +10 -0
  186. package/dist/cli/commands/import-tasks.d.ts.map +1 -0
  187. package/dist/cli/commands/import-tasks.js +38 -0
  188. package/dist/cli/commands/import-tasks.js.map +1 -0
  189. package/dist/cli/commands/import.d.ts +9 -0
  190. package/dist/cli/commands/import.d.ts.map +1 -0
  191. package/dist/cli/commands/import.js +28 -0
  192. package/dist/cli/commands/import.js.map +1 -0
  193. package/dist/cli/commands/init.d.ts +34 -0
  194. package/dist/cli/commands/init.d.ts.map +1 -0
  195. package/dist/cli/commands/init.js +96 -0
  196. package/dist/cli/commands/init.js.map +1 -0
  197. package/dist/cli/commands/inject.d.ts +8 -0
  198. package/dist/cli/commands/inject.d.ts.map +1 -0
  199. package/dist/cli/commands/inject.js +28 -0
  200. package/dist/cli/commands/inject.js.map +1 -0
  201. package/dist/cli/commands/issue.d.ts +17 -0
  202. package/dist/cli/commands/issue.d.ts.map +1 -0
  203. package/dist/cli/commands/issue.js +107 -0
  204. package/dist/cli/commands/issue.js.map +1 -0
  205. package/dist/cli/commands/labels.d.ts +13 -0
  206. package/dist/cli/commands/labels.d.ts.map +1 -0
  207. package/dist/cli/commands/labels.js +44 -0
  208. package/dist/cli/commands/labels.js.map +1 -0
  209. package/dist/cli/commands/lifecycle.d.ts +8 -0
  210. package/dist/cli/commands/lifecycle.d.ts.map +1 -0
  211. package/dist/cli/commands/lifecycle.js +84 -0
  212. package/dist/cli/commands/lifecycle.js.map +1 -0
  213. package/dist/cli/commands/list.d.ts +14 -0
  214. package/dist/cli/commands/list.d.ts.map +1 -0
  215. package/dist/cli/commands/list.js +71 -0
  216. package/dist/cli/commands/list.js.map +1 -0
  217. package/dist/cli/commands/log.d.ts +12 -0
  218. package/dist/cli/commands/log.d.ts.map +1 -0
  219. package/dist/cli/commands/log.js +30 -0
  220. package/dist/cli/commands/log.js.map +1 -0
  221. package/dist/cli/commands/map.d.ts +10 -0
  222. package/dist/cli/commands/map.d.ts.map +1 -0
  223. package/dist/cli/commands/map.js +23 -0
  224. package/dist/cli/commands/map.js.map +1 -0
  225. package/dist/cli/commands/memory-brain.d.ts +14 -0
  226. package/dist/cli/commands/memory-brain.d.ts.map +1 -0
  227. package/dist/cli/commands/memory-brain.js +157 -0
  228. package/dist/cli/commands/memory-brain.js.map +1 -0
  229. package/dist/cli/commands/migrate-claude-mem.d.ts +18 -0
  230. package/dist/cli/commands/migrate-claude-mem.d.ts.map +1 -0
  231. package/dist/cli/commands/migrate-claude-mem.js +60 -0
  232. package/dist/cli/commands/migrate-claude-mem.js.map +1 -0
  233. package/dist/cli/commands/next.d.ts +9 -0
  234. package/dist/cli/commands/next.d.ts.map +1 -0
  235. package/dist/cli/commands/next.js +20 -0
  236. package/dist/cli/commands/next.js.map +1 -0
  237. package/dist/cli/commands/nexus.d.ts +16 -0
  238. package/dist/cli/commands/nexus.d.ts.map +1 -0
  239. package/dist/cli/commands/nexus.js +155 -0
  240. package/dist/cli/commands/nexus.js.map +1 -0
  241. package/dist/cli/commands/observe.d.ts +9 -0
  242. package/dist/cli/commands/observe.d.ts.map +1 -0
  243. package/dist/cli/commands/observe.js +39 -0
  244. package/dist/cli/commands/observe.js.map +1 -0
  245. package/dist/cli/commands/ops.d.ts +10 -0
  246. package/dist/cli/commands/ops.d.ts.map +1 -0
  247. package/dist/cli/commands/ops.js +19 -0
  248. package/dist/cli/commands/ops.js.map +1 -0
  249. package/dist/cli/commands/orchestrate.d.ts +8 -0
  250. package/dist/cli/commands/orchestrate.d.ts.map +1 -0
  251. package/dist/cli/commands/orchestrate.js +58 -0
  252. package/dist/cli/commands/orchestrate.js.map +1 -0
  253. package/dist/cli/commands/otel.d.ts +12 -0
  254. package/dist/cli/commands/otel.d.ts.map +1 -0
  255. package/dist/cli/commands/otel.js +128 -0
  256. package/dist/cli/commands/otel.js.map +1 -0
  257. package/dist/cli/commands/phase.d.ts +12 -0
  258. package/dist/cli/commands/phase.d.ts.map +1 -0
  259. package/dist/cli/commands/phase.js +91 -0
  260. package/dist/cli/commands/phase.js.map +1 -0
  261. package/dist/cli/commands/phases.d.ts +12 -0
  262. package/dist/cli/commands/phases.d.ts.map +1 -0
  263. package/dist/cli/commands/phases.js +37 -0
  264. package/dist/cli/commands/phases.js.map +1 -0
  265. package/dist/cli/commands/plan.d.ts +8 -0
  266. package/dist/cli/commands/plan.d.ts.map +1 -0
  267. package/dist/cli/commands/plan.js +15 -0
  268. package/dist/cli/commands/plan.js.map +1 -0
  269. package/dist/cli/commands/promote.d.ts +7 -0
  270. package/dist/cli/commands/promote.d.ts.map +1 -0
  271. package/dist/cli/commands/promote.js +15 -0
  272. package/dist/cli/commands/promote.js.map +1 -0
  273. package/dist/cli/commands/reason.d.ts +35 -0
  274. package/dist/cli/commands/reason.d.ts.map +1 -0
  275. package/dist/cli/commands/reason.js +104 -0
  276. package/dist/cli/commands/reason.js.map +1 -0
  277. package/dist/cli/commands/refresh-memory.d.ts +9 -0
  278. package/dist/cli/commands/refresh-memory.d.ts.map +1 -0
  279. package/dist/cli/commands/refresh-memory.js +24 -0
  280. package/dist/cli/commands/refresh-memory.js.map +1 -0
  281. package/dist/cli/commands/relates.d.ts +12 -0
  282. package/dist/cli/commands/relates.d.ts.map +1 -0
  283. package/dist/cli/commands/relates.js +53 -0
  284. package/dist/cli/commands/relates.js.map +1 -0
  285. package/dist/cli/commands/release.d.ts +8 -0
  286. package/dist/cli/commands/release.d.ts.map +1 -0
  287. package/dist/cli/commands/release.js +72 -0
  288. package/dist/cli/commands/release.js.map +1 -0
  289. package/dist/cli/commands/remote.d.ts +12 -0
  290. package/dist/cli/commands/remote.d.ts.map +1 -0
  291. package/dist/cli/commands/remote.js +207 -0
  292. package/dist/cli/commands/remote.js.map +1 -0
  293. package/dist/cli/commands/reorder.d.ts +7 -0
  294. package/dist/cli/commands/reorder.d.ts.map +1 -0
  295. package/dist/cli/commands/reorder.js +20 -0
  296. package/dist/cli/commands/reorder.js.map +1 -0
  297. package/dist/cli/commands/reparent.d.ts +10 -0
  298. package/dist/cli/commands/reparent.d.ts.map +1 -0
  299. package/dist/cli/commands/reparent.js +19 -0
  300. package/dist/cli/commands/reparent.js.map +1 -0
  301. package/dist/cli/commands/research.d.ts +8 -0
  302. package/dist/cli/commands/research.d.ts.map +1 -0
  303. package/dist/cli/commands/research.js +129 -0
  304. package/dist/cli/commands/research.js.map +1 -0
  305. package/dist/cli/commands/restore.d.ts +11 -0
  306. package/dist/cli/commands/restore.d.ts.map +1 -0
  307. package/dist/cli/commands/restore.js +224 -0
  308. package/dist/cli/commands/restore.js.map +1 -0
  309. package/dist/cli/commands/roadmap.d.ts +8 -0
  310. package/dist/cli/commands/roadmap.d.ts.map +1 -0
  311. package/dist/cli/commands/roadmap.js +21 -0
  312. package/dist/cli/commands/roadmap.js.map +1 -0
  313. package/dist/cli/commands/safestop.d.ts +14 -0
  314. package/dist/cli/commands/safestop.d.ts.map +1 -0
  315. package/dist/cli/commands/safestop.js +32 -0
  316. package/dist/cli/commands/safestop.js.map +1 -0
  317. package/dist/cli/commands/self-update.d.ts +15 -0
  318. package/dist/cli/commands/self-update.d.ts.map +1 -0
  319. package/dist/cli/commands/self-update.js +329 -0
  320. package/dist/cli/commands/self-update.js.map +1 -0
  321. package/dist/cli/commands/sequence.d.ts +8 -0
  322. package/dist/cli/commands/sequence.d.ts.map +1 -0
  323. package/dist/cli/commands/sequence.js +30 -0
  324. package/dist/cli/commands/sequence.js.map +1 -0
  325. package/dist/cli/commands/session.d.ts +12 -0
  326. package/dist/cli/commands/session.d.ts.map +1 -0
  327. package/dist/cli/commands/session.js +175 -0
  328. package/dist/cli/commands/session.js.map +1 -0
  329. package/dist/cli/commands/show.d.ts +13 -0
  330. package/dist/cli/commands/show.d.ts.map +1 -0
  331. package/dist/cli/commands/show.js +20 -0
  332. package/dist/cli/commands/show.js.map +1 -0
  333. package/dist/cli/commands/skills.d.ts +13 -0
  334. package/dist/cli/commands/skills.d.ts.map +1 -0
  335. package/dist/cli/commands/skills.js +131 -0
  336. package/dist/cli/commands/skills.js.map +1 -0
  337. package/dist/cli/commands/snapshot.d.ts +9 -0
  338. package/dist/cli/commands/snapshot.d.ts.map +1 -0
  339. package/dist/cli/commands/snapshot.js +50 -0
  340. package/dist/cli/commands/snapshot.js.map +1 -0
  341. package/dist/cli/commands/specification.d.ts +13 -0
  342. package/dist/cli/commands/specification.d.ts.map +1 -0
  343. package/dist/cli/commands/specification.js +45 -0
  344. package/dist/cli/commands/specification.js.map +1 -0
  345. package/dist/cli/commands/start.d.ts +13 -0
  346. package/dist/cli/commands/start.d.ts.map +1 -0
  347. package/dist/cli/commands/start.js +20 -0
  348. package/dist/cli/commands/start.js.map +1 -0
  349. package/dist/cli/commands/stats.d.ts +12 -0
  350. package/dist/cli/commands/stats.d.ts.map +1 -0
  351. package/dist/cli/commands/stats.js +35 -0
  352. package/dist/cli/commands/stats.js.map +1 -0
  353. package/dist/cli/commands/sticky.d.ts +16 -0
  354. package/dist/cli/commands/sticky.d.ts.map +1 -0
  355. package/dist/cli/commands/sticky.js +211 -0
  356. package/dist/cli/commands/sticky.js.map +1 -0
  357. package/dist/cli/commands/stop.d.ts +13 -0
  358. package/dist/cli/commands/stop.d.ts.map +1 -0
  359. package/dist/cli/commands/stop.js +20 -0
  360. package/dist/cli/commands/stop.js.map +1 -0
  361. package/dist/cli/commands/testing.d.ts +13 -0
  362. package/dist/cli/commands/testing.d.ts.map +1 -0
  363. package/dist/cli/commands/testing.js +64 -0
  364. package/dist/cli/commands/testing.js.map +1 -0
  365. package/dist/cli/commands/token.d.ts +10 -0
  366. package/dist/cli/commands/token.d.ts.map +1 -0
  367. package/dist/cli/commands/token.js +135 -0
  368. package/dist/cli/commands/token.js.map +1 -0
  369. package/dist/cli/commands/update.d.ts +12 -0
  370. package/dist/cli/commands/update.d.ts.map +1 -0
  371. package/dist/cli/commands/update.js +83 -0
  372. package/dist/cli/commands/update.js.map +1 -0
  373. package/dist/cli/commands/upgrade.d.ts +18 -0
  374. package/dist/cli/commands/upgrade.d.ts.map +1 -0
  375. package/dist/cli/commands/upgrade.js +103 -0
  376. package/dist/cli/commands/upgrade.js.map +1 -0
  377. package/dist/cli/commands/validate.d.ts +12 -0
  378. package/dist/cli/commands/validate.d.ts.map +1 -0
  379. package/dist/cli/commands/validate.js +23 -0
  380. package/dist/cli/commands/validate.js.map +1 -0
  381. package/dist/cli/commands/verify.d.ts +8 -0
  382. package/dist/cli/commands/verify.d.ts.map +1 -0
  383. package/dist/cli/commands/verify.js +28 -0
  384. package/dist/cli/commands/verify.js.map +1 -0
  385. package/dist/cli/commands/web.d.ts +13 -0
  386. package/dist/cli/commands/web.d.ts.map +1 -0
  387. package/dist/cli/commands/web.js +277 -0
  388. package/dist/cli/commands/web.js.map +1 -0
  389. package/dist/cli/field-context.d.ts +32 -0
  390. package/dist/cli/field-context.d.ts.map +1 -0
  391. package/dist/cli/field-context.js +47 -0
  392. package/dist/cli/field-context.js.map +1 -0
  393. package/dist/cli/format-context.d.ts +32 -0
  394. package/dist/cli/format-context.d.ts.map +1 -0
  395. package/dist/cli/format-context.js +50 -0
  396. package/dist/cli/format-context.js.map +1 -0
  397. package/dist/cli/index.d.ts +9 -0
  398. package/dist/cli/index.d.ts.map +1 -0
  399. package/dist/cli/index.js +3767 -3387
  400. package/dist/cli/index.js.map +4 -4
  401. package/dist/cli/logger-bootstrap.d.ts +6 -0
  402. package/dist/cli/logger-bootstrap.d.ts.map +1 -0
  403. package/dist/cli/logger-bootstrap.js +10 -0
  404. package/dist/cli/logger-bootstrap.js.map +1 -0
  405. package/dist/cli/middleware/output-format.d.ts +30 -0
  406. package/dist/cli/middleware/output-format.d.ts.map +1 -0
  407. package/dist/cli/middleware/output-format.js +35 -0
  408. package/dist/cli/middleware/output-format.js.map +1 -0
  409. package/dist/cli/progress.d.ts +84 -0
  410. package/dist/cli/progress.d.ts.map +1 -0
  411. package/dist/cli/progress.js +169 -0
  412. package/dist/cli/progress.js.map +1 -0
  413. package/dist/cli/renderers/colors.d.ts +32 -0
  414. package/dist/cli/renderers/colors.d.ts.map +1 -0
  415. package/dist/cli/renderers/colors.js +141 -0
  416. package/dist/cli/renderers/colors.js.map +1 -0
  417. package/dist/cli/renderers/error.d.ts +13 -0
  418. package/dist/cli/renderers/error.d.ts.map +1 -0
  419. package/dist/cli/renderers/error.js +42 -0
  420. package/dist/cli/renderers/error.js.map +1 -0
  421. package/dist/cli/renderers/index.d.ts +59 -0
  422. package/dist/cli/renderers/index.d.ts.map +1 -0
  423. package/dist/cli/renderers/index.js +208 -0
  424. package/dist/cli/renderers/index.js.map +1 -0
  425. package/dist/cli/renderers/lafs-validator.d.ts +97 -0
  426. package/dist/cli/renderers/lafs-validator.d.ts.map +1 -0
  427. package/dist/cli/renderers/lafs-validator.js +229 -0
  428. package/dist/cli/renderers/lafs-validator.js.map +1 -0
  429. package/dist/cli/renderers/normalizer.d.ts +21 -0
  430. package/dist/cli/renderers/normalizer.d.ts.map +1 -0
  431. package/dist/cli/renderers/normalizer.js +106 -0
  432. package/dist/cli/renderers/normalizer.js.map +1 -0
  433. package/dist/cli/renderers/system.d.ts +25 -0
  434. package/dist/cli/renderers/system.d.ts.map +1 -0
  435. package/dist/cli/renderers/system.js +416 -0
  436. package/dist/cli/renderers/system.js.map +1 -0
  437. package/dist/cli/renderers/tasks.d.ts +28 -0
  438. package/dist/cli/renderers/tasks.d.ts.map +1 -0
  439. package/dist/cli/renderers/tasks.js +306 -0
  440. package/dist/cli/renderers/tasks.js.map +1 -0
  441. package/dist/dispatch/adapters/cli.d.ts +67 -0
  442. package/dist/dispatch/adapters/cli.d.ts.map +1 -0
  443. package/dist/dispatch/adapters/cli.js +262 -0
  444. package/dist/dispatch/adapters/cli.js.map +1 -0
  445. package/dist/dispatch/context/session-context.d.ts +54 -0
  446. package/dist/dispatch/context/session-context.d.ts.map +1 -0
  447. package/dist/dispatch/context/session-context.js +61 -0
  448. package/dist/dispatch/context/session-context.js.map +1 -0
  449. package/dist/dispatch/dispatcher.d.ts +23 -0
  450. package/dist/dispatch/dispatcher.d.ts.map +1 -0
  451. package/dist/dispatch/dispatcher.js +84 -0
  452. package/dist/dispatch/dispatcher.js.map +1 -0
  453. package/dist/dispatch/domains/_base.d.ts +59 -0
  454. package/dist/dispatch/domains/_base.d.ts.map +1 -0
  455. package/dist/dispatch/domains/_base.js +77 -0
  456. package/dist/dispatch/domains/_base.js.map +1 -0
  457. package/dist/dispatch/domains/_meta.d.ts +23 -0
  458. package/dist/dispatch/domains/_meta.d.ts.map +1 -0
  459. package/dist/dispatch/domains/_meta.js +25 -0
  460. package/dist/dispatch/domains/_meta.js.map +1 -0
  461. package/dist/dispatch/domains/_routing.d.ts +8 -0
  462. package/dist/dispatch/domains/_routing.d.ts.map +1 -0
  463. package/dist/dispatch/domains/_routing.js +20 -0
  464. package/dist/dispatch/domains/_routing.js.map +1 -0
  465. package/dist/dispatch/domains/admin.d.ts +25 -0
  466. package/dist/dispatch/domains/admin.d.ts.map +1 -0
  467. package/dist/dispatch/domains/admin.js +719 -0
  468. package/dist/dispatch/domains/admin.js.map +1 -0
  469. package/dist/dispatch/domains/check.d.ts +22 -0
  470. package/dist/dispatch/domains/check.d.ts.map +1 -0
  471. package/dist/dispatch/domains/check.js +360 -0
  472. package/dist/dispatch/domains/check.js.map +1 -0
  473. package/dist/dispatch/domains/conduit.d.ts +38 -0
  474. package/dist/dispatch/domains/conduit.d.ts.map +1 -0
  475. package/dist/dispatch/domains/conduit.js +247 -0
  476. package/dist/dispatch/domains/conduit.js.map +1 -0
  477. package/dist/dispatch/domains/index.d.ts +27 -0
  478. package/dist/dispatch/domains/index.d.ts.map +1 -0
  479. package/dist/dispatch/domains/index.js +40 -0
  480. package/dist/dispatch/domains/index.js.map +1 -0
  481. package/dist/dispatch/domains/memory.d.ts +22 -0
  482. package/dist/dispatch/domains/memory.d.ts.map +1 -0
  483. package/dist/dispatch/domains/memory.js +303 -0
  484. package/dist/dispatch/domains/memory.js.map +1 -0
  485. package/dist/dispatch/domains/nexus.d.ts +22 -0
  486. package/dist/dispatch/domains/nexus.d.ts.map +1 -0
  487. package/dist/dispatch/domains/nexus.js +286 -0
  488. package/dist/dispatch/domains/nexus.js.map +1 -0
  489. package/dist/dispatch/domains/orchestrate.d.ts +19 -0
  490. package/dist/dispatch/domains/orchestrate.d.ts.map +1 -0
  491. package/dist/dispatch/domains/orchestrate.js +259 -0
  492. package/dist/dispatch/domains/orchestrate.js.map +1 -0
  493. package/dist/dispatch/domains/pipeline.d.ts +35 -0
  494. package/dist/dispatch/domains/pipeline.d.ts.map +1 -0
  495. package/dist/dispatch/domains/pipeline.js +593 -0
  496. package/dist/dispatch/domains/pipeline.js.map +1 -0
  497. package/dist/dispatch/domains/session.d.ts +22 -0
  498. package/dist/dispatch/domains/session.d.ts.map +1 -0
  499. package/dist/dispatch/domains/session.js +257 -0
  500. package/dist/dispatch/domains/session.js.map +1 -0
  501. package/dist/dispatch/domains/sticky.d.ts +20 -0
  502. package/dist/dispatch/domains/sticky.d.ts.map +1 -0
  503. package/dist/dispatch/domains/sticky.js +164 -0
  504. package/dist/dispatch/domains/sticky.js.map +1 -0
  505. package/dist/dispatch/domains/tasks.d.ts +25 -0
  506. package/dist/dispatch/domains/tasks.d.ts.map +1 -0
  507. package/dist/dispatch/domains/tasks.js +361 -0
  508. package/dist/dispatch/domains/tasks.js.map +1 -0
  509. package/dist/dispatch/domains/tools.d.ts +37 -0
  510. package/dist/dispatch/domains/tools.d.ts.map +1 -0
  511. package/dist/dispatch/domains/tools.js +481 -0
  512. package/dist/dispatch/domains/tools.js.map +1 -0
  513. package/dist/dispatch/engines/_error.d.ts +85 -0
  514. package/dist/dispatch/engines/_error.d.ts.map +1 -0
  515. package/dist/dispatch/engines/_error.js +244 -0
  516. package/dist/dispatch/engines/_error.js.map +1 -0
  517. package/dist/dispatch/engines/code-engine.d.ts +18 -0
  518. package/dist/dispatch/engines/code-engine.d.ts.map +1 -0
  519. package/dist/dispatch/engines/code-engine.js +71 -0
  520. package/dist/dispatch/engines/code-engine.js.map +1 -0
  521. package/dist/dispatch/engines/codebase-map-engine.d.ts +31 -0
  522. package/dist/dispatch/engines/codebase-map-engine.d.ts.map +1 -0
  523. package/dist/dispatch/engines/codebase-map-engine.js +43 -0
  524. package/dist/dispatch/engines/codebase-map-engine.js.map +1 -0
  525. package/dist/dispatch/engines/config-engine.d.ts +32 -0
  526. package/dist/dispatch/engines/config-engine.d.ts.map +1 -0
  527. package/dist/dispatch/engines/config-engine.js +70 -0
  528. package/dist/dispatch/engines/config-engine.js.map +1 -0
  529. package/dist/dispatch/engines/hooks-engine.d.ts +96 -0
  530. package/dist/dispatch/engines/hooks-engine.d.ts.map +1 -0
  531. package/dist/dispatch/engines/hooks-engine.js +144 -0
  532. package/dist/dispatch/engines/hooks-engine.js.map +1 -0
  533. package/dist/dispatch/engines/init-engine.d.ts +56 -0
  534. package/dist/dispatch/engines/init-engine.d.ts.map +1 -0
  535. package/dist/dispatch/engines/init-engine.js +78 -0
  536. package/dist/dispatch/engines/init-engine.js.map +1 -0
  537. package/dist/dispatch/engines/lifecycle-engine.d.ts +66 -0
  538. package/dist/dispatch/engines/lifecycle-engine.d.ts.map +1 -0
  539. package/dist/dispatch/engines/lifecycle-engine.js +224 -0
  540. package/dist/dispatch/engines/lifecycle-engine.js.map +1 -0
  541. package/dist/dispatch/engines/memory-engine.d.ts +10 -0
  542. package/dist/dispatch/engines/memory-engine.d.ts.map +1 -0
  543. package/dist/dispatch/engines/memory-engine.js +10 -0
  544. package/dist/dispatch/engines/memory-engine.js.map +1 -0
  545. package/dist/dispatch/engines/nexus-engine.d.ts +167 -0
  546. package/dist/dispatch/engines/nexus-engine.d.ts.map +1 -0
  547. package/dist/dispatch/engines/nexus-engine.js +356 -0
  548. package/dist/dispatch/engines/nexus-engine.js.map +1 -0
  549. package/dist/dispatch/engines/orchestrate-engine.d.ts +133 -0
  550. package/dist/dispatch/engines/orchestrate-engine.d.ts.map +1 -0
  551. package/dist/dispatch/engines/orchestrate-engine.js +769 -0
  552. package/dist/dispatch/engines/orchestrate-engine.js.map +1 -0
  553. package/dist/dispatch/engines/pipeline-engine.d.ts +51 -0
  554. package/dist/dispatch/engines/pipeline-engine.d.ts.map +1 -0
  555. package/dist/dispatch/engines/pipeline-engine.js +191 -0
  556. package/dist/dispatch/engines/pipeline-engine.js.map +1 -0
  557. package/dist/dispatch/engines/release-engine.d.ts +94 -0
  558. package/dist/dispatch/engines/release-engine.d.ts.map +1 -0
  559. package/dist/dispatch/engines/release-engine.js +763 -0
  560. package/dist/dispatch/engines/release-engine.js.map +1 -0
  561. package/dist/dispatch/engines/session-engine.d.ts +383 -0
  562. package/dist/dispatch/engines/session-engine.d.ts.map +1 -0
  563. package/dist/dispatch/engines/session-engine.js +960 -0
  564. package/dist/dispatch/engines/session-engine.js.map +1 -0
  565. package/dist/dispatch/engines/sticky-engine.d.ts +100 -0
  566. package/dist/dispatch/engines/sticky-engine.d.ts.map +1 -0
  567. package/dist/dispatch/engines/sticky-engine.js +181 -0
  568. package/dist/dispatch/engines/sticky-engine.js.map +1 -0
  569. package/dist/dispatch/engines/system-engine.d.ts +539 -0
  570. package/dist/dispatch/engines/system-engine.d.ts.map +1 -0
  571. package/dist/dispatch/engines/system-engine.js +1266 -0
  572. package/dist/dispatch/engines/system-engine.js.map +1 -0
  573. package/dist/dispatch/engines/task-engine.d.ts +1055 -0
  574. package/dist/dispatch/engines/task-engine.d.ts.map +1 -0
  575. package/dist/dispatch/engines/task-engine.js +1387 -0
  576. package/dist/dispatch/engines/task-engine.js.map +1 -0
  577. package/dist/dispatch/engines/template-parser.d.ts +85 -0
  578. package/dist/dispatch/engines/template-parser.d.ts.map +1 -0
  579. package/dist/dispatch/engines/template-parser.js +108 -0
  580. package/dist/dispatch/engines/template-parser.js.map +1 -0
  581. package/dist/dispatch/engines/tools-engine.d.ts +270 -0
  582. package/dist/dispatch/engines/tools-engine.d.ts.map +1 -0
  583. package/dist/dispatch/engines/tools-engine.js +636 -0
  584. package/dist/dispatch/engines/tools-engine.js.map +1 -0
  585. package/dist/dispatch/engines/validate-engine.d.ts +218 -0
  586. package/dist/dispatch/engines/validate-engine.d.ts.map +1 -0
  587. package/dist/dispatch/engines/validate-engine.js +737 -0
  588. package/dist/dispatch/engines/validate-engine.js.map +1 -0
  589. package/dist/dispatch/index.d.ts +20 -0
  590. package/dist/dispatch/index.d.ts.map +1 -0
  591. package/dist/dispatch/index.js +19 -0
  592. package/dist/dispatch/index.js.map +1 -0
  593. package/dist/dispatch/lib/background-jobs.d.ts +86 -0
  594. package/dist/dispatch/lib/background-jobs.d.ts.map +1 -0
  595. package/dist/dispatch/lib/background-jobs.js +183 -0
  596. package/dist/dispatch/lib/background-jobs.js.map +1 -0
  597. package/dist/dispatch/lib/budget.d.ts +35 -0
  598. package/dist/dispatch/lib/budget.d.ts.map +1 -0
  599. package/dist/dispatch/lib/budget.js +102 -0
  600. package/dist/dispatch/lib/budget.js.map +1 -0
  601. package/dist/dispatch/lib/capability-matrix.d.ts +11 -0
  602. package/dist/dispatch/lib/capability-matrix.d.ts.map +1 -0
  603. package/dist/dispatch/lib/capability-matrix.js +10 -0
  604. package/dist/dispatch/lib/capability-matrix.js.map +1 -0
  605. package/dist/dispatch/lib/config-loader.d.ts +42 -0
  606. package/dist/dispatch/lib/config-loader.d.ts.map +1 -0
  607. package/dist/dispatch/lib/config-loader.js +217 -0
  608. package/dist/dispatch/lib/config-loader.js.map +1 -0
  609. package/dist/dispatch/lib/config.d.ts +11 -0
  610. package/dist/dispatch/lib/config.d.ts.map +1 -0
  611. package/dist/dispatch/lib/config.js +10 -0
  612. package/dist/dispatch/lib/config.js.map +1 -0
  613. package/dist/dispatch/lib/defaults.d.ts +117 -0
  614. package/dist/dispatch/lib/defaults.d.ts.map +1 -0
  615. package/dist/dispatch/lib/defaults.js +58 -0
  616. package/dist/dispatch/lib/defaults.js.map +1 -0
  617. package/dist/dispatch/lib/engine.d.ts +26 -0
  618. package/dist/dispatch/lib/engine.d.ts.map +1 -0
  619. package/dist/dispatch/lib/engine.js +46 -0
  620. package/dist/dispatch/lib/engine.js.map +1 -0
  621. package/dist/dispatch/lib/gateway-meta.d.ts +37 -0
  622. package/dist/dispatch/lib/gateway-meta.d.ts.map +1 -0
  623. package/dist/dispatch/lib/gateway-meta.js +50 -0
  624. package/dist/dispatch/lib/gateway-meta.js.map +1 -0
  625. package/dist/dispatch/lib/job-manager-accessor.d.ts +9 -0
  626. package/dist/dispatch/lib/job-manager-accessor.d.ts.map +1 -0
  627. package/dist/dispatch/lib/job-manager-accessor.js +13 -0
  628. package/dist/dispatch/lib/job-manager-accessor.js.map +1 -0
  629. package/dist/dispatch/lib/meta.d.ts +26 -0
  630. package/dist/dispatch/lib/meta.d.ts.map +1 -0
  631. package/dist/dispatch/lib/meta.js +37 -0
  632. package/dist/dispatch/lib/meta.js.map +1 -0
  633. package/dist/dispatch/lib/param-utils.d.ts +11 -0
  634. package/dist/dispatch/lib/param-utils.d.ts.map +1 -0
  635. package/dist/dispatch/lib/param-utils.js +10 -0
  636. package/dist/dispatch/lib/param-utils.js.map +1 -0
  637. package/dist/dispatch/lib/projections.d.ts +56 -0
  638. package/dist/dispatch/lib/projections.d.ts.map +1 -0
  639. package/dist/dispatch/lib/projections.js +65 -0
  640. package/dist/dispatch/lib/projections.js.map +1 -0
  641. package/dist/dispatch/lib/schema-utils.d.ts +39 -0
  642. package/dist/dispatch/lib/schema-utils.d.ts.map +1 -0
  643. package/dist/dispatch/lib/schema-utils.js +88 -0
  644. package/dist/dispatch/lib/schema-utils.js.map +1 -0
  645. package/dist/dispatch/lib/security.d.ts +11 -0
  646. package/dist/dispatch/lib/security.d.ts.map +1 -0
  647. package/dist/dispatch/lib/security.js +10 -0
  648. package/dist/dispatch/lib/security.js.map +1 -0
  649. package/dist/dispatch/middleware/audit.d.ts +23 -0
  650. package/dist/dispatch/middleware/audit.d.ts.map +1 -0
  651. package/dist/dispatch/middleware/audit.js +169 -0
  652. package/dist/dispatch/middleware/audit.js.map +1 -0
  653. package/dist/dispatch/middleware/field-filter.d.ts +24 -0
  654. package/dist/dispatch/middleware/field-filter.d.ts.map +1 -0
  655. package/dist/dispatch/middleware/field-filter.js +65 -0
  656. package/dist/dispatch/middleware/field-filter.js.map +1 -0
  657. package/dist/dispatch/middleware/pipeline.d.ts +33 -0
  658. package/dist/dispatch/middleware/pipeline.d.ts.map +1 -0
  659. package/dist/dispatch/middleware/pipeline.js +60 -0
  660. package/dist/dispatch/middleware/pipeline.js.map +1 -0
  661. package/dist/dispatch/middleware/projection.d.ts +35 -0
  662. package/dist/dispatch/middleware/projection.d.ts.map +1 -0
  663. package/dist/dispatch/middleware/projection.js +146 -0
  664. package/dist/dispatch/middleware/projection.js.map +1 -0
  665. package/dist/dispatch/middleware/protocol-enforcement.d.ts +27 -0
  666. package/dist/dispatch/middleware/protocol-enforcement.d.ts.map +1 -0
  667. package/dist/dispatch/middleware/protocol-enforcement.js +45 -0
  668. package/dist/dispatch/middleware/protocol-enforcement.js.map +1 -0
  669. package/dist/dispatch/middleware/rate-limiter.d.ts +72 -0
  670. package/dist/dispatch/middleware/rate-limiter.d.ts.map +1 -0
  671. package/dist/dispatch/middleware/rate-limiter.js +127 -0
  672. package/dist/dispatch/middleware/rate-limiter.js.map +1 -0
  673. package/dist/dispatch/middleware/sanitizer.d.ts +24 -0
  674. package/dist/dispatch/middleware/sanitizer.d.ts.map +1 -0
  675. package/dist/dispatch/middleware/sanitizer.js +56 -0
  676. package/dist/dispatch/middleware/sanitizer.js.map +1 -0
  677. package/dist/dispatch/middleware/session-resolver.d.ts +26 -0
  678. package/dist/dispatch/middleware/session-resolver.d.ts.map +1 -0
  679. package/dist/dispatch/middleware/session-resolver.js +65 -0
  680. package/dist/dispatch/middleware/session-resolver.js.map +1 -0
  681. package/dist/dispatch/middleware/verification-gates.d.ts +22 -0
  682. package/dist/dispatch/middleware/verification-gates.d.ts.map +1 -0
  683. package/dist/dispatch/middleware/verification-gates.js +59 -0
  684. package/dist/dispatch/middleware/verification-gates.js.map +1 -0
  685. package/dist/dispatch/registry.d.ts +91 -0
  686. package/dist/dispatch/registry.d.ts.map +1 -0
  687. package/dist/dispatch/registry.js +3133 -0
  688. package/dist/dispatch/registry.js.map +1 -0
  689. package/dist/dispatch/types.d.ts +202 -0
  690. package/dist/dispatch/types.d.ts.map +1 -0
  691. package/dist/dispatch/types.js +26 -0
  692. package/dist/dispatch/types.js.map +1 -0
  693. package/package.json +7 -7
@@ -0,0 +1,960 @@
1
+ /**
2
+ * Session Engine — thin wrapper layer.
3
+ *
4
+ * Delegates all business logic to src/core/sessions/ and src/core/task-work/.
5
+ * Each function catches errors from core and wraps them into EngineResult.
6
+ *
7
+ * @task T4782
8
+ * @epic T4654
9
+ */
10
+ import { getExitCodeName } from '@cleocode/contracts';
11
+ // ... existing imports ...
12
+ import { archiveSessions, CleoError, cleanupSessions, computeBriefing, computeDebrief, computeHandoff, currentTask, findSessions, generateSessionId, getAccessor, getContextDrift, getDecisionLog, getLastHandoff, getSessionHistory, getSessionStats, getTaskHistory, injectContext, paginate, parseScope, persistHandoff, recordAssumption, recordDecision, showSession, startTask, stopTask, suspendSession, switchSession, } from '@cleocode/core/internal';
13
+ import { engineError } from './_error.js';
14
+ /**
15
+ * Get current session status.
16
+ *
17
+ * @remarks
18
+ * Returns whether there is an active session, along with the session record
19
+ * and current task work state if available.
20
+ *
21
+ * @param projectRoot - Absolute path to the project root
22
+ * @returns EngineResult with active session flag, session record, and task work state
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const result = await sessionStatus('/project');
27
+ * if (result.success && result.data.hasActiveSession) {
28
+ * console.log(result.data.session?.id);
29
+ * }
30
+ * ```
31
+ *
32
+ * @task T4782
33
+ */
34
+ export async function sessionStatus(projectRoot) {
35
+ try {
36
+ const accessor = await getAccessor(projectRoot);
37
+ const focusState = await accessor.getMetaValue('focus_state');
38
+ const sessions = await accessor.loadSessions();
39
+ const active = sessions.find((s) => s.status === 'active');
40
+ return {
41
+ success: true,
42
+ data: {
43
+ hasActiveSession: !!active,
44
+ session: active || null,
45
+ taskWork: focusState || null,
46
+ },
47
+ };
48
+ }
49
+ catch {
50
+ return engineError('E_NOT_INITIALIZED', 'Task database not initialized');
51
+ }
52
+ }
53
+ /** Default limit for sessionList when none is provided. @task T5121 */
54
+ const SESSION_LIST_DEFAULT_LIMIT = 10;
55
+ /**
56
+ * List sessions with budget enforcement.
57
+ *
58
+ * When a limit is applied (explicit or default), the response includes
59
+ * `_meta.truncated` and `_meta.total` so agents know the result set
60
+ * was capped.
61
+ *
62
+ * @remarks
63
+ * Defaults to 10 results when no explicit limit is provided to protect
64
+ * agent context budgets. Use offset for pagination.
65
+ *
66
+ * @param projectRoot - Absolute path to the project root
67
+ * @param params - Optional filter and pagination parameters
68
+ * @returns EngineResult with sessions array, total, filtered count, and truncation metadata
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * const result = await sessionList('/project', { active: true, limit: 5 });
73
+ * ```
74
+ *
75
+ * @task T4782
76
+ * @task T5120 - budget enforcement metadata
77
+ * @task T5121 - default limit=10
78
+ */
79
+ export async function sessionList(projectRoot, params) {
80
+ try {
81
+ const accessor = await getAccessor(projectRoot);
82
+ const sessions = await accessor.loadSessions();
83
+ let result = sessions;
84
+ if (params?.status) {
85
+ result = result.filter((s) => s.status === params.status);
86
+ }
87
+ else if (params?.active === true) {
88
+ result = result.filter((s) => s.status === 'active');
89
+ }
90
+ else if (params?.active === false) {
91
+ result = result.filter((s) => s.status !== 'active');
92
+ }
93
+ const total = sessions.length;
94
+ const filtered = result.length;
95
+ const limit = params?.limit && params.limit > 0 ? params.limit : SESSION_LIST_DEFAULT_LIMIT;
96
+ const offset = typeof params?.offset === 'number' && params.offset > 0 ? params.offset : 0;
97
+ const pageResult = paginate(result, limit, offset);
98
+ const truncated = filtered !== pageResult.items.length || offset > 0;
99
+ return {
100
+ success: true,
101
+ data: {
102
+ sessions: pageResult.items,
103
+ total,
104
+ filtered,
105
+ _meta: { truncated, total: filtered },
106
+ },
107
+ page: pageResult.page,
108
+ };
109
+ }
110
+ catch {
111
+ return engineError('E_NOT_INITIALIZED', 'Task database not initialized');
112
+ }
113
+ }
114
+ /**
115
+ * Lightweight session discovery -- returns minimal session records.
116
+ *
117
+ * @remarks
118
+ * Optimized for low context cost. Returns only essential fields (ID, status,
119
+ * scope, timestamps) without full session details.
120
+ *
121
+ * @param projectRoot - Absolute path to the project root
122
+ * @param params - Optional search parameters
123
+ * @returns EngineResult with array of minimal session records
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * const result = await sessionFind('/project', { status: 'active' });
128
+ * ```
129
+ *
130
+ * @task T5119
131
+ */
132
+ export async function sessionFind(projectRoot, params) {
133
+ try {
134
+ const accessor = await getAccessor(projectRoot);
135
+ const result = await findSessions(accessor, params);
136
+ return { success: true, data: result };
137
+ }
138
+ catch {
139
+ return engineError('E_NOT_INITIALIZED', 'Task database not initialized');
140
+ }
141
+ }
142
+ /**
143
+ * Show a specific session by ID.
144
+ *
145
+ * @remarks
146
+ * Returns the full session record including scope, status, timestamps,
147
+ * and associated task data.
148
+ *
149
+ * @param projectRoot - Absolute path to the project root
150
+ * @param sessionId - Session identifier to look up
151
+ * @returns EngineResult with the full Session record
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * const result = await sessionShow('/project', 'ses_20260401_abc123');
156
+ * ```
157
+ *
158
+ * @task T4782
159
+ */
160
+ export async function sessionShow(projectRoot, sessionId) {
161
+ try {
162
+ const result = await showSession(projectRoot, sessionId);
163
+ return { success: true, data: result };
164
+ }
165
+ catch (err) {
166
+ const message = err.message;
167
+ const code = message.includes('not found') ? 'E_NOT_FOUND' : 'E_NOT_INITIALIZED';
168
+ return engineError(code, message);
169
+ }
170
+ }
171
+ /**
172
+ * Get current task being worked on.
173
+ * Delegates to core/task-work/currentTask.
174
+ * @task T4782
175
+ */
176
+ export async function taskCurrentGet(projectRoot) {
177
+ try {
178
+ const accessor = await getAccessor(projectRoot);
179
+ const result = await currentTask(undefined, accessor);
180
+ return {
181
+ success: true,
182
+ data: {
183
+ currentTask: result.currentTask,
184
+ currentPhase: result.currentPhase,
185
+ },
186
+ };
187
+ }
188
+ catch {
189
+ return engineError('E_NOT_INITIALIZED', 'Task database not initialized');
190
+ }
191
+ }
192
+ /**
193
+ * Start working on a specific task.
194
+ * Delegates to core/task-work/startTask.
195
+ * @task T4782
196
+ */
197
+ export async function taskStart(projectRoot, taskId) {
198
+ try {
199
+ const accessor = await getAccessor(projectRoot);
200
+ const result = await startTask(taskId, undefined, accessor);
201
+ return {
202
+ success: true,
203
+ data: { taskId: result.taskId, previousTask: result.previousTask },
204
+ };
205
+ }
206
+ catch (err) {
207
+ if (err instanceof CleoError) {
208
+ const stringCode = `E_${getExitCodeName(err.code)}`;
209
+ return engineError(stringCode, err.message, {
210
+ ...(err.fix && { fix: err.fix }),
211
+ });
212
+ }
213
+ const message = err.message;
214
+ const code = message.includes('not found') ? 'E_NOT_FOUND' : 'E_NOT_INITIALIZED';
215
+ return engineError(code, message);
216
+ }
217
+ }
218
+ /**
219
+ * Stop working on the current task.
220
+ * Delegates to core/task-work/stopTask.
221
+ * @task T4782
222
+ */
223
+ export async function taskStop(projectRoot) {
224
+ try {
225
+ const accessor = await getAccessor(projectRoot);
226
+ const result = await stopTask(undefined, accessor);
227
+ return {
228
+ success: true,
229
+ data: { cleared: true, previousTask: result.previousTask },
230
+ };
231
+ }
232
+ catch {
233
+ return engineError('E_NOT_INITIALIZED', 'Task database not initialized');
234
+ }
235
+ }
236
+ /**
237
+ * Get task work history from session notes.
238
+ * @task T5323
239
+ */
240
+ export async function taskWorkHistory(projectRoot) {
241
+ try {
242
+ const accessor = await getAccessor(projectRoot);
243
+ const history = await getTaskHistory(undefined, accessor);
244
+ return {
245
+ success: true,
246
+ data: { history, count: history.length },
247
+ };
248
+ }
249
+ catch {
250
+ return engineError('E_NOT_INITIALIZED', 'Task database not initialized');
251
+ }
252
+ }
253
+ /**
254
+ * Start a new session.
255
+ * Note: This function has engine-specific logic for task file focus management
256
+ * and session store updates, so it remains in the engine layer.
257
+ * @task T4782
258
+ */
259
+ export async function sessionStart(projectRoot, params) {
260
+ try {
261
+ let accessor = await getAccessor(projectRoot);
262
+ // Validate scope BEFORE auto-ending active session (prevents data loss on invalid input)
263
+ let scope;
264
+ try {
265
+ scope = parseScope(params.scope);
266
+ }
267
+ catch (err) {
268
+ return engineError('E_INVALID_INPUT', err instanceof Error ? err.message : 'Invalid scope');
269
+ }
270
+ // For non-global scopes, verify root task exists before auto-ending
271
+ if (scope.type !== 'global') {
272
+ const rootTask = await accessor.loadSingleTask(scope.rootTaskId);
273
+ if (!rootTask) {
274
+ return engineError('E_NOT_FOUND', `Root task '${scope.rootTaskId}' not found`);
275
+ }
276
+ }
277
+ // Auto-end any active session before starting a new one
278
+ const existingActive = await accessor.getActiveSession();
279
+ if (existingActive) {
280
+ await sessionEnd(projectRoot);
281
+ // Reload after auto-end
282
+ accessor = await getAccessor(projectRoot);
283
+ }
284
+ const now = new Date().toISOString();
285
+ const sessionId = generateSessionId();
286
+ // T4959: Chain linking — find most recent ended session for same scope
287
+ let previousSessionId = null;
288
+ {
289
+ const sessions = await accessor.loadSessions();
290
+ const sameScope = sessions
291
+ .filter((s) => s.status === 'ended' &&
292
+ s.endedAt &&
293
+ s.scope?.type === scope.type &&
294
+ (scope.type === 'global' || s.scope?.rootTaskId === scope.rootTaskId))
295
+ .sort((a, b) => new Date(b.endedAt).getTime() - new Date(a.endedAt).getTime());
296
+ if (sameScope.length > 0) {
297
+ previousSessionId = sameScope[0].id;
298
+ }
299
+ }
300
+ // Resolve agent identifier from params or env
301
+ const agentIdentifier = params.agentIdentifier ??
302
+ process.env.CLEO_AGENT_ID ??
303
+ null;
304
+ const rootTaskId = scope.type !== 'global' ? scope.rootTaskId : undefined;
305
+ const startingTaskId = params.startTask || (params.autoStart && rootTaskId ? rootTaskId : null);
306
+ const newSession = {
307
+ id: sessionId,
308
+ status: 'active',
309
+ name: params.name || `session-${sessionId}`,
310
+ scope: scope.type === 'global'
311
+ ? { type: 'global' }
312
+ : { type: scope.type, rootTaskId: scope.rootTaskId, includeDescendants: true },
313
+ taskWork: {
314
+ taskId: startingTaskId,
315
+ setAt: now,
316
+ },
317
+ startedAt: now,
318
+ resumeCount: 0,
319
+ ...(params.grade ? { gradeMode: true } : {}),
320
+ stats: {
321
+ tasksCompleted: 0,
322
+ tasksCreated: 0,
323
+ tasksUpdated: 0,
324
+ focusChanges: 0,
325
+ totalActiveMinutes: 0,
326
+ suspendCount: 0,
327
+ },
328
+ };
329
+ // Update focus state via metadata
330
+ const existingFocus = (await accessor.getMetaValue('focus_state')) ?? {
331
+ currentTask: null,
332
+ currentPhase: null,
333
+ blockedUntil: null,
334
+ sessionNote: null,
335
+ sessionNotes: [],
336
+ nextAction: null,
337
+ primarySession: null,
338
+ };
339
+ const startingTask = params.startTask;
340
+ if (startingTask) {
341
+ existingFocus.currentTask = startingTask;
342
+ }
343
+ else if (params.autoStart && rootTaskId) {
344
+ existingFocus.currentTask = rootTaskId;
345
+ }
346
+ await accessor.setMetaValue('focus_state', existingFocus);
347
+ // Update file meta (activeSession no longer stored — session.status is source of truth)
348
+ const currentMeta = (await accessor.getMetaValue('file_meta')) ?? {};
349
+ currentMeta.lastSessionId = sessionId;
350
+ currentMeta.generation = (currentMeta.generation || 0) + 1;
351
+ await accessor.setMetaValue('file_meta', currentMeta);
352
+ // T4959: Set chain fields on new session
353
+ if (previousSessionId) {
354
+ newSession.previousSessionId = previousSessionId;
355
+ }
356
+ if (agentIdentifier) {
357
+ newSession.agentIdentifier = agentIdentifier;
358
+ }
359
+ // Insert new session FIRST — FK constraints require the target row to exist
360
+ // before predecessor.nextSessionId can reference it.
361
+ await accessor.upsertSingleSession(newSession);
362
+ // Now update predecessor's nextSessionId (new session row exists for FK)
363
+ if (previousSessionId) {
364
+ const sessions = await accessor.loadSessions();
365
+ const pred = sessions.find((s) => s.id === previousSessionId);
366
+ if (pred) {
367
+ pred.nextSessionId = sessionId;
368
+ await accessor.upsertSingleSession(pred);
369
+ }
370
+ }
371
+ // Enable grade mode: set env vars so audit middleware logs queries too
372
+ if (params.grade) {
373
+ process.env.CLEO_SESSION_GRADE = 'true';
374
+ process.env.CLEO_SESSION_ID = sessionId;
375
+ process.env.CLEO_SESSION_GRADE_ID = sessionId;
376
+ }
377
+ // T4959: Auto-briefing — enrich response with briefing + predecessor debrief
378
+ let briefing = null;
379
+ let previousDebrief = null;
380
+ try {
381
+ briefing = await computeBriefing(projectRoot, { scope: params.scope });
382
+ }
383
+ catch {
384
+ // Best-effort — briefing failure should not fail session start
385
+ }
386
+ // 5B: Load predecessor debrief/handoff and mark consumed
387
+ let previousHandoff = null;
388
+ if (previousSessionId) {
389
+ try {
390
+ const sessions2 = await accessor.loadSessions();
391
+ const pred = sessions2.find((s) => s.id === previousSessionId);
392
+ if (pred) {
393
+ // Try debriefJson first (rich data), then handoffJson (basic)
394
+ if (pred.debriefJson) {
395
+ previousDebrief = JSON.parse(pred.debriefJson);
396
+ }
397
+ else if (pred.handoffJson) {
398
+ previousHandoff = JSON.parse(pred.handoffJson);
399
+ }
400
+ // Always mark consumed regardless of debrief vs handoff
401
+ pred.handoffConsumedAt = new Date().toISOString();
402
+ pred.handoffConsumedBy = sessionId;
403
+ await accessor.upsertSingleSession(pred);
404
+ }
405
+ }
406
+ catch {
407
+ // Best-effort
408
+ }
409
+ }
410
+ const enrichedSession = {
411
+ ...newSession,
412
+ ...(briefing && { briefing }),
413
+ ...(previousDebrief && { previousDebrief }),
414
+ ...(previousHandoff && { previousHandoff }),
415
+ };
416
+ return { success: true, data: enrichedSession };
417
+ }
418
+ catch {
419
+ return engineError('E_NOT_INITIALIZED', 'Task database not initialized');
420
+ }
421
+ }
422
+ /**
423
+ * End the current session.
424
+ * Note: This function has engine-specific logic for task file focus management
425
+ * and session store management, so it remains in the engine layer.
426
+ * @task T4782
427
+ * @task T140 @epic T134 - Summarization wiring
428
+ */
429
+ export async function sessionEnd(projectRoot, notes, params) {
430
+ try {
431
+ const accessor = await getAccessor(projectRoot);
432
+ const activeSession = await accessor.getActiveSession();
433
+ const sessionId = activeSession?.id;
434
+ if (!sessionId) {
435
+ return engineError('E_SESSION_NOT_FOUND', 'No active session to end', {
436
+ fix: 'Start a session first with: session start --scope <scope> --name <name>',
437
+ });
438
+ }
439
+ const now = new Date().toISOString();
440
+ // NOTE: Do NOT clear grade mode env vars here — gradeSession() needs them
441
+ // to query audit entries after the session ends. The caller (admin.grade handler)
442
+ // is responsible for cleanup after evaluation completes.
443
+ // Clear focus
444
+ const focusEnd = await accessor.getMetaValue('focus_state');
445
+ if (focusEnd) {
446
+ focusEnd.currentTask = null;
447
+ if (notes) {
448
+ if (!focusEnd.sessionNotes)
449
+ focusEnd.sessionNotes = [];
450
+ focusEnd.sessionNotes.push({ timestamp: now, note: notes });
451
+ }
452
+ await accessor.setMetaValue('focus_state', focusEnd);
453
+ }
454
+ // Bump file_meta generation (activeSession no longer stored here)
455
+ const fileMetaEnd = await accessor.getMetaValue('file_meta');
456
+ if (fileMetaEnd) {
457
+ fileMetaEnd.generation = (fileMetaEnd.generation || 0) + 1;
458
+ await accessor.setMetaValue('file_meta', fileMetaEnd);
459
+ }
460
+ // Update session record — status is the source of truth
461
+ if (sessionId !== 'default') {
462
+ activeSession.status = 'ended';
463
+ activeSession.endedAt = now;
464
+ await accessor.upsertSingleSession(activeSession);
465
+ }
466
+ // T140: Build summarization prompt and ingest structured summary if provided
467
+ let memoryPrompt;
468
+ try {
469
+ const { loadConfig } = await import('@cleocode/core/internal');
470
+ const config = await loadConfig(projectRoot);
471
+ if (config.brain?.summarization?.enabled) {
472
+ // Fetch the debrief if available to build a summarization prompt
473
+ const sessions = await accessor.loadSessions();
474
+ const endedSession = sessions.find((s) => s.id === sessionId);
475
+ if (endedSession?.debriefJson) {
476
+ try {
477
+ const debrief = JSON.parse(endedSession.debriefJson);
478
+ const { buildSummarizationPrompt } = await import('@cleocode/core/internal');
479
+ const prompt = buildSummarizationPrompt(sessionId, debrief);
480
+ if (prompt)
481
+ memoryPrompt = prompt;
482
+ }
483
+ catch {
484
+ // Best-effort
485
+ }
486
+ }
487
+ }
488
+ // Ingest structured summary if provided by caller (e.g. from CLI --summary flag)
489
+ if (params?.sessionSummary) {
490
+ const { ingestStructuredSummary } = await import('@cleocode/core/internal');
491
+ await ingestStructuredSummary(projectRoot, sessionId, params.sessionSummary);
492
+ }
493
+ }
494
+ catch {
495
+ // Summarization must never block session end
496
+ }
497
+ return {
498
+ success: true,
499
+ data: { sessionId, ended: true, ...(memoryPrompt && { memoryPrompt }) },
500
+ };
501
+ }
502
+ catch {
503
+ return engineError('E_NOT_INITIALIZED', 'Task database not initialized');
504
+ }
505
+ }
506
+ /**
507
+ * Resume an ended or suspended session.
508
+ * Note: This function has engine-specific logic for task file focus sync,
509
+ * so it remains in the engine layer.
510
+ * @task T4782
511
+ */
512
+ export async function sessionResume(projectRoot, sessionId) {
513
+ try {
514
+ const accessor = await getAccessor(projectRoot);
515
+ // Look up sessions from the store.
516
+ const sessions = await accessor.loadSessions();
517
+ // Look in sessions list
518
+ const session = sessions.find((s) => s.id === sessionId);
519
+ if (!session) {
520
+ return engineError('E_NOT_FOUND', `Session '${sessionId}' not found`);
521
+ }
522
+ if (session.status === 'active') {
523
+ return { success: true, data: session };
524
+ }
525
+ if (session.status === 'archived') {
526
+ return engineError('E_INVALID_INPUT', `Session '${sessionId}' is archived and cannot be resumed`);
527
+ }
528
+ session.status = 'active';
529
+ session.endedAt = undefined;
530
+ session.resumeCount = (session.resumeCount || 0) + 1;
531
+ // Bump file_meta generation (activeSession no longer stored — status is source of truth)
532
+ const resumeMeta = (await accessor.getMetaValue('file_meta')) ?? {};
533
+ resumeMeta.generation = (resumeMeta.generation || 0) + 1;
534
+ await accessor.setMetaValue('file_meta', resumeMeta);
535
+ // Restore focus from session task work
536
+ if (session.taskWork?.taskId) {
537
+ const resumeFocus = await accessor.getMetaValue('focus_state');
538
+ if (resumeFocus) {
539
+ resumeFocus.currentTask = session.taskWork.taskId;
540
+ await accessor.setMetaValue('focus_state', resumeFocus);
541
+ }
542
+ }
543
+ await accessor.upsertSingleSession(session);
544
+ // Wave 3B: Enrich resumed session with brain memory context (best-effort)
545
+ let memoryContext;
546
+ try {
547
+ const { getSessionMemoryContext } = await import('@cleocode/core/internal');
548
+ const scopeType = session.scope?.type;
549
+ const rootTaskId = session.scope?.rootTaskId;
550
+ memoryContext = await getSessionMemoryContext(projectRoot, {
551
+ type: scopeType ?? 'global',
552
+ rootTaskId,
553
+ epicId: rootTaskId,
554
+ });
555
+ }
556
+ catch {
557
+ // Best-effort -- memory context failure should not fail resume
558
+ }
559
+ const enrichedSession = {
560
+ ...session,
561
+ ...(memoryContext && { memoryContext }),
562
+ };
563
+ return { success: true, data: enrichedSession };
564
+ }
565
+ catch {
566
+ return engineError('E_NOT_INITIALIZED', 'Task database not initialized');
567
+ }
568
+ }
569
+ /**
570
+ * Garbage collect old sessions.
571
+ * @task T4782
572
+ */
573
+ export async function sessionGc(projectRoot, maxAgeDays = 1) {
574
+ try {
575
+ const accessor = await getAccessor(projectRoot);
576
+ const sessions = await accessor.loadSessions();
577
+ const now = Date.now();
578
+ const maxAgeMs = maxAgeDays * 24 * 60 * 60 * 1000;
579
+ const thirtyDaysMs = 30 * 24 * 60 * 60 * 1000;
580
+ const orphaned = [];
581
+ const removed = [];
582
+ // Mark stale active sessions as orphaned
583
+ for (const session of sessions) {
584
+ if (session.status === 'active') {
585
+ const lastActive = new Date(session.endedAt || session.startedAt).getTime();
586
+ if (now - lastActive > maxAgeMs) {
587
+ session.status = 'ended';
588
+ session.endedAt = new Date().toISOString();
589
+ orphaned.push(session.id);
590
+ await accessor.upsertSingleSession(session);
591
+ }
592
+ }
593
+ }
594
+ // Remove very old ended sessions
595
+ for (const s of sessions) {
596
+ if (s.status === 'active')
597
+ continue;
598
+ const endedAt = s.endedAt ? new Date(s.endedAt).getTime() : new Date(s.startedAt).getTime();
599
+ if (now - endedAt > thirtyDaysMs) {
600
+ removed.push(s.id);
601
+ await accessor.removeSingleSession(s.id);
602
+ }
603
+ }
604
+ return { success: true, data: { orphaned, removed } };
605
+ }
606
+ catch {
607
+ return engineError('E_NOT_INITIALIZED', 'Task database not initialized');
608
+ }
609
+ }
610
+ /**
611
+ * Suspend an active session.
612
+ * @task T4782
613
+ */
614
+ export async function sessionSuspend(projectRoot, sessionId, reason) {
615
+ try {
616
+ const result = await suspendSession(projectRoot, sessionId, reason);
617
+ return { success: true, data: result };
618
+ }
619
+ catch (err) {
620
+ const message = err.message;
621
+ const code = message.includes('not found')
622
+ ? 'E_NOT_FOUND'
623
+ : message.includes('not active')
624
+ ? 'E_INVALID_STATE'
625
+ : 'E_NOT_INITIALIZED';
626
+ return engineError(code, message);
627
+ }
628
+ }
629
+ /**
630
+ * List session history with focus changes and completed tasks.
631
+ * @task T4782
632
+ */
633
+ export async function sessionHistory(projectRoot, params) {
634
+ try {
635
+ const result = await getSessionHistory(projectRoot, params);
636
+ return { success: true, data: result };
637
+ }
638
+ catch {
639
+ return engineError('E_NOT_INITIALIZED', 'Task database not initialized');
640
+ }
641
+ }
642
+ /**
643
+ * Remove orphaned sessions and clean up stale data.
644
+ * @task T4782
645
+ */
646
+ export async function sessionCleanup(projectRoot) {
647
+ try {
648
+ const result = await cleanupSessions(projectRoot);
649
+ return { success: true, data: result };
650
+ }
651
+ catch {
652
+ return engineError('E_NOT_INITIALIZED', 'Task database not initialized');
653
+ }
654
+ }
655
+ /**
656
+ * Record a decision to the audit trail.
657
+ * @task T4782
658
+ */
659
+ export async function sessionRecordDecision(projectRoot, params) {
660
+ try {
661
+ const result = await recordDecision(projectRoot, params);
662
+ return { success: true, data: result };
663
+ }
664
+ catch (err) {
665
+ const message = err.message;
666
+ return engineError('E_INVALID_INPUT', message);
667
+ }
668
+ }
669
+ /**
670
+ * Read the decision log, optionally filtered by sessionId and/or taskId.
671
+ * @task T4782
672
+ */
673
+ export async function sessionDecisionLog(projectRoot, params) {
674
+ try {
675
+ const result = await getDecisionLog(projectRoot, params);
676
+ return { success: true, data: result };
677
+ }
678
+ catch {
679
+ return { success: true, data: [] };
680
+ }
681
+ }
682
+ /**
683
+ * Compute context drift score for the current session.
684
+ * @task T4782
685
+ */
686
+ export async function sessionContextDrift(projectRoot, params) {
687
+ try {
688
+ const result = await getContextDrift(projectRoot, params);
689
+ return { success: true, data: result };
690
+ }
691
+ catch (err) {
692
+ const message = err.message;
693
+ const code = message.includes('not found') ? 'E_NOT_FOUND' : 'E_NOT_INITIALIZED';
694
+ return engineError(code, message);
695
+ }
696
+ }
697
+ /**
698
+ * Record an assumption made during a session.
699
+ * @task T4782
700
+ */
701
+ export async function sessionRecordAssumption(projectRoot, params) {
702
+ try {
703
+ const result = await recordAssumption(projectRoot, params);
704
+ return { success: true, data: result };
705
+ }
706
+ catch (err) {
707
+ const message = err.message;
708
+ const code = message.includes('required') || message.includes('must be')
709
+ ? 'E_INVALID_INPUT'
710
+ : 'E_NOT_INITIALIZED';
711
+ return engineError(code, message);
712
+ }
713
+ }
714
+ /**
715
+ * Compute session statistics, optionally for a specific session.
716
+ * @task T4782
717
+ */
718
+ export async function sessionStats(projectRoot, sessionId) {
719
+ try {
720
+ const result = await getSessionStats(projectRoot, sessionId);
721
+ return { success: true, data: result };
722
+ }
723
+ catch (err) {
724
+ const message = err.message;
725
+ const code = message.includes('not found') ? 'E_NOT_FOUND' : 'E_NOT_INITIALIZED';
726
+ return engineError(code, message);
727
+ }
728
+ }
729
+ /**
730
+ * Switch to a different session.
731
+ * @task T4782
732
+ */
733
+ export async function sessionSwitch(projectRoot, sessionId) {
734
+ try {
735
+ const result = await switchSession(projectRoot, sessionId);
736
+ return { success: true, data: result };
737
+ }
738
+ catch (err) {
739
+ const message = err.message;
740
+ const code = message.includes('not found')
741
+ ? 'E_NOT_FOUND'
742
+ : message.includes('archived')
743
+ ? 'E_INVALID_STATE'
744
+ : 'E_NOT_INITIALIZED';
745
+ return engineError(code, message);
746
+ }
747
+ }
748
+ /**
749
+ * Archive old/ended sessions.
750
+ * @task T4782
751
+ */
752
+ export async function sessionArchive(projectRoot, olderThan) {
753
+ try {
754
+ const result = await archiveSessions(projectRoot, olderThan);
755
+ return { success: true, data: result };
756
+ }
757
+ catch {
758
+ return engineError('E_NOT_INITIALIZED', 'Task database not initialized');
759
+ }
760
+ }
761
+ /**
762
+ * Get handoff data for the most recent ended session.
763
+ * @task T4915, T5123
764
+ */
765
+ export async function sessionHandoff(projectRoot, scope) {
766
+ try {
767
+ const result = await getLastHandoff(projectRoot, scope);
768
+ return { success: true, data: result };
769
+ }
770
+ catch (err) {
771
+ if (err instanceof CleoError) {
772
+ const stringCode = `E_${getExitCodeName(err.code)}`;
773
+ return engineError(stringCode, err.message, {
774
+ ...(err.fix && { fix: err.fix }),
775
+ });
776
+ }
777
+ const message = err instanceof Error ? err.message : String(err);
778
+ return engineError('E_GENERAL', message);
779
+ }
780
+ }
781
+ /**
782
+ * Compute and persist handoff data for a session.
783
+ * @task T4915
784
+ */
785
+ export async function sessionComputeHandoff(projectRoot, sessionId, options) {
786
+ try {
787
+ const handoff = await computeHandoff(projectRoot, {
788
+ sessionId,
789
+ note: options?.note,
790
+ nextAction: options?.nextAction,
791
+ });
792
+ await persistHandoff(projectRoot, sessionId, handoff);
793
+ return { success: true, data: handoff };
794
+ }
795
+ catch (err) {
796
+ const message = err.message;
797
+ return engineError(message.includes('not found') ? 'E_NOT_FOUND' : 'E_INTERNAL', message);
798
+ }
799
+ }
800
+ /**
801
+ * Compute session briefing - composite view for session start.
802
+ * Aggregates data from handoff, current focus, next tasks, bugs, blockers, and epics.
803
+ * @task T4916
804
+ */
805
+ export async function sessionBriefing(projectRoot, options) {
806
+ try {
807
+ const briefing = await computeBriefing(projectRoot, options);
808
+ return { success: true, data: briefing };
809
+ }
810
+ catch (err) {
811
+ const message = err.message;
812
+ return engineError(message.includes('not found') ? 'E_NOT_FOUND' : 'E_INTERNAL', message);
813
+ }
814
+ }
815
+ // =============================================================================
816
+ // RICH DEBRIEF + CHAIN OPERATIONS (T4959)
817
+ // =============================================================================
818
+ /**
819
+ * Compute and persist rich debrief data for a session.
820
+ * Persists as both handoffJson (backward compat) and debriefJson (rich data).
821
+ * @epic T4959
822
+ */
823
+ export async function sessionComputeDebrief(projectRoot, sessionId, options) {
824
+ try {
825
+ const accessor = await getAccessor(projectRoot);
826
+ const sessions = await accessor.loadSessions();
827
+ const session = sessions.find((s) => s.id === sessionId);
828
+ const debrief = await computeDebrief(projectRoot, {
829
+ sessionId,
830
+ note: options?.note,
831
+ nextAction: options?.nextAction,
832
+ agentIdentifier: session?.agentIdentifier ?? null,
833
+ startedAt: session?.startedAt,
834
+ endedAt: session?.endedAt ?? new Date().toISOString(),
835
+ });
836
+ // Persist both handoffJson and debriefJson
837
+ const { persistHandoff: corePersistHandoff } = await import('@cleocode/core/internal');
838
+ await corePersistHandoff(projectRoot, sessionId, debrief.handoff);
839
+ // Persist debriefJson via session update
840
+ if (session) {
841
+ session.debriefJson = JSON.stringify(debrief);
842
+ await accessor.upsertSingleSession(session);
843
+ }
844
+ return { success: true, data: debrief };
845
+ }
846
+ catch (err) {
847
+ const message = err.message;
848
+ return engineError(message.includes('not found') ? 'E_NOT_FOUND' : 'E_INTERNAL', message);
849
+ }
850
+ }
851
+ /**
852
+ * Read a session's debrief data.
853
+ * Falls back to handoff data if no debrief is available.
854
+ * @epic T4959
855
+ */
856
+ export async function sessionDebriefShow(projectRoot, sessionId) {
857
+ try {
858
+ const accessor = await getAccessor(projectRoot);
859
+ const sessions = await accessor.loadSessions();
860
+ const session = sessions.find((s) => s.id === sessionId);
861
+ if (!session) {
862
+ return engineError('E_NOT_FOUND', `Session '${sessionId}' not found`);
863
+ }
864
+ // Try debriefJson first
865
+ if (session.debriefJson) {
866
+ try {
867
+ const debrief = JSON.parse(session.debriefJson);
868
+ return { success: true, data: debrief };
869
+ }
870
+ catch {
871
+ // Fall through to handoff
872
+ }
873
+ }
874
+ // Fall back to handoffJson
875
+ if (typeof session.handoffJson === 'string') {
876
+ try {
877
+ const handoff = JSON.parse(session.handoffJson);
878
+ return { success: true, data: { handoff, fallback: true } };
879
+ }
880
+ catch {
881
+ // No data available
882
+ }
883
+ }
884
+ return { success: true, data: null };
885
+ }
886
+ catch (err) {
887
+ const message = err.message;
888
+ return engineError(message.includes('not found') ? 'E_NOT_FOUND' : 'E_INTERNAL', message);
889
+ }
890
+ }
891
+ /**
892
+ * Show the session chain for a given session.
893
+ * Returns ordered list of sessions linked via previousSessionId/nextSessionId.
894
+ * @epic T4959
895
+ */
896
+ export async function sessionChainShow(projectRoot, sessionId) {
897
+ try {
898
+ const accessor = await getAccessor(projectRoot);
899
+ const sessions = await accessor.loadSessions();
900
+ const sessionMap = new Map(sessions.map((s) => [s.id, s]));
901
+ const target = sessionMap.get(sessionId);
902
+ if (!target) {
903
+ return engineError('E_NOT_FOUND', `Session '${sessionId}' not found`);
904
+ }
905
+ // Walk backward to chain start
906
+ const chain = [sessionId];
907
+ const visited = new Set([sessionId]);
908
+ let current = target.previousSessionId;
909
+ while (current && !visited.has(current)) {
910
+ chain.unshift(current);
911
+ visited.add(current);
912
+ const s = sessionMap.get(current);
913
+ current = s?.previousSessionId ?? undefined;
914
+ }
915
+ // Walk forward from target
916
+ current = target.nextSessionId;
917
+ while (current && !visited.has(current)) {
918
+ chain.push(current);
919
+ visited.add(current);
920
+ const s = sessionMap.get(current);
921
+ current = s?.nextSessionId ?? undefined;
922
+ }
923
+ const result = chain.map((id, idx) => {
924
+ const s = sessionMap.get(id);
925
+ return {
926
+ id,
927
+ status: s?.status ?? 'unknown',
928
+ startedAt: s?.startedAt ?? '',
929
+ endedAt: s?.endedAt ?? null,
930
+ agentIdentifier: s?.agentIdentifier ?? null,
931
+ position: idx + 1,
932
+ };
933
+ });
934
+ return { success: true, data: result };
935
+ }
936
+ catch (err) {
937
+ const message = err.message;
938
+ return engineError('E_INTERNAL', message);
939
+ }
940
+ }
941
+ /**
942
+ * Inject context protocol content.
943
+ * @task T5673
944
+ */
945
+ export function sessionContextInject(protocolType, params, projectRoot) {
946
+ try {
947
+ const result = injectContext(protocolType, params, projectRoot);
948
+ return { success: true, data: result };
949
+ }
950
+ catch (err) {
951
+ const message = err.message;
952
+ const code = message.includes('required')
953
+ ? 'E_INVALID_INPUT'
954
+ : message.includes('not found')
955
+ ? 'E_NOT_FOUND'
956
+ : 'E_INTERNAL';
957
+ return engineError(code, message);
958
+ }
959
+ }
960
+ //# sourceMappingURL=session-engine.js.map