@cleocode/core 2026.9.8 → 2026.9.10

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 (569) hide show
  1. package/dist/audit/reconstruct.d.ts +13 -43
  2. package/dist/audit/reconstruct.d.ts.map +1 -1
  3. package/dist/audit/reconstruct.js +295 -290
  4. package/dist/audit/reconstruct.js.map +1 -1
  5. package/dist/bootstrap.d.ts.map +1 -1
  6. package/dist/bootstrap.js +8 -2
  7. package/dist/bootstrap.js.map +1 -1
  8. package/dist/compliance/protocol-rules.d.ts.map +1 -1
  9. package/dist/compliance/protocol-rules.js +3 -1
  10. package/dist/compliance/protocol-rules.js.map +1 -1
  11. package/dist/dispatch/mutate-projection.d.ts.map +1 -1
  12. package/dist/dispatch/mutate-projection.js +12 -0
  13. package/dist/dispatch/mutate-projection.js.map +1 -1
  14. package/dist/dispatch/mvi-projection.d.ts +29 -6
  15. package/dist/dispatch/mvi-projection.d.ts.map +1 -1
  16. package/dist/dispatch/mvi-projection.js +109 -139
  17. package/dist/dispatch/mvi-projection.js.map +1 -1
  18. package/dist/docs/docs-read-model.d.ts +3 -2
  19. package/dist/docs/docs-read-model.d.ts.map +1 -1
  20. package/dist/docs/docs-read-model.js +4 -3
  21. package/dist/docs/docs-read-model.js.map +1 -1
  22. package/dist/docs/export-document.js +5129 -2297
  23. package/dist/docs/export-document.js.map +3 -3
  24. package/dist/docs/projection.d.ts +67 -0
  25. package/dist/docs/projection.d.ts.map +1 -0
  26. package/dist/docs/projection.js +370 -0
  27. package/dist/docs/projection.js.map +1 -0
  28. package/dist/doctor/acceptance-drift.d.ts +6 -2
  29. package/dist/doctor/acceptance-drift.d.ts.map +1 -1
  30. package/dist/doctor/acceptance-drift.js +43 -5
  31. package/dist/doctor/acceptance-drift.js.map +1 -1
  32. package/dist/doctor/knowledge-summary.d.ts +41 -0
  33. package/dist/doctor/knowledge-summary.d.ts.map +1 -0
  34. package/dist/doctor/knowledge-summary.js +81 -0
  35. package/dist/doctor/knowledge-summary.js.map +1 -0
  36. package/dist/doctor/knowledge.d.ts +192 -0
  37. package/dist/doctor/knowledge.d.ts.map +1 -0
  38. package/dist/doctor/knowledge.js +1864 -0
  39. package/dist/doctor/knowledge.js.map +1 -0
  40. package/dist/git/work-tree.d.ts +169 -0
  41. package/dist/git/work-tree.d.ts.map +1 -0
  42. package/dist/git/work-tree.js +341 -0
  43. package/dist/git/work-tree.js.map +1 -0
  44. package/dist/hooks/handlers/task-hooks.d.ts +8 -5
  45. package/dist/hooks/handlers/task-hooks.d.ts.map +1 -1
  46. package/dist/hooks/handlers/task-hooks.js +15 -60
  47. package/dist/hooks/handlers/task-hooks.js.map +1 -1
  48. package/dist/identity/cleo-identity.d.ts +13 -0
  49. package/dist/identity/cleo-identity.d.ts.map +1 -1
  50. package/dist/identity/cleo-identity.js +20 -6
  51. package/dist/identity/cleo-identity.js.map +1 -1
  52. package/dist/injection.d.ts.map +1 -1
  53. package/dist/injection.js +29 -13
  54. package/dist/injection.js.map +1 -1
  55. package/dist/internal.d.ts +3 -0
  56. package/dist/internal.d.ts.map +1 -1
  57. package/dist/internal.js +4 -0
  58. package/dist/internal.js.map +1 -1
  59. package/dist/lifecycle/verification/satisfies-validator.d.ts.map +1 -1
  60. package/dist/lifecycle/verification/satisfies-validator.js +124 -120
  61. package/dist/lifecycle/verification/satisfies-validator.js.map +1 -1
  62. package/dist/llm/plugin-facade.js +4047 -1726
  63. package/dist/llm/plugin-facade.js.map +3 -3
  64. package/dist/memory/brain-backfill.d.ts +27 -12
  65. package/dist/memory/brain-backfill.d.ts.map +1 -1
  66. package/dist/memory/brain-backfill.js +325 -134
  67. package/dist/memory/brain-backfill.js.map +1 -1
  68. package/dist/memory/brain-doctor.d.ts +21 -0
  69. package/dist/memory/brain-doctor.d.ts.map +1 -1
  70. package/dist/memory/brain-doctor.js +111 -53
  71. package/dist/memory/brain-doctor.js.map +1 -1
  72. package/dist/memory/brain-links.d.ts.map +1 -1
  73. package/dist/memory/brain-links.js +31 -4
  74. package/dist/memory/brain-links.js.map +1 -1
  75. package/dist/memory/brain-reasoning.d.ts.map +1 -1
  76. package/dist/memory/brain-reasoning.js +28 -2
  77. package/dist/memory/brain-reasoning.js.map +1 -1
  78. package/dist/memory/brain-reconciler.d.ts +14 -19
  79. package/dist/memory/brain-reconciler.d.ts.map +1 -1
  80. package/dist/memory/brain-reconciler.js +70 -97
  81. package/dist/memory/brain-reconciler.js.map +1 -1
  82. package/dist/memory/brain-search.d.ts +2 -0
  83. package/dist/memory/brain-search.d.ts.map +1 -1
  84. package/dist/memory/brain-search.js +59 -29
  85. package/dist/memory/brain-search.js.map +1 -1
  86. package/dist/memory/brain-similarity.d.ts.map +1 -1
  87. package/dist/memory/brain-similarity.js +5 -4
  88. package/dist/memory/brain-similarity.js.map +1 -1
  89. package/dist/memory/brain-stub-prune.d.ts +31 -9
  90. package/dist/memory/brain-stub-prune.d.ts.map +1 -1
  91. package/dist/memory/brain-stub-prune.js +65 -18
  92. package/dist/memory/brain-stub-prune.js.map +1 -1
  93. package/dist/memory/brain-writer-handlers.d.ts +10 -1
  94. package/dist/memory/brain-writer-handlers.d.ts.map +1 -1
  95. package/dist/memory/brain-writer-handlers.js +23 -3
  96. package/dist/memory/brain-writer-handlers.js.map +1 -1
  97. package/dist/memory/brain-writer-thread.d.ts +11 -1
  98. package/dist/memory/brain-writer-thread.d.ts.map +1 -1
  99. package/dist/memory/brain-writer-thread.js +87 -20
  100. package/dist/memory/brain-writer-thread.js.map +1 -1
  101. package/dist/memory/brain-writer-worker.js +8 -1
  102. package/dist/memory/brain-writer-worker.js.map +1 -1
  103. package/dist/memory/decision-cross-link.d.ts +39 -0
  104. package/dist/memory/decision-cross-link.d.ts.map +1 -1
  105. package/dist/memory/decision-cross-link.js +316 -0
  106. package/dist/memory/decision-cross-link.js.map +1 -1
  107. package/dist/memory/decisions.d.ts +4 -1
  108. package/dist/memory/decisions.d.ts.map +1 -1
  109. package/dist/memory/decisions.js +7 -24
  110. package/dist/memory/decisions.js.map +1 -1
  111. package/dist/memory/dispatch-trace.d.ts +12 -5
  112. package/dist/memory/dispatch-trace.d.ts.map +1 -1
  113. package/dist/memory/dispatch-trace.js +17 -7
  114. package/dist/memory/dispatch-trace.js.map +1 -1
  115. package/dist/memory/eligibility.d.ts +51 -0
  116. package/dist/memory/eligibility.d.ts.map +1 -0
  117. package/dist/memory/eligibility.js +77 -0
  118. package/dist/memory/eligibility.js.map +1 -0
  119. package/dist/memory/engine-compat.d.ts +2 -0
  120. package/dist/memory/engine-compat.d.ts.map +1 -1
  121. package/dist/memory/engine-compat.js +10 -0
  122. package/dist/memory/engine-compat.js.map +1 -1
  123. package/dist/memory/extraction-gate.d.ts +21 -7
  124. package/dist/memory/extraction-gate.d.ts.map +1 -1
  125. package/dist/memory/extraction-gate.js +178 -216
  126. package/dist/memory/extraction-gate.js.map +1 -1
  127. package/dist/memory/graph-auto-populate.d.ts +38 -5
  128. package/dist/memory/graph-auto-populate.d.ts.map +1 -1
  129. package/dist/memory/graph-auto-populate.js +182 -60
  130. package/dist/memory/graph-auto-populate.js.map +1 -1
  131. package/dist/memory/graph-memory-bridge.d.ts +14 -1
  132. package/dist/memory/graph-memory-bridge.d.ts.map +1 -1
  133. package/dist/memory/graph-memory-bridge.js +66 -28
  134. package/dist/memory/graph-memory-bridge.js.map +1 -1
  135. package/dist/memory/index.d.ts +1 -19
  136. package/dist/memory/index.d.ts.map +1 -1
  137. package/dist/memory/index.js +1 -50
  138. package/dist/memory/index.js.map +1 -1
  139. package/dist/memory/learnings.d.ts.map +1 -1
  140. package/dist/memory/learnings.js +2 -23
  141. package/dist/memory/learnings.js.map +1 -1
  142. package/dist/memory/manifest-filter.d.ts +21 -0
  143. package/dist/memory/manifest-filter.d.ts.map +1 -0
  144. package/dist/memory/manifest-filter.js +51 -0
  145. package/dist/memory/manifest-filter.js.map +1 -0
  146. package/dist/memory/manifest-ingestion.d.ts +28 -30
  147. package/dist/memory/manifest-ingestion.d.ts.map +1 -1
  148. package/dist/memory/manifest-ingestion.js +104 -235
  149. package/dist/memory/manifest-ingestion.js.map +1 -1
  150. package/dist/memory/observer-reflector.d.ts +2 -0
  151. package/dist/memory/observer-reflector.d.ts.map +1 -1
  152. package/dist/memory/observer-reflector.js +6 -49
  153. package/dist/memory/observer-reflector.js.map +1 -1
  154. package/dist/memory/patterns.d.ts +10 -0
  155. package/dist/memory/patterns.d.ts.map +1 -1
  156. package/dist/memory/patterns.js +25 -33
  157. package/dist/memory/patterns.js.map +1 -1
  158. package/dist/memory/pipeline-manifest-sqlite.d.ts +72 -9
  159. package/dist/memory/pipeline-manifest-sqlite.d.ts.map +1 -1
  160. package/dist/memory/pipeline-manifest-sqlite.js +508 -412
  161. package/dist/memory/pipeline-manifest-sqlite.js.map +1 -1
  162. package/dist/memory/retrieval/build-retrieval-bundle.d.ts.map +1 -1
  163. package/dist/memory/retrieval/build-retrieval-bundle.js +16 -15
  164. package/dist/memory/retrieval/build-retrieval-bundle.js.map +1 -1
  165. package/dist/memory/retrieval/fetch.d.ts +7 -0
  166. package/dist/memory/retrieval/fetch.d.ts.map +1 -1
  167. package/dist/memory/retrieval/fetch.js +14 -11
  168. package/dist/memory/retrieval/fetch.js.map +1 -1
  169. package/dist/memory/retrieval/observe.d.ts +7 -1
  170. package/dist/memory/retrieval/observe.d.ts.map +1 -1
  171. package/dist/memory/retrieval/observe.js +58 -4
  172. package/dist/memory/retrieval/observe.js.map +1 -1
  173. package/dist/memory/retrieval/search.d.ts +14 -1
  174. package/dist/memory/retrieval/search.d.ts.map +1 -1
  175. package/dist/memory/retrieval/search.js +133 -69
  176. package/dist/memory/retrieval/search.js.map +1 -1
  177. package/dist/memory/retrieval/telemetry.d.ts +31 -0
  178. package/dist/memory/retrieval/telemetry.d.ts.map +1 -0
  179. package/dist/memory/retrieval/telemetry.js +53 -0
  180. package/dist/memory/retrieval/telemetry.js.map +1 -0
  181. package/dist/nexus/analyze-orchestrator.d.ts +41 -9
  182. package/dist/nexus/analyze-orchestrator.d.ts.map +1 -1
  183. package/dist/nexus/analyze-orchestrator.js +257 -58
  184. package/dist/nexus/analyze-orchestrator.js.map +1 -1
  185. package/dist/nexus/api-contracts.d.ts +2 -6
  186. package/dist/nexus/api-contracts.d.ts.map +1 -1
  187. package/dist/nexus/api-contracts.js +11 -2
  188. package/dist/nexus/api-contracts.js.map +1 -1
  189. package/dist/nexus/context.d.ts.map +1 -1
  190. package/dist/nexus/context.js +14 -37
  191. package/dist/nexus/context.js.map +1 -1
  192. package/dist/nexus/diff.d.ts.map +1 -1
  193. package/dist/nexus/diff.js +2 -1
  194. package/dist/nexus/diff.js.map +1 -1
  195. package/dist/nexus/identity.d.ts +29 -3
  196. package/dist/nexus/identity.d.ts.map +1 -1
  197. package/dist/nexus/identity.js +63 -12
  198. package/dist/nexus/identity.js.map +1 -1
  199. package/dist/nexus/impact.d.ts +21 -19
  200. package/dist/nexus/impact.d.ts.map +1 -1
  201. package/dist/nexus/impact.js +96 -192
  202. package/dist/nexus/impact.js.map +1 -1
  203. package/dist/nexus/knowledge.d.ts +80 -0
  204. package/dist/nexus/knowledge.d.ts.map +1 -0
  205. package/dist/nexus/knowledge.js +786 -0
  206. package/dist/nexus/knowledge.js.map +1 -0
  207. package/dist/nexus/living-brain.d.ts +8 -5
  208. package/dist/nexus/living-brain.d.ts.map +1 -1
  209. package/dist/nexus/living-brain.js +252 -188
  210. package/dist/nexus/living-brain.js.map +1 -1
  211. package/dist/nexus/registry.d.ts +11 -2
  212. package/dist/nexus/registry.d.ts.map +1 -1
  213. package/dist/nexus/registry.js +144 -128
  214. package/dist/nexus/registry.js.map +1 -1
  215. package/dist/nexus/source-roots.d.ts +16 -0
  216. package/dist/nexus/source-roots.d.ts.map +1 -0
  217. package/dist/nexus/source-roots.js +174 -0
  218. package/dist/nexus/source-roots.js.map +1 -0
  219. package/dist/nexus/task-evidence.d.ts +22 -0
  220. package/dist/nexus/task-evidence.d.ts.map +1 -0
  221. package/dist/nexus/task-evidence.js +210 -0
  222. package/dist/nexus/task-evidence.js.map +1 -0
  223. package/dist/nexus/tasks-bridge.d.ts +14 -7
  224. package/dist/nexus/tasks-bridge.d.ts.map +1 -1
  225. package/dist/nexus/tasks-bridge.js +81 -40
  226. package/dist/nexus/tasks-bridge.js.map +1 -1
  227. package/dist/orchestrate/lifecycle-ops.d.ts.map +1 -1
  228. package/dist/orchestrate/lifecycle-ops.js +170 -120
  229. package/dist/orchestrate/lifecycle-ops.js.map +1 -1
  230. package/dist/orchestrate/query-ops.d.ts +6 -7
  231. package/dist/orchestrate/query-ops.d.ts.map +1 -1
  232. package/dist/orchestrate/query-ops.js +509 -532
  233. package/dist/orchestrate/query-ops.js.map +1 -1
  234. package/dist/orchestration/bootstrap.d.ts +15 -1
  235. package/dist/orchestration/bootstrap.d.ts.map +1 -1
  236. package/dist/orchestration/bootstrap.js +21 -10
  237. package/dist/orchestration/bootstrap.js.map +1 -1
  238. package/dist/orchestration/index.d.ts +35 -3
  239. package/dist/orchestration/index.d.ts.map +1 -1
  240. package/dist/orchestration/index.js +64 -35
  241. package/dist/orchestration/index.js.map +1 -1
  242. package/dist/orchestration/lead-rollup.d.ts +24 -1
  243. package/dist/orchestration/lead-rollup.d.ts.map +1 -1
  244. package/dist/orchestration/lead-rollup.js +31 -11
  245. package/dist/orchestration/lead-rollup.js.map +1 -1
  246. package/dist/orchestration/spawn-prompt.d.ts.map +1 -1
  247. package/dist/orchestration/spawn-prompt.js +25 -45
  248. package/dist/orchestration/spawn-prompt.js.map +1 -1
  249. package/dist/orchestration/unblock.d.ts +15 -1
  250. package/dist/orchestration/unblock.d.ts.map +1 -1
  251. package/dist/orchestration/unblock.js +23 -12
  252. package/dist/orchestration/unblock.js.map +1 -1
  253. package/dist/orchestration/validate-spawn.d.ts.map +1 -1
  254. package/dist/orchestration/validate-spawn.js +3 -3
  255. package/dist/orchestration/validate-spawn.js.map +1 -1
  256. package/dist/orchestration/waves.d.ts +29 -13
  257. package/dist/orchestration/waves.d.ts.map +1 -1
  258. package/dist/orchestration/waves.js +43 -55
  259. package/dist/orchestration/waves.js.map +1 -1
  260. package/dist/paths.d.ts +17 -163
  261. package/dist/paths.d.ts.map +1 -1
  262. package/dist/paths.js +145 -496
  263. package/dist/paths.js.map +1 -1
  264. package/dist/project-info.d.ts +2 -11
  265. package/dist/project-info.d.ts.map +1 -1
  266. package/dist/project-info.js +3 -31
  267. package/dist/project-info.js.map +1 -1
  268. package/dist/project-scope.d.ts +239 -0
  269. package/dist/project-scope.d.ts.map +1 -0
  270. package/dist/project-scope.js +473 -0
  271. package/dist/project-scope.js.map +1 -0
  272. package/dist/release/pr-evidence.d.ts +23 -4
  273. package/dist/release/pr-evidence.d.ts.map +1 -1
  274. package/dist/release/pr-evidence.js +65 -9
  275. package/dist/release/pr-evidence.js.map +1 -1
  276. package/dist/render/nexus/graph/index.d.ts.map +1 -1
  277. package/dist/render/nexus/graph/index.js +4 -2
  278. package/dist/render/nexus/graph/index.js.map +1 -1
  279. package/dist/render/orchestration/audit-reconstruct.d.ts +11 -0
  280. package/dist/render/orchestration/audit-reconstruct.d.ts.map +1 -1
  281. package/dist/render/orchestration/audit-reconstruct.js +21 -6
  282. package/dist/render/orchestration/audit-reconstruct.js.map +1 -1
  283. package/dist/render/tasks/show.js +2 -1
  284. package/dist/render/tasks/show.js.map +1 -1
  285. package/dist/resources/spawn-wrapper.d.ts +82 -14
  286. package/dist/resources/spawn-wrapper.d.ts.map +1 -1
  287. package/dist/resources/spawn-wrapper.js +585 -27
  288. package/dist/resources/spawn-wrapper.js.map +1 -1
  289. package/dist/selfimprove/fix-gen.js +4055 -1734
  290. package/dist/selfimprove/fix-gen.js.map +3 -3
  291. package/dist/sequence/index.d.ts.map +1 -1
  292. package/dist/sequence/index.js +76 -68
  293. package/dist/sequence/index.js.map +1 -1
  294. package/dist/session/canon-lint.d.ts +24 -3
  295. package/dist/session/canon-lint.d.ts.map +1 -1
  296. package/dist/session/canon-lint.js +72 -31
  297. package/dist/session/canon-lint.js.map +1 -1
  298. package/dist/session/engine-ops.d.ts +1 -4
  299. package/dist/session/engine-ops.d.ts.map +1 -1
  300. package/dist/session/engine-ops.js +42 -6
  301. package/dist/session/engine-ops.js.map +1 -1
  302. package/dist/sessions/briefing.d.ts +11 -1
  303. package/dist/sessions/briefing.d.ts.map +1 -1
  304. package/dist/sessions/briefing.js +76 -8
  305. package/dist/sessions/briefing.js.map +1 -1
  306. package/dist/sessions/handoff.d.ts +3 -1
  307. package/dist/sessions/handoff.d.ts.map +1 -1
  308. package/dist/sessions/handoff.js +2 -0
  309. package/dist/sessions/handoff.js.map +1 -1
  310. package/dist/shutdown-deadline.d.ts +24 -33
  311. package/dist/shutdown-deadline.d.ts.map +1 -1
  312. package/dist/shutdown-deadline.js +71 -14
  313. package/dist/shutdown-deadline.js.map +1 -1
  314. package/dist/shutdown.d.ts +21 -10
  315. package/dist/shutdown.d.ts.map +1 -1
  316. package/dist/shutdown.js +89 -42
  317. package/dist/shutdown.js.map +1 -1
  318. package/dist/skills/index.d.ts +1 -1
  319. package/dist/skills/index.d.ts.map +1 -1
  320. package/dist/skills/index.js +1 -1
  321. package/dist/skills/index.js.map +1 -1
  322. package/dist/skills/orchestrator/validator.d.ts +87 -20
  323. package/dist/skills/orchestrator/validator.d.ts.map +1 -1
  324. package/dist/skills/orchestrator/validator.js +330 -241
  325. package/dist/skills/orchestrator/validator.js.map +1 -1
  326. package/dist/store/agent-resolver.d.ts.map +1 -1
  327. package/dist/store/agent-resolver.js +16 -9
  328. package/dist/store/agent-resolver.js.map +1 -1
  329. package/dist/store/attachment-store.d.ts +4 -1
  330. package/dist/store/attachment-store.d.ts.map +1 -1
  331. package/dist/store/attachment-store.js +20 -3
  332. package/dist/store/attachment-store.js.map +1 -1
  333. package/dist/store/background-jobs.d.ts +426 -105
  334. package/dist/store/background-jobs.d.ts.map +1 -1
  335. package/dist/store/background-jobs.js +1208 -252
  336. package/dist/store/background-jobs.js.map +1 -1
  337. package/dist/store/background-ops.d.ts +145 -8
  338. package/dist/store/background-ops.d.ts.map +1 -1
  339. package/dist/store/background-ops.js +459 -15
  340. package/dist/store/background-ops.js.map +1 -1
  341. package/dist/store/backup-inspect.d.ts +48 -4
  342. package/dist/store/backup-inspect.d.ts.map +1 -1
  343. package/dist/store/backup-inspect.js +384 -4
  344. package/dist/store/backup-inspect.js.map +1 -1
  345. package/dist/store/converters.d.ts.map +1 -1
  346. package/dist/store/converters.js +19 -2
  347. package/dist/store/converters.js.map +1 -1
  348. package/dist/store/data-accessor.d.ts +9 -1
  349. package/dist/store/data-accessor.d.ts.map +1 -1
  350. package/dist/store/data-accessor.js +22 -5
  351. package/dist/store/data-accessor.js.map +1 -1
  352. package/dist/store/data-safety-central.d.ts.map +1 -1
  353. package/dist/store/data-safety-central.js +272 -232
  354. package/dist/store/data-safety-central.js.map +1 -1
  355. package/dist/store/db-helpers.d.ts +19 -3
  356. package/dist/store/db-helpers.d.ts.map +1 -1
  357. package/dist/store/db-helpers.js +42 -58
  358. package/dist/store/db-helpers.js.map +1 -1
  359. package/dist/store/dual-scope-db.d.ts +63 -4
  360. package/dist/store/dual-scope-db.d.ts.map +1 -1
  361. package/dist/store/dual-scope-db.js +166 -19
  362. package/dist/store/dual-scope-db.js.map +1 -1
  363. package/dist/store/exodus/archive.d.ts +21 -7
  364. package/dist/store/exodus/archive.d.ts.map +1 -1
  365. package/dist/store/exodus/archive.js +60 -18
  366. package/dist/store/exodus/archive.js.map +1 -1
  367. package/dist/store/exodus/migrate.d.ts.map +1 -1
  368. package/dist/store/exodus/migrate.js +27 -23
  369. package/dist/store/exodus/migrate.js.map +1 -1
  370. package/dist/store/exodus/on-open.d.ts +16 -27
  371. package/dist/store/exodus/on-open.d.ts.map +1 -1
  372. package/dist/store/exodus/on-open.js +121 -169
  373. package/dist/store/exodus/on-open.js.map +1 -1
  374. package/dist/store/exodus/recovery.d.ts +90 -0
  375. package/dist/store/exodus/recovery.d.ts.map +1 -0
  376. package/dist/store/exodus/recovery.js +434 -0
  377. package/dist/store/exodus/recovery.js.map +1 -0
  378. package/dist/store/exodus/types.d.ts +15 -0
  379. package/dist/store/exodus/types.d.ts.map +1 -1
  380. package/dist/store/memory-accessor.d.ts +52 -3
  381. package/dist/store/memory-accessor.d.ts.map +1 -1
  382. package/dist/store/memory-accessor.js +122 -7
  383. package/dist/store/memory-accessor.js.map +1 -1
  384. package/dist/store/nexus-sqlite.d.ts +24 -6
  385. package/dist/store/nexus-sqlite.d.ts.map +1 -1
  386. package/dist/store/nexus-sqlite.js +39 -20
  387. package/dist/store/nexus-sqlite.js.map +1 -1
  388. package/dist/store/ports/domain-binding.d.ts.map +1 -1
  389. package/dist/store/ports/domain-binding.js +27 -5
  390. package/dist/store/ports/domain-binding.js.map +1 -1
  391. package/dist/store/schema/background-jobs.d.ts +181 -2
  392. package/dist/store/schema/background-jobs.d.ts.map +1 -1
  393. package/dist/store/schema/background-jobs.js +27 -3
  394. package/dist/store/schema/background-jobs.js.map +1 -1
  395. package/dist/store/schema/cleo-global/skills.d.ts +2 -2
  396. package/dist/store/schema/cleo-project/lifecycle.d.ts +2 -2
  397. package/dist/store/schema/cleo-project/runtime.d.ts +1 -1
  398. package/dist/store/schema/cleo-project/tasks-core.d.ts +1 -1
  399. package/dist/store/schema/lifecycle.d.ts +2 -2
  400. package/dist/store/schema/skills-schema.d.ts +2 -2
  401. package/dist/store/schema/tasks.d.ts +1 -1
  402. package/dist/store/session-store.d.ts +3 -1
  403. package/dist/store/session-store.d.ts.map +1 -1
  404. package/dist/store/session-store.js +252 -207
  405. package/dist/store/session-store.js.map +1 -1
  406. package/dist/store/sqlite-data-accessor.d.ts +39 -4
  407. package/dist/store/sqlite-data-accessor.d.ts.map +1 -1
  408. package/dist/store/sqlite-data-accessor.js +689 -527
  409. package/dist/store/sqlite-data-accessor.js.map +1 -1
  410. package/dist/store/tasks-sqlite.d.ts +3 -1
  411. package/dist/store/tasks-sqlite.d.ts.map +1 -1
  412. package/dist/store/tasks-sqlite.js +309 -279
  413. package/dist/store/tasks-sqlite.js.map +1 -1
  414. package/dist/store/validation-schemas.d.ts +8 -8
  415. package/dist/store/writer-lease.d.ts +80 -8
  416. package/dist/store/writer-lease.d.ts.map +1 -1
  417. package/dist/store/writer-lease.js +503 -134
  418. package/dist/store/writer-lease.js.map +1 -1
  419. package/dist/system/audit.d.ts +2 -1
  420. package/dist/system/audit.d.ts.map +1 -1
  421. package/dist/system/audit.js +118 -71
  422. package/dist/system/audit.js.map +1 -1
  423. package/dist/system/backup.d.ts.map +1 -1
  424. package/dist/system/backup.js +5 -5
  425. package/dist/system/backup.js.map +1 -1
  426. package/dist/system/inject-generate.js +1 -1
  427. package/dist/task-work/index.d.ts +3 -0
  428. package/dist/task-work/index.d.ts.map +1 -1
  429. package/dist/task-work/index.js +34 -37
  430. package/dist/task-work/index.js.map +1 -1
  431. package/dist/tasks/ac-coverage-gate.d.ts.map +1 -1
  432. package/dist/tasks/ac-coverage-gate.js +4 -0
  433. package/dist/tasks/ac-coverage-gate.js.map +1 -1
  434. package/dist/tasks/ac-immutability.d.ts +7 -4
  435. package/dist/tasks/ac-immutability.d.ts.map +1 -1
  436. package/dist/tasks/ac-immutability.js +19 -17
  437. package/dist/tasks/ac-immutability.js.map +1 -1
  438. package/dist/tasks/ac-table.d.ts +5 -5
  439. package/dist/tasks/ac-table.d.ts.map +1 -1
  440. package/dist/tasks/ac-table.js +26 -12
  441. package/dist/tasks/ac-table.js.map +1 -1
  442. package/dist/tasks/acceptance-input.d.ts +52 -0
  443. package/dist/tasks/acceptance-input.d.ts.map +1 -0
  444. package/dist/tasks/acceptance-input.js +259 -0
  445. package/dist/tasks/acceptance-input.js.map +1 -0
  446. package/dist/tasks/add.d.ts +67 -29
  447. package/dist/tasks/add.d.ts.map +1 -1
  448. package/dist/tasks/add.js +255 -97
  449. package/dist/tasks/add.js.map +1 -1
  450. package/dist/tasks/complete.d.ts +16 -1
  451. package/dist/tasks/complete.d.ts.map +1 -1
  452. package/dist/tasks/complete.js +152 -55
  453. package/dist/tasks/complete.js.map +1 -1
  454. package/dist/tasks/decompose.d.ts +103 -0
  455. package/dist/tasks/decompose.d.ts.map +1 -0
  456. package/dist/tasks/decompose.js +224 -0
  457. package/dist/tasks/decompose.js.map +1 -0
  458. package/dist/tasks/delete.d.ts +5 -8
  459. package/dist/tasks/delete.d.ts.map +1 -1
  460. package/dist/tasks/delete.js +4 -3
  461. package/dist/tasks/delete.js.map +1 -1
  462. package/dist/tasks/dependency-check.d.ts +59 -0
  463. package/dist/tasks/dependency-check.d.ts.map +1 -1
  464. package/dist/tasks/dependency-check.js +73 -0
  465. package/dist/tasks/dependency-check.js.map +1 -1
  466. package/dist/tasks/deps-ready.d.ts +13 -1
  467. package/dist/tasks/deps-ready.d.ts.map +1 -1
  468. package/dist/tasks/deps-ready.js +16 -5
  469. package/dist/tasks/deps-ready.js.map +1 -1
  470. package/dist/tasks/engine-converters.d.ts +7 -0
  471. package/dist/tasks/engine-converters.d.ts.map +1 -1
  472. package/dist/tasks/engine-converters.js +8 -1
  473. package/dist/tasks/engine-converters.js.map +1 -1
  474. package/dist/tasks/evidence.d.ts +88 -27
  475. package/dist/tasks/evidence.d.ts.map +1 -1
  476. package/dist/tasks/evidence.js +344 -43
  477. package/dist/tasks/evidence.js.map +1 -1
  478. package/dist/tasks/find.d.ts +16 -12
  479. package/dist/tasks/find.d.ts.map +1 -1
  480. package/dist/tasks/find.js +107 -93
  481. package/dist/tasks/find.js.map +1 -1
  482. package/dist/tasks/gate-preview.d.ts +73 -0
  483. package/dist/tasks/gate-preview.d.ts.map +1 -0
  484. package/dist/tasks/gate-preview.js +119 -0
  485. package/dist/tasks/gate-preview.js.map +1 -0
  486. package/dist/tasks/gate-runner.d.ts +88 -14
  487. package/dist/tasks/gate-runner.d.ts.map +1 -1
  488. package/dist/tasks/gate-runner.js +719 -250
  489. package/dist/tasks/gate-runner.js.map +1 -1
  490. package/dist/tasks/hierarchy-policy.d.ts +8 -0
  491. package/dist/tasks/hierarchy-policy.d.ts.map +1 -1
  492. package/dist/tasks/hierarchy-policy.js +9 -2
  493. package/dist/tasks/hierarchy-policy.js.map +1 -1
  494. package/dist/tasks/hierarchy.d.ts +67 -1
  495. package/dist/tasks/hierarchy.d.ts.map +1 -1
  496. package/dist/tasks/hierarchy.js +81 -1
  497. package/dist/tasks/hierarchy.js.map +1 -1
  498. package/dist/tasks/index.d.ts +3 -0
  499. package/dist/tasks/index.d.ts.map +1 -1
  500. package/dist/tasks/index.js +3 -0
  501. package/dist/tasks/index.js.map +1 -1
  502. package/dist/tasks/infer-add-params.d.ts +1 -20
  503. package/dist/tasks/infer-add-params.d.ts.map +1 -1
  504. package/dist/tasks/infer-add-params.js +2 -203
  505. package/dist/tasks/infer-add-params.js.map +1 -1
  506. package/dist/tasks/list.d.ts +7 -2
  507. package/dist/tasks/list.d.ts.map +1 -1
  508. package/dist/tasks/list.js +24 -36
  509. package/dist/tasks/list.js.map +1 -1
  510. package/dist/tasks/ops.d.ts +6 -61
  511. package/dist/tasks/ops.d.ts.map +1 -1
  512. package/dist/tasks/ops.js +5 -53
  513. package/dist/tasks/ops.js.map +1 -1
  514. package/dist/tasks/plan.d.ts +15 -1
  515. package/dist/tasks/plan.d.ts.map +1 -1
  516. package/dist/tasks/plan.js +23 -25
  517. package/dist/tasks/plan.js.map +1 -1
  518. package/dist/tasks/population.d.ts +46 -0
  519. package/dist/tasks/population.d.ts.map +1 -0
  520. package/dist/tasks/population.js +88 -0
  521. package/dist/tasks/population.js.map +1 -0
  522. package/dist/tasks/reconcile-scope.d.ts +157 -0
  523. package/dist/tasks/reconcile-scope.d.ts.map +1 -0
  524. package/dist/tasks/reconcile-scope.js +242 -0
  525. package/dist/tasks/reconcile-scope.js.map +1 -0
  526. package/dist/tasks/req.d.ts +51 -12
  527. package/dist/tasks/req.d.ts.map +1 -1
  528. package/dist/tasks/req.js +125 -69
  529. package/dist/tasks/req.js.map +1 -1
  530. package/dist/tasks/session-scope.d.ts +6 -31
  531. package/dist/tasks/session-scope.d.ts.map +1 -1
  532. package/dist/tasks/session-scope.js +3 -17
  533. package/dist/tasks/session-scope.js.map +1 -1
  534. package/dist/tasks/severity-attestation.d.ts +39 -10
  535. package/dist/tasks/severity-attestation.d.ts.map +1 -1
  536. package/dist/tasks/severity-attestation.js +75 -36
  537. package/dist/tasks/severity-attestation.js.map +1 -1
  538. package/dist/tasks/task-next.d.ts +5 -0
  539. package/dist/tasks/task-next.d.ts.map +1 -1
  540. package/dist/tasks/task-next.js +10 -9
  541. package/dist/tasks/task-next.js.map +1 -1
  542. package/dist/tasks/task-reparent.d.ts.map +1 -1
  543. package/dist/tasks/task-reparent.js +3 -13
  544. package/dist/tasks/task-reparent.js.map +1 -1
  545. package/dist/tasks/update.d.ts +20 -43
  546. package/dist/tasks/update.d.ts.map +1 -1
  547. package/dist/tasks/update.js +64 -49
  548. package/dist/tasks/update.js.map +1 -1
  549. package/dist/validation/engine-ops.d.ts +17 -1
  550. package/dist/validation/engine-ops.d.ts.map +1 -1
  551. package/dist/validation/engine-ops.js +149 -11
  552. package/dist/validation/engine-ops.js.map +1 -1
  553. package/dist/workgraph/reparent-preflight.d.ts +1 -1
  554. package/dist/workgraph/reparent-preflight.d.ts.map +1 -1
  555. package/dist/workgraph/reparent-preflight.js +6 -1
  556. package/dist/workgraph/reparent-preflight.js.map +1 -1
  557. package/dist/workgraph/scaffold-apply.d.ts.map +1 -1
  558. package/dist/workgraph/scaffold-apply.js +81 -76
  559. package/dist/workgraph/scaffold-apply.js.map +1 -1
  560. package/dist/workgraph/structure-validation.d.ts +1 -1
  561. package/dist/workgraph/structure-validation.d.ts.map +1 -1
  562. package/dist/workgraph/structure-validation.js +6 -1
  563. package/dist/workgraph/structure-validation.js.map +1 -1
  564. package/migrations/drizzle-tasks/20260919180000_t12263-job-ownership-fences/migration.sql +34 -0
  565. package/migrations/drizzle-tasks/20260919184500_t12265-durable-pending-proposals/migration.sql +4 -0
  566. package/package.json +18 -13
  567. package/schemas/config.schema.json +2 -2
  568. package/schemas/project-context.schema.json +12 -0
  569. package/templates/CLEO-INJECTION.md +114 -101
@@ -1,296 +1,385 @@
1
1
  /**
2
- * Orchestrator protocol compliance validation.
3
- * Ports lib/skills/orchestrator-validator.sh.
4
- *
5
- * Validates subagent output compliance, orchestrator behavior,
6
- * manifest integrity, and pre-spawn compliance checks.
7
- *
8
- * @epic T4454
9
- * @task T4519
2
+ * Orchestrator protocol validation against canonical current evidence or an
3
+ * explicitly selected historical JSONL file. Historical validation is never
4
+ * presented as verification of the current authoritative store.
5
+ * @task T12282
10
6
  */
11
- import { existsSync, readFileSync } from 'node:fs';
12
- import { join } from 'node:path';
7
+ import { readFileSync } from 'node:fs';
8
+ import { join, resolve } from 'node:path';
13
9
  import { MANIFEST_STATUSES } from '@cleocode/contracts';
14
- import { getAgentOutputsAbsolute, getManifestPath as getManifestPathFromPaths, } from '../../paths.js';
10
+ import { z } from 'zod';
11
+ import { EngineResultError } from '../../engine-result.js';
12
+ import { pipelineManifestShow, readManifestEntries, } from '../../memory/pipeline-manifest-sqlite.js';
13
+ import { getAgentOutputsAbsolute, getProjectRoot, resolveOrCwd } from '../../paths.js';
14
+ import { captureProjectScope, worktreeScope } from '../../project-scope.js';
15
15
  import { getTaskAccessor } from '../../store/data-accessor.js';
16
- // ============================================================================
17
- // Constants
18
- // ============================================================================
19
16
  const KEY_FINDINGS_MIN = 3;
20
17
  const KEY_FINDINGS_MAX = 7;
21
- const MANIFEST_REQUIRED_FIELDS = [
22
- 'id',
23
- 'file',
24
- 'title',
25
- 'date',
26
- 'status',
27
- 'topics',
28
- 'key_findings',
29
- 'actionable',
30
- ];
31
18
  const VALID_STATUSES_SET = new Set(MANIFEST_STATUSES);
32
- // ============================================================================
33
- // Manifest Helpers
34
- // ============================================================================
35
- /** Alias for centralized getManifestPath to avoid name conflicts with local usages. */
36
- function getManifestPath(cwd) {
37
- return getManifestPathFromPaths(cwd);
19
+ const CHECKED_RULES = [
20
+ 'MANIFEST_ENTRY_EXISTS',
21
+ 'REQUIRED_FIELDS_PRESENT',
22
+ 'STATUS_VALID_ENUM',
23
+ 'KEY_FINDINGS_COUNT_3_7',
24
+ 'DATE_ISO_8601',
25
+ 'TOPICS_ARRAY_NON_EMPTY',
26
+ 'NEEDS_FOLLOWUP_ARRAY',
27
+ 'ACTIONABLE_BOOLEAN',
28
+ 'OUTPUT_FILE_EXISTS',
29
+ ];
30
+ const historicalEntrySchema = z.looseObject({
31
+ id: z.string().min(1),
32
+ file: z.string().min(1),
33
+ title: z.string().min(1),
34
+ date: z.string().min(1),
35
+ status: z.enum(MANIFEST_STATUSES),
36
+ agent_type: z.string().optional(),
37
+ topics: z.array(z.string()),
38
+ key_findings: z.array(z.string()),
39
+ actionable: z.boolean(),
40
+ needs_followup: z.array(z.string()),
41
+ linked_tasks: z.array(z.string()).optional(),
42
+ });
43
+ function currentSourceIssue(method) {
44
+ return `CURRENT_MANIFEST_REQUIRES_ASYNC: Use ${method} for the authoritative store, or explicitly select a historicalManifestPath.`;
38
45
  }
39
- /**
40
- * Read all manifest entries from the legacy agent-outputs flat-file.
41
- */
42
- function readManifestEntries(cwd) {
43
- const manifestPath = getManifestPath(cwd);
44
- if (!existsSync(manifestPath))
45
- return [];
46
- const content = readFileSync(manifestPath, 'utf-8');
46
+ function readHistoricalEntries(cwd, manifestPath) {
47
47
  const entries = [];
48
- for (const line of content.split('\n')) {
49
- const trimmed = line.trim();
50
- if (!trimmed)
48
+ const issues = [];
49
+ let content;
50
+ try {
51
+ content = readFileSync(resolve(resolveOrCwd(cwd), manifestPath), 'utf8');
52
+ }
53
+ catch (error) {
54
+ issues.push(`HISTORICAL_MANIFEST_READ_FAILED: ${error instanceof Error ? error.message : String(error)}`);
55
+ return { exists: false, entries, issues, totalLines: 0, invalidEntries: 0 };
56
+ }
57
+ let totalLines = 0;
58
+ let invalidEntries = 0;
59
+ const seen = new Set();
60
+ for (const [index, line] of content.split('\n').entries()) {
61
+ if (!line.trim())
51
62
  continue;
63
+ totalLines++;
52
64
  try {
53
- entries.push(JSON.parse(trimmed));
65
+ const parsed = historicalEntrySchema.safeParse(JSON.parse(line));
66
+ if (!parsed.success) {
67
+ issues.push(`LINE_${index + 1}_INVALID_ENTRY: ${parsed.error.message}`);
68
+ invalidEntries++;
69
+ continue;
70
+ }
71
+ if (seen.has(parsed.data.id)) {
72
+ issues.push(`LINE_${index + 1}_DUPLICATE_ID: ${parsed.data.id}`);
73
+ invalidEntries++;
74
+ continue;
75
+ }
76
+ seen.add(parsed.data.id);
77
+ entries.push(parsed.data);
54
78
  }
55
- catch {
56
- // Skip invalid lines
79
+ catch (error) {
80
+ issues.push(`LINE_${index + 1}_INVALID_JSON: ${error instanceof Error ? error.message : String(error)}`);
81
+ invalidEntries++;
57
82
  }
58
83
  }
59
- return entries;
84
+ if (totalLines === 0)
85
+ issues.push('MANIFEST_EMPTY: Selected historical file has no evidence');
86
+ return { exists: true, entries, issues, totalLines, invalidEntries };
60
87
  }
61
- // ============================================================================
62
- // Subagent Output Validation
63
- // ============================================================================
64
- /**
65
- * Validate a subagent's manifest entry for protocol compliance.
66
- * @task T4519
67
- */
68
- export function validateSubagentOutput(researchId, cwd) {
88
+ function entryIssues(entry, researchId) {
89
+ if (!entry)
90
+ return [`MANIFEST_ENTRY_MISSING: No manifest entry found for id=${researchId}`];
69
91
  const issues = [];
70
- const checkedRules = [
71
- 'MANIFEST_ENTRY_EXISTS',
72
- 'REQUIRED_FIELDS_PRESENT',
73
- 'STATUS_VALID_ENUM',
74
- 'KEY_FINDINGS_COUNT_3_7',
75
- 'DATE_ISO_8601',
76
- 'TOPICS_ARRAY_NON_EMPTY',
77
- 'NEEDS_FOLLOWUP_ARRAY',
78
- 'ACTIONABLE_BOOLEAN',
79
- 'OUTPUT_FILE_EXISTS',
80
- ];
81
- const entries = readManifestEntries(cwd);
82
- const entry = entries.find((e) => e.id === researchId);
83
- if (!entry) {
84
- issues.push(`MANIFEST_ENTRY_MISSING: No manifest entry found for id=${researchId}`);
85
- return { passed: false, issues, checkedRules };
86
- }
87
- // Check required fields
88
- for (const field of MANIFEST_REQUIRED_FIELDS) {
89
- if (!(field in entry)) {
92
+ for (const field of ['id', 'file', 'title', 'date']) {
93
+ if (!entry[field])
90
94
  issues.push(`MISSING_FIELD: ${field}`);
91
- }
92
- }
93
- // Validate status
94
- if (entry.status && !VALID_STATUSES_SET.has(entry.status)) {
95
- issues.push(`INVALID_STATUS: ${entry.status} (must be completed|partial|blocked|archived)`);
96
- }
97
- // Validate key_findings count
98
- if (!Array.isArray(entry.key_findings)) {
99
- issues.push('KEY_FINDINGS_NOT_ARRAY');
100
95
  }
101
- else if (entry.key_findings.length < KEY_FINDINGS_MIN) {
102
- issues.push(`KEY_FINDINGS_TOO_FEW: count=${entry.key_findings.length} (must be ${KEY_FINDINGS_MIN}-${KEY_FINDINGS_MAX})`);
96
+ if (!VALID_STATUSES_SET.has(entry.status))
97
+ issues.push(`INVALID_STATUS: ${entry.status}`);
98
+ if (entry.key_findings.length < KEY_FINDINGS_MIN ||
99
+ entry.key_findings.length > KEY_FINDINGS_MAX) {
100
+ issues.push(`KEY_FINDINGS_COUNT: count=${entry.key_findings.length} (must be ${KEY_FINDINGS_MIN}-${KEY_FINDINGS_MAX})`);
103
101
  }
104
- else if (entry.key_findings.length > KEY_FINDINGS_MAX) {
105
- issues.push(`KEY_FINDINGS_TOO_MANY: count=${entry.key_findings.length} (must be ${KEY_FINDINGS_MIN}-${KEY_FINDINGS_MAX})`);
106
- }
107
- // Validate date format
108
- if (entry.date && !/^\d{4}-\d{2}-\d{2}$/.test(entry.date)) {
109
- issues.push(`INVALID_DATE: ${entry.date} (must be YYYY-MM-DD)`);
110
- }
111
- // Validate topics
112
- if (!Array.isArray(entry.topics) || entry.topics.length === 0) {
102
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(entry.date))
103
+ issues.push(`INVALID_DATE: ${entry.date}`);
104
+ if (entry.topics.length === 0)
113
105
  issues.push('TOPICS_EMPTY: topics must be a non-empty array');
106
+ return issues;
107
+ }
108
+ function historicalOutputIssue(entry, cwd) {
109
+ if (/^[a-z][a-z0-9+.-]*:/i.test(entry.file)) {
110
+ return `HISTORICAL_OUTPUT_REQUIRES_ASYNC: Cannot resolve ${entry.file} as an explicit historical file`;
114
111
  }
115
- // Validate actionable
116
- if (typeof entry.actionable !== 'boolean') {
117
- issues.push('ACTIONABLE_NOT_BOOLEAN');
112
+ try {
113
+ const scope = captureProjectScope(cwd ?? getProjectRoot(), worktreeScope.getStore());
114
+ const outputRoot = worktreeScope.run(scope, () => getAgentOutputsAbsolute(scope.worktreeRoot));
115
+ readFileSync(join(outputRoot, entry.file));
116
+ return null;
118
117
  }
119
- // Check output file exists
120
- if (entry.file) {
121
- const absOutputDir = getAgentOutputsAbsolute(cwd);
122
- const filePath = join(absOutputDir, entry.file);
123
- if (!existsSync(filePath)) {
124
- issues.push(`FILE_NOT_FOUND: Expected file at ${filePath}`);
125
- }
118
+ catch (error) {
119
+ return `OUTPUT_FILE_READ_FAILED: ${entry.file}: ${error instanceof Error ? error.message : String(error)}`;
120
+ }
121
+ }
122
+ function selectedEntry(entries, taskId, researchId) {
123
+ return researchId
124
+ ? entries.find((entry) => entry.id === researchId)
125
+ : entries.find((entry) => entry.linked_tasks?.includes(taskId));
126
+ }
127
+ function complianceResult(taskId, entry, issues) {
128
+ const violations = [...issues];
129
+ const researchLinkedToTask = entry?.linked_tasks?.includes(taskId) ?? false;
130
+ if (entry && !researchLinkedToTask)
131
+ violations.push(`RESEARCH_NOT_LINKED: ${entry.id} is not linked to ${taskId}`);
132
+ const returnStatusValid = entry ? VALID_STATUSES_SET.has(entry.status) : null;
133
+ if (returnStatusValid === false)
134
+ violations.push(`INVALID_MANIFEST_STATUS: ${entry?.status}`);
135
+ return {
136
+ previousTaskId: taskId,
137
+ researchId: entry?.id ?? null,
138
+ checks: { manifestEntryExists: !!entry, researchLinkedToTask, returnStatusValid },
139
+ canSpawnNext: violations.length === 0,
140
+ violations,
141
+ warnings: [],
142
+ };
143
+ }
144
+ function currentRoot(cwd) {
145
+ return captureProjectScope(cwd ?? getProjectRoot(), worktreeScope.getStore()).worktreeRoot;
146
+ }
147
+ async function currentOutputIssue(entry, root) {
148
+ const result = await pipelineManifestShow(entry.id, root);
149
+ if (!result.success)
150
+ throw new EngineResultError(result.error);
151
+ const data = result.data;
152
+ if (!data ||
153
+ typeof data !== 'object' ||
154
+ !('fileExists' in data) ||
155
+ typeof data.fileExists !== 'boolean') {
156
+ throw new EngineResultError({
157
+ code: 'E_MANIFEST_RESULT_INVALID',
158
+ message: 'Canonical manifest show did not disclose output availability',
159
+ details: { entryId: entry.id },
160
+ });
126
161
  }
127
- return { passed: issues.length === 0, issues, checkedRules };
162
+ return data.fileExists ? null : `OUTPUT_FILE_MISSING: ${entry.file}`;
163
+ }
164
+ /**
165
+ * Validate one entry in an explicitly selected historical JSONL file synchronously.
166
+ * @remarks Bare calls cannot validate the authoritative current store and return
167
+ * an unavailable-current-source issue. Use validateCurrentSubagentOutput for that store.
168
+ * @param researchId - Exact historical entry identity.
169
+ * @param cwd - Root used for relative historical paths and output files.
170
+ * @param historicalManifestPath - Explicit historical file; never inferred from cwd.
171
+ * @returns Synchronous compliance result with all historical read/parse issues.
172
+ * @example
173
+ * ```ts
174
+ * const result = validateSubagentOutput('entry', '/project', 'history.jsonl');
175
+ * ```
176
+ */
177
+ export function validateSubagentOutput(researchId, cwd, historicalManifestPath) {
178
+ if (!historicalManifestPath)
179
+ return {
180
+ passed: false,
181
+ issues: [currentSourceIssue('validateCurrentSubagentOutput')],
182
+ checkedRules: [...CHECKED_RULES],
183
+ };
184
+ const history = readHistoricalEntries(cwd, historicalManifestPath);
185
+ const entry = history.entries.find((candidate) => candidate.id === researchId);
186
+ const issues = [...history.issues, ...entryIssues(entry, researchId)];
187
+ const outputIssue = entry && historicalOutputIssue(entry, cwd);
188
+ if (outputIssue)
189
+ issues.push(outputIssue);
190
+ return { passed: issues.length === 0, issues, checkedRules: [...CHECKED_RULES] };
128
191
  }
129
- // ============================================================================
130
- // Manifest Integrity
131
- // ============================================================================
132
192
  /**
133
- * Validate the entire manifest file integrity.
134
- * @task T4519
193
+ * Validate an explicitly selected historical manifest synchronously.
194
+ * @remarks This preserves the synchronous return shape without equating a retired
195
+ * or missing JSONL file with a valid current database. Every malformed row fails.
196
+ * @param cwd - Root for relative historical and output paths.
197
+ * @param historicalManifestPath - Explicit historical JSONL file.
198
+ * @returns Historical validation result; absent explicit source fails.
199
+ * @example
200
+ * ```ts
201
+ * const result = validateManifestIntegrity('/project', 'history.jsonl');
202
+ * ```
135
203
  */
136
- export function validateManifestIntegrity(cwd) {
137
- const manifestPath = getManifestPath(cwd);
138
- if (!existsSync(manifestPath)) {
139
- return { exists: false, passed: true, issues: [] };
204
+ export function validateManifestIntegrity(cwd, historicalManifestPath) {
205
+ if (!historicalManifestPath)
206
+ return {
207
+ exists: false,
208
+ passed: false,
209
+ issues: [currentSourceIssue('validateCurrentManifestIntegrity')],
210
+ };
211
+ const history = readHistoricalEntries(cwd, historicalManifestPath);
212
+ const issues = [...history.issues];
213
+ for (const entry of history.entries) {
214
+ issues.push(...entryIssues(entry, entry.id));
215
+ const outputIssue = historicalOutputIssue(entry, cwd);
216
+ if (outputIssue)
217
+ issues.push(outputIssue);
140
218
  }
141
- const content = readFileSync(manifestPath, 'utf-8');
142
- const lines = content.split('\n').filter((l) => l.trim());
143
- const issues = [];
144
- let validEntries = 0;
219
+ return {
220
+ exists: history.exists,
221
+ passed: issues.length === 0,
222
+ issues,
223
+ stats: {
224
+ totalLines: history.totalLines,
225
+ validEntries: history.entries.length,
226
+ invalidEntries: history.invalidEntries,
227
+ },
228
+ };
229
+ }
230
+ /**
231
+ * Check exact task linkage and output validity in explicitly selected history.
232
+ * @remarks Entry names and follow-up requests do not establish task evidence.
233
+ * Bare synchronous calls fail with current-store async guidance.
234
+ * @param previousTaskId - Exact task whose evidence is required.
235
+ * @param researchId - Optional exact historical entry identity.
236
+ * @param cwd - Root for relative historical and output paths.
237
+ * @param historicalManifestPath - Explicit historical JSONL file.
238
+ * @returns Synchronous compliance result, never successful after read/parse failure.
239
+ * @example
240
+ * ```ts
241
+ * const result = verifyCompliance('T1', undefined, '/project', 'history.jsonl');
242
+ * ```
243
+ */
244
+ export function verifyCompliance(previousTaskId, researchId, cwd, historicalManifestPath) {
245
+ if (!historicalManifestPath)
246
+ return complianceResult(previousTaskId, undefined, [
247
+ currentSourceIssue('verifyCurrentCompliance'),
248
+ ]);
249
+ const history = readHistoricalEntries(cwd, historicalManifestPath);
250
+ const entry = selectedEntry(history.entries, previousTaskId, researchId);
251
+ const issues = [...history.issues, ...entryIssues(entry, researchId ?? previousTaskId)];
252
+ const outputIssue = entry && historicalOutputIssue(entry, cwd);
253
+ if (outputIssue)
254
+ issues.push(outputIssue);
255
+ return complianceResult(previousTaskId, entry, issues);
256
+ }
257
+ /**
258
+ * Validate an exact entry from canonical modern and retained historical rows.
259
+ * @remarks Captures project ownership before awaiting and verifies real output
260
+ * availability through the same canonical resolver as manifest show.
261
+ * @param researchId - Exact canonical entry identity.
262
+ * @param cwd - Optional explicit project root.
263
+ * @returns Field and output validation result.
264
+ * @throws If canonical storage, history, metadata or output resolution fails.
265
+ * @example
266
+ * ```ts
267
+ * const result = await validateCurrentSubagentOutput('entry', '/project');
268
+ * ```
269
+ */
270
+ export async function validateCurrentSubagentOutput(researchId, cwd) {
271
+ const root = currentRoot(cwd);
272
+ const entries = await readManifestEntries(root);
273
+ const entry = entries.find((candidate) => candidate.id === researchId);
274
+ const issues = entryIssues(entry, researchId);
275
+ const outputIssue = entry && (await currentOutputIssue(entry, root));
276
+ if (outputIssue)
277
+ issues.push(outputIssue);
278
+ return { passed: issues.length === 0, issues, checkedRules: [...CHECKED_RULES] };
279
+ }
280
+ /**
281
+ * Validate eligible canonical manifest rows and their actual output availability.
282
+ * @remarks The existing totalLines counter denotes records for the database
283
+ * source. Empty evidence fails; archived rows remain outside current eligibility.
284
+ * @param cwd - Optional explicit project root.
285
+ * @returns Integrity result for current eligible evidence.
286
+ * @throws If canonical reads, history comparison or output resolution fail.
287
+ * @example
288
+ * ```ts
289
+ * const result = await validateCurrentManifestIntegrity('/project');
290
+ * ```
291
+ */
292
+ export async function validateCurrentManifestIntegrity(cwd) {
293
+ const root = currentRoot(cwd);
294
+ const entries = await readManifestEntries(root);
295
+ const issues = entries.length
296
+ ? []
297
+ : ['MANIFEST_EMPTY: Current store has no eligible evidence'];
145
298
  let invalidEntries = 0;
146
- const seenIds = new Set();
147
- for (let i = 0; i < lines.length; i++) {
148
- const lineNum = i + 1;
149
- const line = lines[i].trim();
150
- if (!line)
151
- continue;
152
- // Check valid JSON
153
- let entry;
154
- try {
155
- entry = JSON.parse(line);
156
- }
157
- catch {
158
- issues.push(`LINE_${lineNum}_INVALID_JSON: Parse error`);
159
- invalidEntries++;
160
- continue;
161
- }
162
- // Check id field
163
- if (!entry.id) {
164
- issues.push(`LINE_${lineNum}_MISSING_ID: No id field`);
165
- invalidEntries++;
166
- continue;
167
- }
168
- // Check duplicate ID
169
- if (seenIds.has(entry.id)) {
170
- issues.push(`LINE_${lineNum}_DUPLICATE_ID: ${entry.id} already exists`);
299
+ for (const entry of entries) {
300
+ const entryProblems = entryIssues(entry, entry.id);
301
+ const outputIssue = await currentOutputIssue(entry, root);
302
+ if (outputIssue)
303
+ entryProblems.push(outputIssue);
304
+ if (entryProblems.length)
171
305
  invalidEntries++;
172
- continue;
173
- }
174
- seenIds.add(entry.id);
175
- // Check file exists
176
- if (entry.file) {
177
- const absOutputDir = getAgentOutputsAbsolute(cwd);
178
- const filePath = join(absOutputDir, entry.file);
179
- if (!existsSync(filePath)) {
180
- issues.push(`LINE_${lineNum}_FILE_MISSING: ${entry.file} does not exist`);
181
- }
182
- }
183
- validEntries++;
306
+ issues.push(...entryProblems.map((issue) => `${entry.id}: ${issue}`));
184
307
  }
185
308
  return {
186
309
  exists: true,
187
310
  passed: issues.length === 0,
311
+ issues,
188
312
  stats: {
189
- totalLines: lines.length,
190
- validEntries,
313
+ totalLines: entries.length,
314
+ validEntries: entries.length - invalidEntries,
191
315
  invalidEntries,
192
316
  },
193
- issues,
194
317
  };
195
318
  }
196
- // ============================================================================
197
- // Pre-Spawn Compliance Verification
198
- // ============================================================================
199
319
  /**
200
- * Verify previous agent completed protocol compliance before spawning next.
201
- * @task T4519
320
+ * Check current canonical evidence for an exact task before another spawn.
321
+ * @remarks Requires explicit task linkage and valid fields/output; identifier
322
+ * substrings and follow-up requests cannot authorize the next action.
323
+ * @param previousTaskId - Exact task whose evidence is required.
324
+ * @param researchId - Optional exact canonical entry identity.
325
+ * @param cwd - Optional explicit project root.
326
+ * @returns Compliance result with current canonical evidence checks.
327
+ * @throws If canonical reads, history comparison or output resolution fail.
328
+ * @example
329
+ * ```ts
330
+ * const result = await verifyCurrentCompliance('T1', undefined, '/project');
331
+ * ```
202
332
  */
203
- export function verifyCompliance(previousTaskId, researchId, cwd) {
204
- const violations = [];
205
- const warnings = [];
206
- const entries = readManifestEntries(cwd);
207
- // Find manifest entry for previous task
208
- let entry;
209
- if (researchId) {
210
- entry = entries.find((e) => e.id === researchId);
211
- }
212
- else {
213
- // Search by linked_tasks
214
- entry = entries.find((e) => e.linked_tasks?.includes(previousTaskId) || e.needs_followup?.includes(previousTaskId));
215
- // Try ID pattern match
216
- if (!entry) {
217
- const taskNum = previousTaskId.replace(/^T/, '');
218
- entry = entries.find((e) => e.id.includes(taskNum));
219
- }
220
- }
221
- const manifestEntryExists = !!entry;
222
- if (!manifestEntryExists) {
223
- violations.push(`MANIFEST_ENTRY_MISSING: No manifest entry found for task ${previousTaskId}`);
224
- }
225
- // Check research linked to task
226
- let researchLinkedToTask = false;
227
- if (entry) {
228
- researchLinkedToTask = entry.linked_tasks?.includes(previousTaskId) ?? false;
229
- if (!researchLinkedToTask) {
230
- warnings.push(`RESEARCH_NOT_LINKED: Research entry exists but not linked to task ${previousTaskId}`);
231
- }
232
- }
233
- // Check return status
234
- let returnStatusValid = null;
235
- if (entry) {
236
- returnStatusValid = VALID_STATUSES_SET.has(entry.status);
237
- if (!returnStatusValid) {
238
- violations.push(`INVALID_MANIFEST_STATUS: ${entry.status}`);
239
- }
240
- }
241
- return {
242
- previousTaskId,
243
- researchId: entry?.id ?? null,
244
- checks: {
245
- manifestEntryExists,
246
- researchLinkedToTask,
247
- returnStatusValid,
248
- },
249
- canSpawnNext: violations.length === 0,
250
- violations,
251
- warnings,
252
- };
333
+ export async function verifyCurrentCompliance(previousTaskId, researchId, cwd) {
334
+ const root = currentRoot(cwd);
335
+ const entries = await readManifestEntries(root);
336
+ const entry = selectedEntry(entries, previousTaskId, researchId);
337
+ const issues = entryIssues(entry, researchId ?? previousTaskId);
338
+ const outputIssue = entry && (await currentOutputIssue(entry, root));
339
+ if (outputIssue)
340
+ issues.push(outputIssue);
341
+ return complianceResult(previousTaskId, entry, issues);
253
342
  }
254
343
  /**
255
344
  * Validate orchestrator compliance (post-hoc behavioral checks).
256
- * @task T4519
345
+ * @remarks Uses canonical manifest evidence and propagates failed task reads.
346
+ * @param epicId - Optional epic for dependency completion-order checks.
347
+ * @param cwd - Optional explicit project root.
348
+ * @returns Compliance result and observed protocol violations.
349
+ * @throws If canonical evidence or task storage reads fail.
350
+ * @example
351
+ * ```ts
352
+ * const result = await validateOrchestratorCompliance('T0', '/project');
353
+ * ```
257
354
  */
258
355
  export async function validateOrchestratorCompliance(epicId, cwd) {
259
356
  const violations = [];
260
357
  const warnings = [];
261
- const manifestPath = getManifestPath(cwd);
262
- // Check manifest usage
263
- if (!existsSync(manifestPath)) {
264
- warnings.push(`ORC-005_NO_MANIFEST: Manifest file not found at ${manifestPath}`);
265
- }
266
- else {
267
- const content = readFileSync(manifestPath, 'utf-8').trim();
268
- if (!content) {
269
- warnings.push('ORC-005_EMPTY_MANIFEST: Manifest exists but has no entries');
270
- }
271
- }
358
+ const root = currentRoot(cwd);
359
+ const manifest = await validateCurrentManifestIntegrity(root);
360
+ if (!manifest.passed)
361
+ violations.push(...manifest.issues);
272
362
  // Check dependency order (ORC-004) for completed tasks via DataAccessor
273
363
  if (epicId) {
274
- try {
275
- const acc = await getTaskAccessor(cwd);
276
- const children = await acc.getChildren(epicId);
277
- const tasks = children.filter((t) => t.status === 'done');
278
- // Sort by updatedAt and check for dependency violations
279
- const sorted = tasks.sort((a, b) => new Date(a.updatedAt ?? '').getTime() - new Date(b.updatedAt ?? '').getTime());
280
- const completionOrder = sorted.map((t) => t.id);
281
- for (let i = 0; i < sorted.length; i++) {
282
- const deps = sorted[i].depends ?? [];
283
- for (const dep of deps) {
284
- const depIdx = completionOrder.indexOf(dep);
285
- if (depIdx >= 0 && depIdx >= i) {
286
- violations.push(`ORC-004_DEPENDENCY_ORDER: Task ${sorted[i].id} completed before dependency ${dep}`);
287
- }
364
+ const acc = await getTaskAccessor(root);
365
+ if (!(await acc.loadSingleTask(epicId))) {
366
+ violations.push(`ORC_EPIC_NOT_FOUND: Cannot assess dependency order for ${epicId}`);
367
+ return { compliant: false, violations, warnings };
368
+ }
369
+ const children = await acc.getChildren(epicId);
370
+ const tasks = children.filter((t) => t.status === 'done');
371
+ // Sort by updatedAt and check for dependency violations
372
+ const sorted = tasks.sort((a, b) => new Date(a.updatedAt ?? '').getTime() - new Date(b.updatedAt ?? '').getTime());
373
+ const completionOrder = sorted.map((t) => t.id);
374
+ for (let i = 0; i < sorted.length; i++) {
375
+ const deps = sorted[i].depends ?? [];
376
+ for (const dep of deps) {
377
+ const depIdx = completionOrder.indexOf(dep);
378
+ if (depIdx >= 0 && depIdx >= i) {
379
+ violations.push(`ORC-004_DEPENDENCY_ORDER: Task ${sorted[i].id} completed before dependency ${dep}`);
288
380
  }
289
381
  }
290
382
  }
291
- catch {
292
- // Skip on DB error
293
- }
294
383
  }
295
384
  return {
296
385
  compliant: violations.length === 0,