@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
@@ -17,12 +17,18 @@
17
17
  */
18
18
  import { eq } from 'drizzle-orm';
19
19
  import { getLogger } from '../logger.js';
20
+ import { captureProjectScope, getProjectRoot, worktreeScope } from '../project-scope.js';
20
21
  import { checkSequence, repairSequence } from '../sequence/index.js';
21
22
  import { gitCheckpoint } from './git-checkpoint.js';
22
23
  import { getDb } from './sqlite.js';
23
24
  import { vacuumIntoBackup } from './sqlite-backup.js';
24
25
  import * as schema from './tasks-schema.js';
25
26
  const log = getLogger('data-safety');
27
+ /** Bind explicit ownership before the first asynchronous safety or callback step. */
28
+ function inSafetyScope(cwd, operation) {
29
+ const scope = captureProjectScope(cwd ?? getProjectRoot(), worktreeScope.getStore());
30
+ return worktreeScope.run(scope, () => operation(scope.worktreeRoot));
31
+ }
26
32
  /** Safety violation error */
27
33
  export class DataSafetyError extends Error {
28
34
  code;
@@ -127,21 +133,25 @@ async function verifyArchiveFile(data, accessor, options) {
127
133
  * Safe wrapper for DataAccessor.saveSessions()
128
134
  */
129
135
  export async function safeSaveSessions(accessor, data, cwd, options) {
130
- const opts = { ...DEFAULT_SAFETY, ...options };
131
- await accessor.saveSessions(data);
132
- stats.writes++;
133
- await verifySessions(data, accessor, opts);
134
- await checkpoint(`saved Sessions (${data.length} sessions)`, cwd, opts);
136
+ return inSafetyScope(cwd, async (cwd) => {
137
+ const opts = { ...DEFAULT_SAFETY, ...options };
138
+ await accessor.saveSessions(data);
139
+ stats.writes++;
140
+ await verifySessions(data, accessor, opts);
141
+ await checkpoint(`saved Sessions (${data.length} sessions)`, cwd, opts);
142
+ });
135
143
  }
136
144
  /**
137
145
  * Safe wrapper for DataAccessor.saveArchive()
138
146
  */
139
147
  export async function safeSaveArchive(accessor, data, cwd, options) {
140
- const opts = { ...DEFAULT_SAFETY, ...options };
141
- await accessor.saveArchive(data);
142
- stats.writes++;
143
- await verifyArchiveFile(data, accessor, opts);
144
- await checkpoint(`saved Archive (${data.archivedTasks.length} tasks)`, cwd, opts);
148
+ return inSafetyScope(cwd, async (cwd) => {
149
+ const opts = { ...DEFAULT_SAFETY, ...options };
150
+ await accessor.saveArchive(data);
151
+ stats.writes++;
152
+ await verifyArchiveFile(data, accessor, opts);
153
+ await checkpoint(`saved Archive (${data.archivedTasks.length} tasks)`, cwd, opts);
154
+ });
145
155
  }
146
156
  /**
147
157
  * Safe wrapper for single-task write operations (T5034).
@@ -155,14 +165,16 @@ export async function safeSaveArchive(accessor, data, cwd, options) {
155
165
  * itself is a targeted SQL operation that either succeeds or throws.
156
166
  */
157
167
  export async function safeSingleTaskWrite(_accessor, taskId, writeFn, cwd, options) {
158
- const opts = { ...DEFAULT_SAFETY, ...options };
159
- // 1. Validate sequence
160
- await ensureSequenceValid(cwd, opts);
161
- // 2. Perform targeted write
162
- await writeFn();
163
- stats.writes++;
164
- // 3. Checkpoint (lightweight — no full-file verify)
165
- await checkpoint(`single-task ${taskId}`, cwd, opts);
168
+ return inSafetyScope(cwd, async (cwd) => {
169
+ const opts = { ...DEFAULT_SAFETY, ...options };
170
+ // 1. Validate sequence
171
+ await ensureSequenceValid(cwd, opts);
172
+ // 2. Perform targeted write
173
+ await writeFn();
174
+ stats.writes++;
175
+ // 3. Checkpoint (lightweight — no full-file verify)
176
+ await checkpoint(`single-task ${taskId}`, cwd, opts);
177
+ });
166
178
  }
167
179
  /**
168
180
  * Safe wrapper for DataAccessor.appendLog()
@@ -171,77 +183,83 @@ export async function safeSingleTaskWrite(_accessor, taskId, writeFn, cwd, optio
171
183
  * but we still checkpoint to ensure data is committed.
172
184
  */
173
185
  export async function safeAppendLog(accessor, entry, cwd, options) {
174
- const opts = { ...DEFAULT_SAFETY, ...options, verify: false }; // Logs don't need verification
175
- await accessor.appendLog(entry);
176
- stats.writes++;
177
- await checkpoint('log entry', cwd, opts);
186
+ return inSafetyScope(cwd, async (cwd) => {
187
+ const opts = { ...DEFAULT_SAFETY, ...options, verify: false }; // Logs don't need verification
188
+ await accessor.appendLog(entry);
189
+ stats.writes++;
190
+ await checkpoint('log entry', cwd, opts);
191
+ });
178
192
  }
179
193
  /**
180
194
  * Run comprehensive data integrity check.
181
195
  * Validates all data files and sequence consistency.
182
196
  */
183
197
  export async function runDataIntegrityCheck(accessor, cwd) {
184
- const errors = [];
185
- const warnings = [];
186
- // 1. Check sequence
187
- try {
188
- const seqCheck = await checkSequence(cwd);
189
- if (!seqCheck.valid) {
190
- errors.push(`Sequence invalid: counter=${seqCheck.counter}, maxId=T${seqCheck.maxIdInData}`);
191
- // Try to repair
192
- const repair = await repairSequence(cwd);
193
- if (repair.repaired) {
194
- warnings.push(`Auto-repaired sequence: ${repair.oldCounter} -> ${repair.newCounter}`);
198
+ return inSafetyScope(cwd, async (cwd) => {
199
+ const errors = [];
200
+ const warnings = [];
201
+ // 1. Check sequence
202
+ try {
203
+ const seqCheck = await checkSequence(cwd);
204
+ if (!seqCheck.valid) {
205
+ errors.push(`Sequence invalid: counter=${seqCheck.counter}, maxId=T${seqCheck.maxIdInData}`);
206
+ // Try to repair
207
+ const repair = await repairSequence(cwd);
208
+ if (repair.repaired) {
209
+ warnings.push(`Auto-repaired sequence: ${repair.oldCounter} -> ${repair.newCounter}`);
210
+ }
211
+ else {
212
+ errors.push('Sequence auto-repair failed');
213
+ }
195
214
  }
196
- else {
197
- errors.push('Sequence auto-repair failed');
215
+ }
216
+ catch (err) {
217
+ errors.push(`Sequence check failed: ${String(err)}`);
218
+ }
219
+ // 2. Verify task data can be queried
220
+ try {
221
+ const count = await accessor.countTasks();
222
+ if (count < 0) {
223
+ errors.push('Task count returned negative value');
198
224
  }
199
225
  }
200
- }
201
- catch (err) {
202
- errors.push(`Sequence check failed: ${String(err)}`);
203
- }
204
- // 2. Verify task data can be queried
205
- try {
206
- const count = await accessor.countTasks();
207
- if (count < 0) {
208
- errors.push('Task count returned negative value');
226
+ catch (err) {
227
+ errors.push(`Task data query failed: ${String(err)}`);
209
228
  }
210
- }
211
- catch (err) {
212
- errors.push(`Task data query failed: ${String(err)}`);
213
- }
214
- try {
215
- const sessions = await accessor.loadSessions();
216
- if (!Array.isArray(sessions)) {
217
- errors.push('Sessions data is not an array');
229
+ try {
230
+ const sessions = await accessor.loadSessions();
231
+ if (!Array.isArray(sessions)) {
232
+ errors.push('Sessions data is not an array');
233
+ }
218
234
  }
219
- }
220
- catch (err) {
221
- errors.push(`Sessions load failed: ${String(err)}`);
222
- }
223
- // 3. Check for checkpoint recency
224
- if (stats.lastCheckpoint) {
225
- const minutesSinceCheckpoint = (Date.now() - stats.lastCheckpoint.getTime()) / 60000;
226
- if (minutesSinceCheckpoint > 60) {
227
- warnings.push(`Last checkpoint was ${Math.round(minutesSinceCheckpoint)} minutes ago`);
235
+ catch (err) {
236
+ errors.push(`Sessions load failed: ${String(err)}`);
228
237
  }
229
- }
230
- return {
231
- passed: errors.length === 0,
232
- errors,
233
- warnings,
234
- stats: getSafetyStats(),
235
- };
238
+ // 3. Check for checkpoint recency
239
+ if (stats.lastCheckpoint) {
240
+ const minutesSinceCheckpoint = (Date.now() - stats.lastCheckpoint.getTime()) / 60000;
241
+ if (minutesSinceCheckpoint > 60) {
242
+ warnings.push(`Last checkpoint was ${Math.round(minutesSinceCheckpoint)} minutes ago`);
243
+ }
244
+ }
245
+ return {
246
+ passed: errors.length === 0,
247
+ errors,
248
+ warnings,
249
+ stats: getSafetyStats(),
250
+ };
251
+ });
236
252
  }
237
253
  /**
238
254
  * Force immediate checkpoint.
239
255
  * Use before destructive operations.
240
256
  */
241
257
  export async function forceSafetyCheckpoint(context, cwd) {
242
- log.info({ context }, 'Forcing checkpoint');
243
- await gitCheckpoint('manual', context, cwd);
244
- vacuumIntoBackup({ cwd, force: true }).catch(() => { }); // non-fatal SQLite snapshot
258
+ return inSafetyScope(cwd, async (cwd) => {
259
+ log.info({ context }, 'Forcing checkpoint');
260
+ await gitCheckpoint('manual', context, cwd);
261
+ vacuumIntoBackup({ cwd, force: true }).catch(() => { }); // non-fatal SQLite snapshot
262
+ });
245
263
  }
246
264
  /**
247
265
  * Disable all safety for current process.
@@ -292,202 +310,222 @@ export class SafetyError extends Error {
292
310
  * @throws SafetyError if task exists and strict mode is enabled
293
311
  */
294
312
  export async function checkTaskExists(taskId, cwd, config = {}) {
295
- const cfg = { ...DEFAULT_CONFIG, ...config };
296
- if (!cfg.detectCollisions)
297
- return false;
298
- const db = await getDb(cwd);
299
- const existing = await db.select().from(schema.tasks).where(eq(schema.tasks.id, taskId)).all();
300
- const exists = existing.length > 0;
301
- if (exists && cfg.strictMode) {
302
- throw new SafetyError(`Task ID collision detected: ${taskId} already exists`, 'COLLISION_DETECTED', { taskId, existingTask: existing[0] });
303
- }
304
- return exists;
313
+ return inSafetyScope(cwd, async (cwd) => {
314
+ const cfg = { ...DEFAULT_CONFIG, ...config };
315
+ if (!cfg.detectCollisions)
316
+ return false;
317
+ const db = await getDb(cwd);
318
+ const existing = await db.select().from(schema.tasks).where(eq(schema.tasks.id, taskId)).all();
319
+ const exists = existing.length > 0;
320
+ if (exists && cfg.strictMode) {
321
+ throw new SafetyError(`Task ID collision detected: ${taskId} already exists`, 'COLLISION_DETECTED', { taskId, existingTask: existing[0] });
322
+ }
323
+ return exists;
324
+ });
305
325
  }
306
326
  /**
307
327
  * Verify a task was actually written to the database.
308
328
  * @throws SafetyError if verification fails
309
329
  */
310
330
  export async function verifyTaskWrite(taskId, expectedData, cwd, config = {}) {
311
- const cfg = { ...DEFAULT_CONFIG, ...config };
312
- if (!cfg.verifyWrites)
313
- return true;
314
- const db = await getDb(cwd);
315
- const rows = await db.select().from(schema.tasks).where(eq(schema.tasks.id, taskId)).all();
316
- if (rows.length === 0) {
317
- if (cfg.strictMode) {
318
- throw new SafetyError(`Write verification failed: Task ${taskId} not found after write`, 'WRITE_VERIFICATION_FAILED', { taskId });
331
+ return inSafetyScope(cwd, async (cwd) => {
332
+ const cfg = { ...DEFAULT_CONFIG, ...config };
333
+ if (!cfg.verifyWrites)
334
+ return true;
335
+ const db = await getDb(cwd);
336
+ const rows = await db.select().from(schema.tasks).where(eq(schema.tasks.id, taskId)).all();
337
+ if (rows.length === 0) {
338
+ if (cfg.strictMode) {
339
+ throw new SafetyError(`Write verification failed: Task ${taskId} not found after write`, 'WRITE_VERIFICATION_FAILED', { taskId });
340
+ }
341
+ return false;
319
342
  }
320
- return false;
321
- }
322
- // Verify expected data if provided
323
- if (expectedData) {
324
- const row = rows[0];
325
- for (const [key, value] of Object.entries(expectedData)) {
326
- if (value !== undefined && row[key] !== value) {
327
- if (cfg.strictMode) {
328
- throw new SafetyError(`Write verification failed: Task ${taskId} field ${key} mismatch`, 'WRITE_VERIFICATION_MISMATCH', { taskId, field: key, expected: value, actual: row[key] });
343
+ // Verify expected data if provided
344
+ if (expectedData) {
345
+ const row = rows[0];
346
+ for (const [key, value] of Object.entries(expectedData)) {
347
+ if (value !== undefined && row[key] !== value) {
348
+ if (cfg.strictMode) {
349
+ throw new SafetyError(`Write verification failed: Task ${taskId} field ${key} mismatch`, 'WRITE_VERIFICATION_MISMATCH', { taskId, field: key, expected: value, actual: row[key] });
350
+ }
351
+ return false;
329
352
  }
330
- return false;
331
353
  }
332
354
  }
333
- }
334
- return true;
355
+ return true;
356
+ });
335
357
  }
336
358
  /**
337
359
  * Validate and repair sequence if necessary.
338
360
  * @returns true if sequence was valid or successfully repaired
339
361
  */
340
362
  export async function validateAndRepairSequence(cwd, config = {}) {
341
- const cfg = { ...DEFAULT_CONFIG, ...config };
342
- if (!cfg.validateSequence)
343
- return { valid: true, repaired: false };
344
- try {
345
- const check = await checkSequence(cwd);
346
- if (check.valid) {
363
+ return inSafetyScope(cwd, async (cwd) => {
364
+ const cfg = { ...DEFAULT_CONFIG, ...config };
365
+ if (!cfg.validateSequence)
366
+ return { valid: true, repaired: false };
367
+ try {
368
+ const check = await checkSequence(cwd);
369
+ if (check.valid) {
370
+ return { valid: true, repaired: false };
371
+ }
372
+ // Sequence is behind, repair it
373
+ const repair = await repairSequence(cwd);
374
+ if (repair.repaired) {
375
+ log.warn({ oldCounter: repair.oldCounter, newCounter: repair.newCounter }, 'Sequence repaired');
376
+ return {
377
+ valid: true,
378
+ repaired: true,
379
+ oldCounter: repair.oldCounter,
380
+ newCounter: repair.newCounter,
381
+ };
382
+ }
383
+ // repairSequence returning repaired:false means "already valid, nothing to do"
347
384
  return { valid: true, repaired: false };
348
385
  }
349
- // Sequence is behind, repair it
350
- const repair = await repairSequence(cwd);
351
- if (repair.repaired) {
352
- log.warn({ oldCounter: repair.oldCounter, newCounter: repair.newCounter }, 'Sequence repaired');
353
- return {
354
- valid: true,
355
- repaired: true,
356
- oldCounter: repair.oldCounter,
357
- newCounter: repair.newCounter,
358
- };
359
- }
360
- // repairSequence returning repaired:false means "already valid, nothing to do"
361
- return { valid: true, repaired: false };
362
- }
363
- catch (err) {
364
- if (cfg.strictMode) {
365
- throw new SafetyError(`Sequence validation failed: ${String(err)}`, 'SEQUENCE_VALIDATION_FAILED', { error: String(err) });
386
+ catch (err) {
387
+ if (cfg.strictMode) {
388
+ throw new SafetyError(`Sequence validation failed: ${String(err)}`, 'SEQUENCE_VALIDATION_FAILED', { error: String(err) });
389
+ }
390
+ return { valid: false, repaired: false };
366
391
  }
367
- return { valid: false, repaired: false };
368
- }
392
+ });
369
393
  }
370
394
  /**
371
395
  * Trigger auto-checkpoint after a successful task write.
372
396
  */
373
397
  export async function triggerCheckpoint(context, cwd, config = {}) {
374
- const cfg = { ...DEFAULT_CONFIG, ...config };
375
- if (!cfg.autoCheckpoint)
376
- return;
377
- try {
378
- await gitCheckpoint('auto', context, cwd);
379
- }
380
- catch (err) {
381
- // Checkpoint failures are non-fatal but should be logged
382
- log.warn({ err }, 'Checkpoint failed (non-fatal)');
383
- }
384
- vacuumIntoBackup({ cwd }).catch(() => { }); // non-fatal SQLite snapshot
398
+ return inSafetyScope(cwd, async (cwd) => {
399
+ const cfg = { ...DEFAULT_CONFIG, ...config };
400
+ if (!cfg.autoCheckpoint)
401
+ return;
402
+ try {
403
+ await gitCheckpoint('auto', context, cwd);
404
+ }
405
+ catch (err) {
406
+ // Checkpoint failures are non-fatal but should be logged
407
+ log.warn({ err }, 'Checkpoint failed (non-fatal)');
408
+ }
409
+ vacuumIntoBackup({ cwd }).catch(() => { }); // non-fatal SQLite snapshot
410
+ });
385
411
  }
386
412
  /**
387
413
  * Safely create a task with all safety mechanisms.
388
414
  * Wraps the actual createTask operation.
389
415
  */
390
416
  export async function safeCreateTask(createFn, task, cwd, config = {}) {
391
- const cfg = { ...DEFAULT_CONFIG, ...config };
392
- // 1. Validate sequence before creation
393
- if (cfg.validateSequence) {
394
- await validateAndRepairSequence(cwd, config);
395
- }
396
- // 2. Check for collisions
397
- if (cfg.detectCollisions) {
398
- await checkTaskExists(task.id, cwd, config);
399
- }
400
- // 3. Perform the actual creation
401
- const result = await createFn();
402
- // 4. Trigger checkpoint
403
- if (cfg.autoCheckpoint) {
404
- await triggerCheckpoint(`created ${task.id}`, cwd, config);
405
- }
406
- return result;
417
+ return inSafetyScope(cwd, async (cwd) => {
418
+ const cfg = { ...DEFAULT_CONFIG, ...config };
419
+ // 1. Validate sequence before creation
420
+ if (cfg.validateSequence) {
421
+ await validateAndRepairSequence(cwd, config);
422
+ }
423
+ // 2. Check for collisions
424
+ if (cfg.detectCollisions) {
425
+ await checkTaskExists(task.id, cwd, config);
426
+ }
427
+ // 3. Perform the actual creation
428
+ const result = await createFn();
429
+ // 4. Trigger checkpoint
430
+ if (cfg.autoCheckpoint) {
431
+ await triggerCheckpoint(`created ${task.id}`, cwd, config);
432
+ }
433
+ return result;
434
+ });
407
435
  }
408
436
  /**
409
437
  * Safely update a task with all safety mechanisms.
410
438
  */
411
439
  export async function safeUpdateTask(updateFn, taskId, _updates, cwd, config = {}) {
412
- const cfg = { ...DEFAULT_CONFIG, ...config };
413
- // 1. Perform the actual update
414
- const result = await updateFn();
415
- if (!result)
416
- return null;
417
- // 2. Trigger checkpoint
418
- if (cfg.autoCheckpoint) {
419
- await triggerCheckpoint(`updated ${taskId}`, cwd, config);
420
- }
421
- return result;
440
+ return inSafetyScope(cwd, async (cwd) => {
441
+ const cfg = { ...DEFAULT_CONFIG, ...config };
442
+ // 1. Perform the actual update
443
+ const result = await updateFn();
444
+ if (!result)
445
+ return null;
446
+ // 2. Trigger checkpoint
447
+ if (cfg.autoCheckpoint) {
448
+ await triggerCheckpoint(`updated ${taskId}`, cwd, config);
449
+ }
450
+ return result;
451
+ });
422
452
  }
423
453
  /**
424
454
  * Safely delete a task with all safety mechanisms.
425
455
  */
426
456
  export async function safeDeleteTask(deleteFn, taskId, cwd, config = {}) {
427
- const cfg = { ...DEFAULT_CONFIG, ...config };
428
- // 1. Perform the actual deletion
429
- const result = await deleteFn();
430
- if (!result)
431
- return false;
432
- // 2. Trigger checkpoint
433
- if (cfg.autoCheckpoint) {
434
- await triggerCheckpoint(`deleted ${taskId}`, cwd, config);
435
- }
436
- return result;
457
+ return inSafetyScope(cwd, async (cwd) => {
458
+ const cfg = { ...DEFAULT_CONFIG, ...config };
459
+ // 1. Perform the actual deletion
460
+ const result = await deleteFn();
461
+ if (!result)
462
+ return false;
463
+ // 2. Trigger checkpoint
464
+ if (cfg.autoCheckpoint) {
465
+ await triggerCheckpoint(`deleted ${taskId}`, cwd, config);
466
+ }
467
+ return result;
468
+ });
437
469
  }
438
470
  /**
439
471
  * Verify a session write landed in the database.
440
472
  * @throws SafetyError if verification fails in strict mode
441
473
  */
442
474
  export async function verifySessionWrite(sessionId, cwd, config = {}) {
443
- const cfg = { ...DEFAULT_CONFIG, ...config };
444
- if (!cfg.verifyWrites)
445
- return true;
446
- const db = await getDb(cwd);
447
- const rows = await db
448
- .select()
449
- .from(schema.sessions)
450
- .where(eq(schema.sessions.id, sessionId))
451
- .all();
452
- if (rows.length === 0) {
453
- if (cfg.strictMode) {
454
- throw new SafetyError(`Write verification failed: Session ${sessionId} not found after write`, 'SESSION_WRITE_VERIFICATION_FAILED', { sessionId });
475
+ return inSafetyScope(cwd, async (cwd) => {
476
+ const cfg = { ...DEFAULT_CONFIG, ...config };
477
+ if (!cfg.verifyWrites)
478
+ return true;
479
+ const db = await getDb(cwd);
480
+ const rows = await db
481
+ .select()
482
+ .from(schema.sessions)
483
+ .where(eq(schema.sessions.id, sessionId))
484
+ .all();
485
+ if (rows.length === 0) {
486
+ if (cfg.strictMode) {
487
+ throw new SafetyError(`Write verification failed: Session ${sessionId} not found after write`, 'SESSION_WRITE_VERIFICATION_FAILED', { sessionId });
488
+ }
489
+ return false;
455
490
  }
456
- return false;
457
- }
458
- return true;
491
+ return true;
492
+ });
459
493
  }
460
494
  /**
461
495
  * Safely create a session with all safety mechanisms.
462
496
  */
463
497
  export async function safeCreateSession(createFn, session, cwd, config = {}) {
464
- const cfg = { ...DEFAULT_CONFIG, ...config };
465
- // 1. Perform the actual creation
466
- const result = await createFn();
467
- // 2. Verify the write
468
- if (cfg.verifyWrites) {
469
- await verifySessionWrite(session.id, cwd, config);
470
- }
471
- // 3. Trigger checkpoint
472
- if (cfg.autoCheckpoint) {
473
- await triggerCheckpoint(`session ${session.id} started`, cwd, config);
474
- }
475
- return result;
498
+ return inSafetyScope(cwd, async (cwd) => {
499
+ const cfg = { ...DEFAULT_CONFIG, ...config };
500
+ // 1. Perform the actual creation
501
+ const result = await createFn();
502
+ // 2. Verify the write
503
+ if (cfg.verifyWrites) {
504
+ await verifySessionWrite(session.id, cwd, config);
505
+ }
506
+ // 3. Trigger checkpoint
507
+ if (cfg.autoCheckpoint) {
508
+ await triggerCheckpoint(`session ${session.id} started`, cwd, config);
509
+ }
510
+ return result;
511
+ });
476
512
  }
477
513
  /**
478
514
  * Force a checkpoint before destructive operations.
479
515
  * Use this before migrations, bulk updates, etc.
480
516
  */
481
517
  export async function forceCheckpointBeforeOperation(operation, cwd) {
482
- log.info({ operation }, 'Forcing checkpoint before operation');
483
- try {
484
- await gitCheckpoint('manual', `pre-${operation}`, cwd);
485
- }
486
- catch (err) {
487
- log.error({ err }, 'Failed to create pre-operation checkpoint');
488
- // Don't throw - checkpoint failures shouldn't block operations
489
- }
490
- vacuumIntoBackup({ cwd, force: true }).catch(() => { }); // non-fatal SQLite snapshot
518
+ return inSafetyScope(cwd, async (cwd) => {
519
+ log.info({ operation }, 'Forcing checkpoint before operation');
520
+ try {
521
+ await gitCheckpoint('manual', `pre-${operation}`, cwd);
522
+ }
523
+ catch (err) {
524
+ log.error({ err }, 'Failed to create pre-operation checkpoint');
525
+ // Don't throw - checkpoint failures shouldn't block operations
526
+ }
527
+ vacuumIntoBackup({ cwd, force: true }).catch(() => { }); // non-fatal SQLite snapshot
528
+ });
491
529
  }
492
530
  /**
493
531
  * Run a sequence-focused integrity check keyed only by working directory.
@@ -497,30 +535,32 @@ export async function forceCheckpointBeforeOperation(operation, cwd) {
497
535
  * only. Retained for the lightweight `cwd`-only integrity probe.
498
536
  */
499
537
  export async function runSequenceIntegrityCheck(cwd) {
500
- const issues = [];
501
- const repairs = [];
502
- // 1. Check sequence
503
- try {
504
- const seqCheck = await checkSequence(cwd);
505
- if (!seqCheck.valid) {
506
- issues.push(`Sequence invalid: counter ${seqCheck.counter} < max ID T${seqCheck.maxIdInData}`);
507
- // Auto-repair
508
- const repair = await repairSequence(cwd);
509
- if (repair.repaired) {
510
- repairs.push(`Sequence repaired: ${repair.oldCounter} -> ${repair.newCounter}`);
511
- }
512
- else {
513
- issues.push('Sequence repair failed');
538
+ return inSafetyScope(cwd, async (cwd) => {
539
+ const issues = [];
540
+ const repairs = [];
541
+ // 1. Check sequence
542
+ try {
543
+ const seqCheck = await checkSequence(cwd);
544
+ if (!seqCheck.valid) {
545
+ issues.push(`Sequence invalid: counter ${seqCheck.counter} < max ID T${seqCheck.maxIdInData}`);
546
+ // Auto-repair
547
+ const repair = await repairSequence(cwd);
548
+ if (repair.repaired) {
549
+ repairs.push(`Sequence repaired: ${repair.oldCounter} -> ${repair.newCounter}`);
550
+ }
551
+ else {
552
+ issues.push('Sequence repair failed');
553
+ }
514
554
  }
515
555
  }
516
- }
517
- catch (err) {
518
- issues.push(`Sequence check failed: ${String(err)}`);
519
- }
520
- return {
521
- passed: issues.length === repairs.length,
522
- issues,
523
- repairs,
524
- };
556
+ catch (err) {
557
+ issues.push(`Sequence check failed: ${String(err)}`);
558
+ }
559
+ return {
560
+ passed: issues.length === repairs.length,
561
+ issues,
562
+ repairs,
563
+ };
564
+ });
525
565
  }
526
566
  //# sourceMappingURL=data-safety-central.js.map