@cleocode/core 2026.10.1 → 2026.10.3

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 (389) hide show
  1. package/dist/build-provenance.json +2 -2
  2. package/dist/cloud/http.d.ts +2 -0
  3. package/dist/cloud/http.d.ts.map +1 -1
  4. package/dist/cloud/http.js +3 -0
  5. package/dist/cloud/http.js.map +1 -1
  6. package/dist/cloud/journal.d.ts +9 -5
  7. package/dist/cloud/journal.d.ts.map +1 -1
  8. package/dist/cloud/journal.js +29 -8
  9. package/dist/cloud/journal.js.map +1 -1
  10. package/dist/cloud/manifest-check.d.ts +140 -4
  11. package/dist/cloud/manifest-check.d.ts.map +1 -1
  12. package/dist/cloud/manifest-check.js +322 -10
  13. package/dist/cloud/manifest-check.js.map +1 -1
  14. package/dist/cloud/nexus-attach.d.ts +25 -0
  15. package/dist/cloud/nexus-attach.d.ts.map +1 -1
  16. package/dist/cloud/nexus-attach.js +81 -6
  17. package/dist/cloud/nexus-attach.js.map +1 -1
  18. package/dist/cloud/nexus-cloud-activity.d.ts +37 -0
  19. package/dist/cloud/nexus-cloud-activity.d.ts.map +1 -0
  20. package/dist/cloud/nexus-cloud-activity.js +79 -0
  21. package/dist/cloud/nexus-cloud-activity.js.map +1 -0
  22. package/dist/cloud/nexus-cloud-status.d.ts.map +1 -1
  23. package/dist/cloud/nexus-cloud-status.js +36 -0
  24. package/dist/cloud/nexus-cloud-status.js.map +1 -1
  25. package/dist/cloud/nexus-device.d.ts +1 -1
  26. package/dist/cloud/nexus-enrol.d.ts.map +1 -1
  27. package/dist/cloud/nexus-enrol.js +5 -0
  28. package/dist/cloud/nexus-enrol.js.map +1 -1
  29. package/dist/cloud/nexus-home.d.ts +74 -0
  30. package/dist/cloud/nexus-home.d.ts.map +1 -0
  31. package/dist/cloud/nexus-home.js +97 -0
  32. package/dist/cloud/nexus-home.js.map +1 -0
  33. package/dist/cloud/nexus-vault-keys.d.ts +130 -0
  34. package/dist/cloud/nexus-vault-keys.d.ts.map +1 -0
  35. package/dist/cloud/nexus-vault-keys.js +347 -0
  36. package/dist/cloud/nexus-vault-keys.js.map +1 -0
  37. package/dist/cloud/nexus-vault-state.d.ts +121 -0
  38. package/dist/cloud/nexus-vault-state.d.ts.map +1 -0
  39. package/dist/cloud/nexus-vault-state.js +274 -0
  40. package/dist/cloud/nexus-vault-state.js.map +1 -0
  41. package/dist/cloud/nexus-vault.d.ts +160 -0
  42. package/dist/cloud/nexus-vault.d.ts.map +1 -0
  43. package/dist/cloud/nexus-vault.js +1745 -0
  44. package/dist/cloud/nexus-vault.js.map +1 -0
  45. package/dist/cloud/signing.d.ts +24 -8
  46. package/dist/cloud/signing.d.ts.map +1 -1
  47. package/dist/cloud/signing.js +61 -15
  48. package/dist/cloud/signing.js.map +1 -1
  49. package/dist/docs/export-document.js +8137 -3318
  50. package/dist/docs/export-document.js.map +3 -3
  51. package/dist/doctor/migrations.d.ts +75 -0
  52. package/dist/doctor/migrations.d.ts.map +1 -0
  53. package/dist/doctor/migrations.js +136 -0
  54. package/dist/doctor/migrations.js.map +1 -0
  55. package/dist/doctor/sync-sealer.d.ts +48 -0
  56. package/dist/doctor/sync-sealer.d.ts.map +1 -0
  57. package/dist/doctor/sync-sealer.js +109 -0
  58. package/dist/doctor/sync-sealer.js.map +1 -0
  59. package/dist/doctor/sync-triggers.d.ts +53 -0
  60. package/dist/doctor/sync-triggers.d.ts.map +1 -0
  61. package/dist/doctor/sync-triggers.js +157 -0
  62. package/dist/doctor/sync-triggers.js.map +1 -0
  63. package/dist/init.d.ts.map +1 -1
  64. package/dist/init.js +5 -1
  65. package/dist/init.js.map +1 -1
  66. package/dist/internal.d.ts +1 -1
  67. package/dist/internal.d.ts.map +1 -1
  68. package/dist/internal.js +1 -1
  69. package/dist/internal.js.map +1 -1
  70. package/dist/llm/plugin-facade.js +8442 -3623
  71. package/dist/llm/plugin-facade.js.map +3 -3
  72. package/dist/nexus/projects-clean.d.ts +3 -0
  73. package/dist/nexus/projects-clean.d.ts.map +1 -1
  74. package/dist/nexus/projects-clean.js +9 -3
  75. package/dist/nexus/projects-clean.js.map +1 -1
  76. package/dist/nexus/registry-roots.d.ts +3 -1
  77. package/dist/nexus/registry-roots.d.ts.map +1 -1
  78. package/dist/nexus/registry-roots.js +5 -2
  79. package/dist/nexus/registry-roots.js.map +1 -1
  80. package/dist/nexus/registry.d.ts +8 -1
  81. package/dist/nexus/registry.d.ts.map +1 -1
  82. package/dist/nexus/registry.js +24 -10
  83. package/dist/nexus/registry.js.map +1 -1
  84. package/dist/nexus/workspace.d.ts +4 -1
  85. package/dist/nexus/workspace.d.ts.map +1 -1
  86. package/dist/nexus/workspace.js +10 -4
  87. package/dist/nexus/workspace.js.map +1 -1
  88. package/dist/orchestrate/spawn-ops.d.ts.map +1 -1
  89. package/dist/orchestrate/spawn-ops.js +7 -2
  90. package/dist/orchestrate/spawn-ops.js.map +1 -1
  91. package/dist/orchestrate/worker-verify.d.ts +121 -12
  92. package/dist/orchestrate/worker-verify.d.ts.map +1 -1
  93. package/dist/orchestrate/worker-verify.js +172 -21
  94. package/dist/orchestrate/worker-verify.js.map +1 -1
  95. package/dist/orchestration/spawn-prompt.d.ts.map +1 -1
  96. package/dist/orchestration/spawn-prompt.js +15 -9
  97. package/dist/orchestration/spawn-prompt.js.map +1 -1
  98. package/dist/release/ci-evidence.d.ts +9 -0
  99. package/dist/release/ci-evidence.d.ts.map +1 -1
  100. package/dist/release/ci-evidence.js +9 -2
  101. package/dist/release/ci-evidence.js.map +1 -1
  102. package/dist/resources/backend.d.ts +15 -3
  103. package/dist/resources/backend.d.ts.map +1 -1
  104. package/dist/resources/backend.js +7 -3
  105. package/dist/resources/backend.js.map +1 -1
  106. package/dist/resources/darwin-backend.d.ts +142 -0
  107. package/dist/resources/darwin-backend.d.ts.map +1 -0
  108. package/dist/resources/darwin-backend.js +288 -0
  109. package/dist/resources/darwin-backend.js.map +1 -0
  110. package/dist/resources/governor.d.ts +44 -1
  111. package/dist/resources/governor.d.ts.map +1 -1
  112. package/dist/resources/governor.js +100 -36
  113. package/dist/resources/governor.js.map +1 -1
  114. package/dist/resources/heavy-command.d.ts +132 -0
  115. package/dist/resources/heavy-command.d.ts.map +1 -0
  116. package/dist/resources/heavy-command.js +768 -0
  117. package/dist/resources/heavy-command.js.map +1 -0
  118. package/dist/resources/monitor.d.ts +50 -1
  119. package/dist/resources/monitor.d.ts.map +1 -1
  120. package/dist/resources/monitor.js +83 -1
  121. package/dist/resources/monitor.js.map +1 -1
  122. package/dist/resources/run-admission.d.ts +303 -0
  123. package/dist/resources/run-admission.d.ts.map +1 -0
  124. package/dist/resources/run-admission.js +648 -0
  125. package/dist/resources/run-admission.js.map +1 -0
  126. package/dist/resources/run-class.d.ts +111 -0
  127. package/dist/resources/run-class.d.ts.map +1 -0
  128. package/dist/resources/run-class.js +658 -0
  129. package/dist/resources/run-class.js.map +1 -0
  130. package/dist/resources/run-governed.d.ts +158 -0
  131. package/dist/resources/run-governed.d.ts.map +1 -0
  132. package/dist/resources/run-governed.js +406 -0
  133. package/dist/resources/run-governed.js.map +1 -0
  134. package/dist/resources/slot-holder.d.ts +267 -0
  135. package/dist/resources/slot-holder.d.ts.map +1 -0
  136. package/dist/resources/slot-holder.js +505 -0
  137. package/dist/resources/slot-holder.js.map +1 -0
  138. package/dist/resources/tool-groups.d.ts +74 -0
  139. package/dist/resources/tool-groups.d.ts.map +1 -0
  140. package/dist/resources/tool-groups.js +118 -0
  141. package/dist/resources/tool-groups.js.map +1 -0
  142. package/dist/routing/build-command-groups.d.ts.map +1 -1
  143. package/dist/routing/build-command-groups.js +1 -0
  144. package/dist/routing/build-command-groups.js.map +1 -1
  145. package/dist/selfimprove/fix-gen.js +8446 -3627
  146. package/dist/selfimprove/fix-gen.js.map +3 -3
  147. package/dist/sentient/cross-project-hygiene.d.ts +3 -2
  148. package/dist/sentient/cross-project-hygiene.d.ts.map +1 -1
  149. package/dist/sentient/cross-project-hygiene.js +5 -2
  150. package/dist/sentient/cross-project-hygiene.js.map +1 -1
  151. package/dist/sentient/state.d.ts +7 -0
  152. package/dist/sentient/state.d.ts.map +1 -1
  153. package/dist/sentient/state.js.map +1 -1
  154. package/dist/sentient/tick.d.ts +14 -2
  155. package/dist/sentient/tick.d.ts.map +1 -1
  156. package/dist/sentient/tick.js +63 -4
  157. package/dist/sentient/tick.js.map +1 -1
  158. package/dist/store/backup-recover.d.ts.map +1 -1
  159. package/dist/store/backup-recover.js +5 -0
  160. package/dist/store/backup-recover.js.map +1 -1
  161. package/dist/store/data-accessor.d.ts +1 -0
  162. package/dist/store/data-accessor.d.ts.map +1 -1
  163. package/dist/store/data-accessor.js +7 -0
  164. package/dist/store/data-accessor.js.map +1 -1
  165. package/dist/store/dual-scope-db.d.ts +23 -1
  166. package/dist/store/dual-scope-db.d.ts.map +1 -1
  167. package/dist/store/dual-scope-db.js +126 -36
  168. package/dist/store/dual-scope-db.js.map +1 -1
  169. package/dist/store/exodus/recovery.d.ts.map +1 -1
  170. package/dist/store/exodus/recovery.js +15 -0
  171. package/dist/store/exodus/recovery.js.map +1 -1
  172. package/dist/store/legacy-tasks-lineage.d.ts.map +1 -1
  173. package/dist/store/legacy-tasks-lineage.js +5 -0
  174. package/dist/store/legacy-tasks-lineage.js.map +1 -1
  175. package/dist/store/lock.d.ts +8 -1
  176. package/dist/store/lock.d.ts.map +1 -1
  177. package/dist/store/lock.js +10 -2
  178. package/dist/store/lock.js.map +1 -1
  179. package/dist/store/migration-manager.d.ts +5 -0
  180. package/dist/store/migration-manager.d.ts.map +1 -1
  181. package/dist/store/migration-manager.js +11 -0
  182. package/dist/store/migration-manager.js.map +1 -1
  183. package/dist/store/migration-runner.d.ts +158 -0
  184. package/dist/store/migration-runner.d.ts.map +1 -0
  185. package/dist/store/migration-runner.js +493 -0
  186. package/dist/store/migration-runner.js.map +1 -0
  187. package/dist/store/portable-bundle-import.d.ts +15 -1
  188. package/dist/store/portable-bundle-import.d.ts.map +1 -1
  189. package/dist/store/portable-bundle-import.js +24 -4
  190. package/dist/store/portable-bundle-import.js.map +1 -1
  191. package/dist/store/portable-bundle-relocate.d.ts +43 -0
  192. package/dist/store/portable-bundle-relocate.d.ts.map +1 -1
  193. package/dist/store/portable-bundle-relocate.js +79 -5
  194. package/dist/store/portable-bundle-relocate.js.map +1 -1
  195. package/dist/store/portable-bundle-scan.d.ts +42 -0
  196. package/dist/store/portable-bundle-scan.d.ts.map +1 -1
  197. package/dist/store/portable-bundle-scan.js +132 -25
  198. package/dist/store/portable-bundle-scan.js.map +1 -1
  199. package/dist/store/portable-bundle.d.ts +40 -0
  200. package/dist/store/portable-bundle.d.ts.map +1 -1
  201. package/dist/store/portable-bundle.js +43 -7
  202. package/dist/store/portable-bundle.js.map +1 -1
  203. package/dist/store/row-identity-registry.d.ts +137 -7
  204. package/dist/store/row-identity-registry.d.ts.map +1 -1
  205. package/dist/store/row-identity-registry.js +364 -9
  206. package/dist/store/row-identity-registry.js.map +1 -1
  207. package/dist/store/row-identity.d.ts.map +1 -1
  208. package/dist/store/row-identity.js +9 -10
  209. package/dist/store/row-identity.js.map +1 -1
  210. package/dist/store/sqlite-data-accessor.d.ts.map +1 -1
  211. package/dist/store/sqlite-data-accessor.js +10 -0
  212. package/dist/store/sqlite-data-accessor.js.map +1 -1
  213. package/dist/store/sqlite.d.ts +31 -0
  214. package/dist/store/sqlite.d.ts.map +1 -1
  215. package/dist/store/sqlite.js +5 -1
  216. package/dist/store/sqlite.js.map +1 -1
  217. package/dist/store/sync/capture.d.ts +203 -0
  218. package/dist/store/sync/capture.d.ts.map +1 -0
  219. package/dist/store/sync/capture.js +562 -0
  220. package/dist/store/sync/capture.js.map +1 -0
  221. package/dist/store/sync/clock-store.d.ts.map +1 -1
  222. package/dist/store/sync/clock-store.js +2 -0
  223. package/dist/store/sync/clock-store.js.map +1 -1
  224. package/dist/store/sync/fk-orphans.d.ts +133 -0
  225. package/dist/store/sync/fk-orphans.d.ts.map +1 -0
  226. package/dist/store/sync/fk-orphans.js +265 -0
  227. package/dist/store/sync/fk-orphans.js.map +1 -0
  228. package/dist/store/sync/flags.d.ts +7 -0
  229. package/dist/store/sync/flags.d.ts.map +1 -1
  230. package/dist/store/sync/flags.js +16 -0
  231. package/dist/store/sync/flags.js.map +1 -1
  232. package/dist/store/sync/hlc.d.ts.map +1 -1
  233. package/dist/store/sync/hlc.js +4 -0
  234. package/dist/store/sync/hlc.js.map +1 -1
  235. package/dist/store/sync/identity-fill.d.ts +45 -0
  236. package/dist/store/sync/identity-fill.d.ts.map +1 -0
  237. package/dist/store/sync/identity-fill.js +85 -0
  238. package/dist/store/sync/identity-fill.js.map +1 -0
  239. package/dist/store/sync/machinery.d.ts +27 -0
  240. package/dist/store/sync/machinery.d.ts.map +1 -0
  241. package/dist/store/sync/machinery.js +44 -0
  242. package/dist/store/sync/machinery.js.map +1 -0
  243. package/dist/store/sync/netting.d.ts +120 -0
  244. package/dist/store/sync/netting.d.ts.map +1 -0
  245. package/dist/store/sync/netting.js +336 -0
  246. package/dist/store/sync/netting.js.map +1 -0
  247. package/dist/store/sync/replica.d.ts +27 -2
  248. package/dist/store/sync/replica.d.ts.map +1 -1
  249. package/dist/store/sync/replica.js +47 -3
  250. package/dist/store/sync/replica.js.map +1 -1
  251. package/dist/store/sync/schema.d.ts +12 -0
  252. package/dist/store/sync/schema.d.ts.map +1 -1
  253. package/dist/store/sync/schema.js +21 -0
  254. package/dist/store/sync/schema.js.map +1 -1
  255. package/dist/store/sync/seal-backlog.d.ts +21 -0
  256. package/dist/store/sync/seal-backlog.d.ts.map +1 -0
  257. package/dist/store/sync/seal-backlog.js +24 -0
  258. package/dist/store/sync/seal-backlog.js.map +1 -0
  259. package/dist/store/sync/sealer-values.d.ts +34 -0
  260. package/dist/store/sync/sealer-values.d.ts.map +1 -0
  261. package/dist/store/sync/sealer-values.js +53 -0
  262. package/dist/store/sync/sealer-values.js.map +1 -0
  263. package/dist/store/sync/sealer.d.ts +145 -0
  264. package/dist/store/sync/sealer.d.ts.map +1 -0
  265. package/dist/store/sync/sealer.js +906 -0
  266. package/dist/store/sync/sealer.js.map +1 -0
  267. package/dist/store/sync/structural.d.ts +63 -0
  268. package/dist/store/sync/structural.d.ts.map +1 -0
  269. package/dist/store/sync/structural.js +180 -0
  270. package/dist/store/sync/structural.js.map +1 -0
  271. package/dist/store/sync/timestamps.d.ts +92 -0
  272. package/dist/store/sync/timestamps.d.ts.map +1 -0
  273. package/dist/store/sync/timestamps.js +228 -0
  274. package/dist/store/sync/timestamps.js.map +1 -0
  275. package/dist/store/sync/tombstones.d.ts +75 -0
  276. package/dist/store/sync/tombstones.d.ts.map +1 -0
  277. package/dist/store/sync/tombstones.js +103 -0
  278. package/dist/store/sync/tombstones.js.map +1 -0
  279. package/dist/store/sync/trigger-classes.d.ts +221 -0
  280. package/dist/store/sync/trigger-classes.d.ts.map +1 -0
  281. package/dist/store/sync/trigger-classes.js +441 -0
  282. package/dist/store/sync/trigger-classes.js.map +1 -0
  283. package/dist/store/sync/trigger-suspend-at-path.d.ts +23 -0
  284. package/dist/store/sync/trigger-suspend-at-path.d.ts.map +1 -0
  285. package/dist/store/sync/trigger-suspend-at-path.js +44 -0
  286. package/dist/store/sync/trigger-suspend-at-path.js.map +1 -0
  287. package/dist/store/sync/writer-version.d.ts +43 -0
  288. package/dist/store/sync/writer-version.d.ts.map +1 -0
  289. package/dist/store/sync/writer-version.js +90 -0
  290. package/dist/store/sync/writer-version.js.map +1 -0
  291. package/dist/store/table-classification.d.ts.map +1 -1
  292. package/dist/store/table-classification.js +102 -0
  293. package/dist/store/table-classification.js.map +1 -1
  294. package/dist/store/trigger-suspend-schema.d.ts +44 -0
  295. package/dist/store/trigger-suspend-schema.d.ts.map +1 -0
  296. package/dist/store/trigger-suspend-schema.js +25 -0
  297. package/dist/store/trigger-suspend-schema.js.map +1 -0
  298. package/dist/store/vault-manifest.d.ts +365 -0
  299. package/dist/store/vault-manifest.d.ts.map +1 -0
  300. package/dist/store/vault-manifest.js +812 -0
  301. package/dist/store/vault-manifest.js.map +1 -0
  302. package/dist/store/writer-lease.d.ts +31 -0
  303. package/dist/store/writer-lease.d.ts.map +1 -1
  304. package/dist/store/writer-lease.js +65 -2
  305. package/dist/store/writer-lease.js.map +1 -1
  306. package/dist/system/health.d.ts.map +1 -1
  307. package/dist/system/health.js +21 -0
  308. package/dist/system/health.js.map +1 -1
  309. package/dist/system/project-health.d.ts.map +1 -1
  310. package/dist/system/project-health.js +3 -1
  311. package/dist/system/project-health.js.map +1 -1
  312. package/dist/tasks/affected-packages.d.ts +58 -0
  313. package/dist/tasks/affected-packages.d.ts.map +1 -1
  314. package/dist/tasks/affected-packages.js +75 -6
  315. package/dist/tasks/affected-packages.js.map +1 -1
  316. package/dist/tasks/affected-scope.d.ts +150 -23
  317. package/dist/tasks/affected-scope.d.ts.map +1 -1
  318. package/dist/tasks/affected-scope.js +320 -32
  319. package/dist/tasks/affected-scope.js.map +1 -1
  320. package/dist/tasks/change-set.d.ts +96 -0
  321. package/dist/tasks/change-set.d.ts.map +1 -1
  322. package/dist/tasks/change-set.js +169 -4
  323. package/dist/tasks/change-set.js.map +1 -1
  324. package/dist/tasks/complete-ci.d.ts +115 -0
  325. package/dist/tasks/complete-ci.d.ts.map +1 -0
  326. package/dist/tasks/complete-ci.js +171 -0
  327. package/dist/tasks/complete-ci.js.map +1 -0
  328. package/dist/tasks/complete.d.ts.map +1 -1
  329. package/dist/tasks/complete.js +50 -17
  330. package/dist/tasks/complete.js.map +1 -1
  331. package/dist/tasks/compute-task-view.d.ts.map +1 -1
  332. package/dist/tasks/compute-task-view.js +7 -0
  333. package/dist/tasks/compute-task-view.js.map +1 -1
  334. package/dist/tasks/done-plan.d.ts.map +1 -1
  335. package/dist/tasks/done-plan.js +51 -30
  336. package/dist/tasks/done-plan.js.map +1 -1
  337. package/dist/tasks/done-record.d.ts +6 -0
  338. package/dist/tasks/done-record.d.ts.map +1 -1
  339. package/dist/tasks/done-record.js +9 -3
  340. package/dist/tasks/done-record.js.map +1 -1
  341. package/dist/tasks/evidence.d.ts +3 -2
  342. package/dist/tasks/evidence.d.ts.map +1 -1
  343. package/dist/tasks/evidence.js +143 -12
  344. package/dist/tasks/evidence.js.map +1 -1
  345. package/dist/tasks/gate-notes.d.ts +22 -0
  346. package/dist/tasks/gate-notes.d.ts.map +1 -0
  347. package/dist/tasks/gate-notes.js +33 -0
  348. package/dist/tasks/gate-notes.js.map +1 -0
  349. package/dist/tasks/index.d.ts +2 -1
  350. package/dist/tasks/index.d.ts.map +1 -1
  351. package/dist/tasks/index.js +2 -1
  352. package/dist/tasks/index.js.map +1 -1
  353. package/dist/tasks/test-run-binding.d.ts +117 -0
  354. package/dist/tasks/test-run-binding.d.ts.map +1 -0
  355. package/dist/tasks/test-run-binding.js +365 -0
  356. package/dist/tasks/test-run-binding.js.map +1 -0
  357. package/dist/tasks/tool-cache-env.d.ts +123 -0
  358. package/dist/tasks/tool-cache-env.d.ts.map +1 -0
  359. package/dist/tasks/tool-cache-env.js +287 -0
  360. package/dist/tasks/tool-cache-env.js.map +1 -0
  361. package/dist/tasks/tool-cache-failed-first.d.ts +155 -0
  362. package/dist/tasks/tool-cache-failed-first.d.ts.map +1 -0
  363. package/dist/tasks/tool-cache-failed-first.js +285 -0
  364. package/dist/tasks/tool-cache-failed-first.js.map +1 -0
  365. package/dist/tasks/tool-cache.d.ts +375 -55
  366. package/dist/tasks/tool-cache.d.ts.map +1 -1
  367. package/dist/tasks/tool-cache.js +912 -303
  368. package/dist/tasks/tool-cache.js.map +1 -1
  369. package/dist/tasks/tool-resolver.d.ts +4 -3
  370. package/dist/tasks/tool-resolver.d.ts.map +1 -1
  371. package/dist/tasks/tool-resolver.js +15 -4
  372. package/dist/tasks/tool-resolver.js.map +1 -1
  373. package/dist/tasks/tool-semaphore.d.ts +67 -7
  374. package/dist/tasks/tool-semaphore.d.ts.map +1 -1
  375. package/dist/tasks/tool-semaphore.js +134 -56
  376. package/dist/tasks/tool-semaphore.js.map +1 -1
  377. package/dist/upgrade.d.ts.map +1 -1
  378. package/dist/upgrade.js +4 -0
  379. package/dist/upgrade.js.map +1 -1
  380. package/dist/validation/engine-ops.d.ts +6 -0
  381. package/dist/validation/engine-ops.d.ts.map +1 -1
  382. package/dist/validation/engine-ops.js +8 -0
  383. package/dist/validation/engine-ops.js.map +1 -1
  384. package/migrations/drizzle-cleo-project/20260930170000_t12819-trigger-suspend-clause/migration.sql +367 -0
  385. package/migrations/sync-journal/20260930120000_t12343-capture/migration.sql +47 -0
  386. package/migrations/sync-journal/20261001170000_t12984-sealer/migration.sql +101 -0
  387. package/package.json +13 -13
  388. package/templates/CLEO-INJECTION.md +5 -5
  389. package/templates/CLEO-REFERENCE.md +8 -4
@@ -0,0 +1,97 @@
1
+ /**
2
+ * This device's global CLEO store (the main brain) on Cleo Nexus: bind its
3
+ * global-scope replica and attach it to the account's `home:` stream with
4
+ * presence (T12952, cleo-nexus T084). `cleo login nexus` runs it after a
5
+ * device login, so login stays the only setup step; `cleo cloud status`
6
+ * reads the attachments back.
7
+ *
8
+ * A server that does not have the home-replica endpoints yet answers 404:
9
+ * that is reported as a warning, never a failure.
10
+ *
11
+ * @task T12952
12
+ * @epic T12323
13
+ */
14
+ import { z } from 'zod';
15
+ import { NexusError } from './http.js';
16
+ import { attachHomeReplica } from './nexus-attach.js';
17
+ import { resolveNexusApiUrl } from './nexus-auth.js';
18
+ import { connectNexusCloud } from './nexus-cloud.js';
19
+ import { isNexusDeviceEnabled } from './nexus-device.js';
20
+ import { ensureNexusDeviceCredential } from './nexus-enrol.js';
21
+ /** Warning code: the server has no home-replica endpoints yet. */
22
+ export const W_NEXUS_HOME_UNSUPPORTED = 'W_NEXUS_HOME_UNSUPPORTED';
23
+ /**
24
+ * Attach this device's global store to the account's home stream.
25
+ *
26
+ * @param opts - API URL, stores and overrides.
27
+ * @returns The attachment (or `null` when the server does not support it) and warnings.
28
+ * @throws {NexusAccountError} Not signed in, or `E_NEXUS_REPLICA_COPIED`.
29
+ */
30
+ export async function attachNexusGlobalStore(opts = {}) {
31
+ if (!isNexusDeviceEnabled())
32
+ return { replica: null, warnings: [] };
33
+ const apiUrl = resolveNexusApiUrl(opts.apiUrl);
34
+ const handle = await ensureNexusDeviceCredential({ ...opts, apiUrl });
35
+ const bearer = handle.device.currentBearer();
36
+ if (bearer === null)
37
+ return { replica: null, warnings: [...handle.warnings] };
38
+ let cliVersion = opts.cliVersion;
39
+ if (cliVersion === undefined) {
40
+ const { getCleoVersion } = await import('../scaffold/ensure-config.js');
41
+ cliVersion = getCleoVersion();
42
+ }
43
+ try {
44
+ const r = await attachHomeReplica({
45
+ apiUrl,
46
+ bearer,
47
+ deviceId: handle.device.deviceId,
48
+ cliVersion,
49
+ ...(opts.binder ? { binder: opts.binder } : {}),
50
+ ...(opts.fetch ? { fetch: opts.fetch } : {}),
51
+ });
52
+ return { replica: r.replica, warnings: [...handle.warnings, ...r.warnings] };
53
+ }
54
+ catch (err) {
55
+ if (err instanceof NexusError && err.status === 404) {
56
+ return {
57
+ replica: null,
58
+ warnings: [
59
+ ...handle.warnings,
60
+ `${W_NEXUS_HOME_UNSUPPORTED}: this Cleo Nexus server does not attach global stores yet`,
61
+ ],
62
+ };
63
+ }
64
+ throw err;
65
+ }
66
+ }
67
+ /** One home-stream replica as `GET /v1/account/home/replicas` lists it. */
68
+ export const nexusHomeReplicaSchema = z.looseObject({
69
+ replicaId: z.string(),
70
+ deviceId: z.string(),
71
+ deviceState: z.string().optional(),
72
+ presenceAt: z.string().nullable().optional(),
73
+ lastSyncAt: z.string().nullable().optional(),
74
+ attachedAt: z.string().optional(),
75
+ });
76
+ /** `GET /v1/account/home/replicas`. */
77
+ export const nexusHomeReplicaListSchema = z.looseObject({
78
+ replicas: z.array(nexusHomeReplicaSchema),
79
+ });
80
+ /**
81
+ * Read the account's global-store attachments (GET only).
82
+ *
83
+ * @param opts - API URL, stores and overrides.
84
+ * @returns The attachments; `supported: false` when the server has no such endpoint.
85
+ */
86
+ export async function nexusGlobalStoreStatus(opts = {}) {
87
+ const conn = await connectNexusCloud(opts);
88
+ const list = await conn.find('/v1/account/home/replicas', nexusHomeReplicaListSchema);
89
+ if (list === null)
90
+ return { supported: false, thisDevice: null, replicas: [] };
91
+ return {
92
+ supported: true,
93
+ thisDevice: list.replicas.find((r) => r.deviceId === conn.device.deviceId) ?? null,
94
+ replicas: list.replicas,
95
+ };
96
+ }
97
+ //# sourceMappingURL=nexus-home.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nexus-home.js","sourceRoot":"","sources":["../../src/cloud/nexus-home.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAA6B,MAAM,mBAAmB,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAA0B,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAE/D,kEAAkE;AAClE,MAAM,CAAC,MAAM,wBAAwB,GAAG,0BAA0B,CAAC;AAUnE;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,OAAsC,EAAE;IAExC,IAAI,CAAC,oBAAoB,EAAE;QAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IACpE,MAAM,MAAM,GAAG,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,MAAM,2BAA2B,CAAC,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IACtE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,a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C;AACJ,CAAC"}
@@ -0,0 +1,130 @@
1
+ /**
2
+ * The vault's connection and keys: a read-write device connection, the
3
+ * account master key, this device's certificate, and the stream data keys.
4
+ *
5
+ * Owner decision (2026-10-01): adding a device needs only `cleo login` and
6
+ * the one-time browser approval; that approval also hands the device the
7
+ * encryption key. So the account master key (MK) is escrowed on Cleo Nexus:
8
+ *
9
+ * 1. `GET /v1/account/keys/escrow` returns MK sealed to this device's X25519
10
+ * key (`sealTo`), released only to an approved, active device. The client
11
+ * opens it with the device's private key and checks it against the
12
+ * escrow's verifier.
13
+ * 2. No escrow and no account keys: this is the account's first vault use.
14
+ * The client mints MK and escrows it (`PUT`, insert-only). A concurrent
15
+ * first device loses the insert with 409 and reads the winner's key.
16
+ * 3. The device certifies itself under MK (a self-grant, `PUT
17
+ * /v1/devices/:id/key`), so other devices can verify its snapshots.
18
+ * 4. Signer trust comes from `certifiedSigners` over `GET /v1/devices/trust`,
19
+ * with the trust state persisted in {@link NexusVaultState}.
20
+ *
21
+ * Threat model (cleo-nexus T082): the escrow `PUT` sends MK to the server
22
+ * over TLS, and the server stores it encrypted under a server-held key
23
+ * (`KEY_ESCROW_SECRET`). Snapshots are therefore encrypted at rest with keys
24
+ * Cleo Nexus can recover: this is server-escrowed encryption, not
25
+ * zero-knowledge end-to-end encryption. What the escrow does guarantee is
26
+ * that MK is released only to an approved, active device of the account,
27
+ * sealed to that device's key.
28
+ *
29
+ * A project's data key (PDK) is minted by its first pusher and stored
30
+ * wrapped by MK (`PUT /v1/projects/:id/keys/:userId`); the home stream key
31
+ * is derived from MK.
32
+ *
33
+ * No function here logs a key, and no error carries one.
34
+ *
35
+ * @task T12336
36
+ * @epic T12322
37
+ */
38
+ import type { CloudWarning } from '@cleocode/contracts';
39
+ import { type KeyPair } from './crypto.js';
40
+ import { type FetchLike, Http, type ResponseSchema } from './http.js';
41
+ import { type TrustedSigners } from './keys.js';
42
+ import { resolveNexusApiUrl } from './nexus-auth.js';
43
+ import { type NexusCloudOptions } from './nexus-cloud.js';
44
+ import type { SealedNexusDevice } from './nexus-device.js';
45
+ import { NexusVaultState } from './nexus-vault-state.js';
46
+ /** Timeout of a snapshot blob upload or download. */
47
+ export declare const NEXUS_VAULT_BLOB_TIMEOUT_MS: number;
48
+ /** The sealed-box context of an escrow release (must match the server, cleo-nexus T082). */
49
+ export declare const escrowContext: (userId: string, deviceId: string) => string;
50
+ /** Options of every vault command. */
51
+ export interface NexusVaultOptions extends NexusCloudOptions {
52
+ /** Vault state store (tests). */
53
+ vaultState?: NexusVaultState;
54
+ /** Timeout of a blob transfer; default {@link NEXUS_VAULT_BLOB_TIMEOUT_MS}. */
55
+ blobTimeoutMs?: number;
56
+ }
57
+ /** A read-write connection with this machine's device credential and keys. */
58
+ export interface NexusVaultConnection {
59
+ readonly apiUrl: string;
60
+ readonly userId: string;
61
+ readonly deviceId: string;
62
+ readonly device: SealedNexusDevice;
63
+ /** Device keys: X25519 for sealed boxes, Ed25519 for signatures. */
64
+ readonly keys: {
65
+ encryption: KeyPair;
66
+ signing: KeyPair;
67
+ };
68
+ /** The authenticated client (sends `X-Cleo-Device-Id`). For the journal. */
69
+ readonly http: Http;
70
+ /** `fetch` for presigned blob transfers (long timeout, no credential). */
71
+ readonly blobFetch: FetchLike;
72
+ readonly state: NexusVaultState;
73
+ readonly warnings: CloudWarning[];
74
+ /** A request whose failure stays a raw {@link NexusError} (callers handle server codes). */
75
+ raw<T>(method: string, path: string, schema: ResponseSchema<T>, body?: unknown): Promise<T>;
76
+ /** {@link NexusVaultConnection.raw}, with failures mapped to {@link NexusAccountError}. */
77
+ call<T>(method: string, path: string, schema: ResponseSchema<T>, body?: unknown): Promise<T>;
78
+ /** `GET`, mapped; a 404 answers `null`. */
79
+ find<T>(path: string, schema: ResponseSchema<T>): Promise<T | null>;
80
+ }
81
+ /**
82
+ * Open a read-write vault connection with this machine's device credential.
83
+ *
84
+ * @param opts - API URL, account, stores and test overrides.
85
+ * @returns The connection.
86
+ * @throws {NexusAccountError} Not signed in, device mode off, or no device keys.
87
+ */
88
+ export declare function connectNexusVault(opts?: NexusVaultOptions): Promise<NexusVaultConnection>;
89
+ /** The unlocked account key and the signers this device trusts. */
90
+ export interface NexusAccountKey {
91
+ masterKey: Buffer;
92
+ keyVersion: number;
93
+ signers: TrustedSigners;
94
+ }
95
+ /**
96
+ * Get the account master key for this device, minting and escrowing it on
97
+ * the account's first vault use, and certify this device under it.
98
+ *
99
+ * @param conn - A vault connection.
100
+ * @param opts - `readOnly`: never mint, escrow or certify (GET only); a missing escrow is
101
+ * `E_NEXUS_VAULT_EMPTY`.
102
+ * @returns The key, its version and the trusted signers.
103
+ * @throws {NexusAccountError} `E_NEXUS_VAULT_KEY_UNAVAILABLE` when the key
104
+ * cannot be obtained or verified; `E_NEXUS_VAULT_UNSUPPORTED` when the server
105
+ * has no key escrow route; a mapped API error otherwise.
106
+ */
107
+ export declare function unlockNexusAccountKey(conn: NexusVaultConnection, opts?: {
108
+ readOnly?: boolean;
109
+ }): Promise<NexusAccountKey>;
110
+ /**
111
+ * The data key of a project stream: unwrap the newest wrapped key, or mint
112
+ * and store one when the project has none yet (its first push).
113
+ *
114
+ * @param conn - A vault connection.
115
+ * @param mk - The unlocked master key.
116
+ * @param projectId - The server's project id.
117
+ * @param mint - Whether a missing key may be created (push: yes; restore: no).
118
+ * @returns The project data key, or `null` when none exists and `mint` is false.
119
+ */
120
+ export declare function nexusProjectDataKey(conn: NexusVaultConnection, mk: Buffer, projectId: string, mint: boolean): Promise<Buffer | null>;
121
+ /**
122
+ * The data key of the account's `home:` stream (derived from MK, never stored).
123
+ *
124
+ * @param mk - The unlocked master key.
125
+ * @returns The home stream key.
126
+ */
127
+ export declare function nexusHomeDataKey(mk: Buffer): Buffer;
128
+ /** Re-export for callers that only need the URL resolver. */
129
+ export { resolveNexusApiUrl };
130
+ //# sourceMappingURL=nexus-vault-keys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nexus-vault-keys.d.ts","sourceRoot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AAI,EAAE,oBAAoB,EAC1B,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAiDxB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,6DAA6D;AAC7D,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
@@ -0,0 +1,347 @@
1
+ /**
2
+ * The vault's connection and keys: a read-write device connection, the
3
+ * account master key, this device's certificate, and the stream data keys.
4
+ *
5
+ * Owner decision (2026-10-01): adding a device needs only `cleo login` and
6
+ * the one-time browser approval; that approval also hands the device the
7
+ * encryption key. So the account master key (MK) is escrowed on Cleo Nexus:
8
+ *
9
+ * 1. `GET /v1/account/keys/escrow` returns MK sealed to this device's X25519
10
+ * key (`sealTo`), released only to an approved, active device. The client
11
+ * opens it with the device's private key and checks it against the
12
+ * escrow's verifier.
13
+ * 2. No escrow and no account keys: this is the account's first vault use.
14
+ * The client mints MK and escrows it (`PUT`, insert-only). A concurrent
15
+ * first device loses the insert with 409 and reads the winner's key.
16
+ * 3. The device certifies itself under MK (a self-grant, `PUT
17
+ * /v1/devices/:id/key`), so other devices can verify its snapshots.
18
+ * 4. Signer trust comes from `certifiedSigners` over `GET /v1/devices/trust`,
19
+ * with the trust state persisted in {@link NexusVaultState}.
20
+ *
21
+ * Threat model (cleo-nexus T082): the escrow `PUT` sends MK to the server
22
+ * over TLS, and the server stores it encrypted under a server-held key
23
+ * (`KEY_ESCROW_SECRET`). Snapshots are therefore encrypted at rest with keys
24
+ * Cleo Nexus can recover: this is server-escrowed encryption, not
25
+ * zero-knowledge end-to-end encryption. What the escrow does guarantee is
26
+ * that MK is released only to an approved, active device of the account,
27
+ * sealed to that device's key.
28
+ *
29
+ * A project's data key (PDK) is minted by its first pusher and stored
30
+ * wrapped by MK (`PUT /v1/projects/:id/keys/:userId`); the home stream key
31
+ * is derived from MK.
32
+ *
33
+ * No function here logs a key, and no error carries one.
34
+ *
35
+ * @task T12336
36
+ * @epic T12322
37
+ */
38
+ import { nexusProjectKeysSchema, nexusUserKeysSchema } from '@cleocode/contracts';
39
+ import { DeviceTrust as DeviceTrustSchema, KeyEscrowGrant, PutKeyEscrowResult, } from '@cleocode/contracts/cloud';
40
+ import { z } from 'zod';
41
+ import { openSealed, randomKey } from './crypto.js';
42
+ import { Http, NexusError } from './http.js';
43
+ import { certifiedSigners, createDeviceGrant, homeStreamKey, masterKeyVerifier, newProjectKey, unwrapProjectKey, wrapProjectKey, } from './keys.js';
44
+ import { NexusAccountError, resolveNexusApiUrl } from './nexus-auth.js';
45
+ import { assertNexusCloudDeviceMode, NEXUS_CLOUD_TIMEOUT_MS, nexusCredentialWarnings, } from './nexus-cloud.js';
46
+ import { ensureNexusDeviceCredential, nexusApiErrorToAccountError } from './nexus-enrol.js';
47
+ import { NexusVaultState } from './nexus-vault-state.js';
48
+ /** Timeout of a snapshot blob upload or download. */
49
+ export const NEXUS_VAULT_BLOB_TIMEOUT_MS = 10 * 60_000;
50
+ /** The sealed-box context of an escrow release (must match the server, cleo-nexus T082). */
51
+ export const escrowContext = (userId, deviceId) => `cleo-nexus/escrow/v1:${userId}:${deviceId}`;
52
+ const b64 = (s) => Buffer.from(s, 'base64');
53
+ function keyPairOf(kp) {
54
+ return { publicKey: b64(kp.publicKey), privateKey: b64(kp.privateKey) };
55
+ }
56
+ /**
57
+ * Open a read-write vault connection with this machine's device credential.
58
+ *
59
+ * @param opts - API URL, account, stores and test overrides.
60
+ * @returns The connection.
61
+ * @throws {NexusAccountError} Not signed in, device mode off, or no device keys.
62
+ */
63
+ export async function connectNexusVault(opts = {}) {
64
+ assertNexusCloudDeviceMode();
65
+ const apiUrl = resolveNexusApiUrl(opts.apiUrl);
66
+ const handle = await ensureNexusDeviceCredential({ ...opts, apiUrl });
67
+ const device = handle.device;
68
+ const bearer = device.currentBearer();
69
+ if (bearer === null) {
70
+ throw new NexusAccountError('E_NEXUS_NOT_SIGNED_IN', `not signed in to Cleo Nexus at ${apiUrl}`, 'run `cleo login nexus`');
71
+ }
72
+ const entryKeys = device.unseal().keys;
73
+ if (entryKeys === null) {
74
+ throw new NexusAccountError('E_NEXUS_VAULT_KEY_UNAVAILABLE', 'this device has no key pair (it was enrolled before device keys existed)', 'run `cleo logout nexus --revoke` and then `cleo login nexus` to enrol it again');
75
+ }
76
+ const base = opts.fetch ?? ((input, init) => globalThis.fetch(input, init));
77
+ const timeoutMs = opts.timeoutMs ?? NEXUS_CLOUD_TIMEOUT_MS;
78
+ const blobTimeoutMs = opts.blobTimeoutMs ?? NEXUS_VAULT_BLOB_TIMEOUT_MS;
79
+ const http = new Http({
80
+ baseUrl: apiUrl,
81
+ token: bearer,
82
+ deviceId: device.deviceId,
83
+ fetch: (input, init) => base(input, { ...init, signal: AbortSignal.timeout(timeoutMs) }),
84
+ maxAttempts: 2,
85
+ });
86
+ const raw = (method, path, schema, body) => http.request(method, path, schema, body);
87
+ return {
88
+ apiUrl,
89
+ userId: device.userId,
90
+ deviceId: device.deviceId,
91
+ device,
92
+ keys: { encryption: keyPairOf(entryKeys.encryption), signing: keyPairOf(entryKeys.signing) },
93
+ http,
94
+ blobFetch: (input, init) => base(input, { ...init, signal: AbortSignal.timeout(blobTimeoutMs) }),
95
+ state: opts.vaultState ?? new NexusVaultState(),
96
+ warnings: nexusCredentialWarnings(handle.warnings),
97
+ raw,
98
+ async call(method, path, schema, body) {
99
+ try {
100
+ return await raw(method, path, schema, body);
101
+ }
102
+ catch (err) {
103
+ throw nexusApiErrorToAccountError(err);
104
+ }
105
+ },
106
+ async find(path, schema) {
107
+ try {
108
+ return await raw('GET', path, schema);
109
+ }
110
+ catch (err) {
111
+ if (err instanceof NexusError && err.status === 404)
112
+ return null;
113
+ throw nexusApiErrorToAccountError(err);
114
+ }
115
+ },
116
+ };
117
+ }
118
+ const isConflict = (err, reason) => err instanceof NexusError &&
119
+ err.status === 409 &&
120
+ (reason === undefined || err.details?.['reason'] === reason);
121
+ function keyUnavailable(message, fix) {
122
+ return new NexusAccountError('E_NEXUS_VAULT_KEY_UNAVAILABLE', message, fix);
123
+ }
124
+ /**
125
+ * The server answered 404 because it has no such route, not because the resource is missing: its
126
+ * fallback handler says `E_NOT_FOUND` "route not found" (cleo-nexus app.notFound), while a missing
127
+ * escrow is "key escrow not found" (T13049).
128
+ */
129
+ function isRouteMissing(err) {
130
+ return (err instanceof NexusError &&
131
+ err.status === 404 &&
132
+ err.code === 'E_NOT_FOUND' &&
133
+ err.serverMessage === 'route not found');
134
+ }
135
+ /** A Cleo Nexus server older than account key escrow (cleo-nexus T082) cannot hold a vault (T13049). */
136
+ function vaultUnsupported() {
137
+ return new NexusAccountError('E_NEXUS_VAULT_UNSUPPORTED', 'this Cleo Nexus server does not support the cloud vault yet: it has no account key escrow', 'upgrade the Cleo Nexus server (account key escrow, cleo-nexus T082), or point CLEO at one that has it; nothing was written');
138
+ }
139
+ async function openEscrow(conn) {
140
+ let grant;
141
+ try {
142
+ grant = await conn.raw('GET', '/v1/account/keys/escrow', KeyEscrowGrant);
143
+ }
144
+ catch (err) {
145
+ if (isRouteMissing(err))
146
+ throw vaultUnsupported();
147
+ // A supporting server with nothing escrowed yet: the account has no vault key. Only the
148
+ // server's own E_NOT_FOUND counts; a 404 page from something else (a proxy, a wrong
149
+ // --api-url) is a failed request, never an empty vault.
150
+ if (err instanceof NexusError && err.status === 404 && err.code === 'E_NOT_FOUND')
151
+ return null;
152
+ throw nexusApiErrorToAccountError(err);
153
+ }
154
+ if (grant.deviceId !== conn.deviceId) {
155
+ throw keyUnavailable('the server released the account key to another device id');
156
+ }
157
+ let mk;
158
+ try {
159
+ mk = openSealed(conn.keys.encryption, b64(grant.sealedMasterKey), escrowContext(conn.userId, conn.deviceId));
160
+ }
161
+ catch {
162
+ throw keyUnavailable('the escrowed account key does not open with this device key', 'run `cleo logout nexus --revoke` and `cleo login nexus` to enrol this machine again');
163
+ }
164
+ if (mk.length !== 32 || masterKeyVerifier(mk) !== grant.masterKeyVerifier) {
165
+ throw keyUnavailable('the escrowed account key does not match its verifier');
166
+ }
167
+ return { mk, kv: grant.keyVersion };
168
+ }
169
+ async function mintEscrow(conn) {
170
+ const existing = await conn.find('/v1/account/keys', nexusUserKeysSchema);
171
+ if (existing !== null) {
172
+ throw keyUnavailable('this account has an encryption key that is not escrowed, so it cannot be handed to this device', 'run `cleo cloud push` once on a device that already holds the key, so it escrows it');
173
+ }
174
+ const mk = randomKey();
175
+ try {
176
+ await conn.raw('PUT', '/v1/account/keys/escrow', PutKeyEscrowResult, {
177
+ masterKey: mk.toString('base64url'),
178
+ keyVersion: 1,
179
+ masterKeyVerifier: masterKeyVerifier(mk),
180
+ });
181
+ return { mk, kv: 1 };
182
+ }
183
+ catch (err) {
184
+ // Backstop: unreachable while GET and PUT escrow ship together (cleo-nexus #24), since
185
+ // openEscrow already refused; kept for a server that exposes one without the other.
186
+ if (isRouteMissing(err))
187
+ throw vaultUnsupported();
188
+ if (!isConflict(err))
189
+ throw nexusApiErrorToAccountError(err);
190
+ // Another device escrowed first: use its key.
191
+ const won = await openEscrow(conn);
192
+ if (won === null)
193
+ throw keyUnavailable('the account key was escrowed concurrently but is not readable');
194
+ return won;
195
+ }
196
+ }
197
+ async function ensureCertified(conn, mk, kv) {
198
+ const trust = await conn.call('GET', '/v1/devices/trust', DeviceTrustSchema);
199
+ const mine = conn.keys.signing.publicKey.toString('base64');
200
+ const certified = trust.certificates.some((c) => c.deviceId === conn.deviceId && c.keyVersion === kv && c.signingPublicKey === mine && c.live);
201
+ if (certified)
202
+ return trust;
203
+ const grant = createDeviceGrant({
204
+ masterKey: mk,
205
+ userId: conn.userId,
206
+ keyVersion: kv,
207
+ recipient: {
208
+ deviceId: conn.deviceId,
209
+ encryptionPublicKey: conn.keys.encryption.publicKey,
210
+ signingPublicKey: conn.keys.signing.publicKey,
211
+ },
212
+ signer: { deviceId: conn.deviceId, signing: conn.keys.signing },
213
+ });
214
+ await conn.call('PUT', `/v1/devices/${encodeURIComponent(conn.deviceId)}/key`, z.looseObject({}), grant);
215
+ return conn.call('GET', '/v1/devices/trust', DeviceTrustSchema);
216
+ }
217
+ /**
218
+ * Get the account master key for this device, minting and escrowing it on
219
+ * the account's first vault use, and certify this device under it.
220
+ *
221
+ * @param conn - A vault connection.
222
+ * @param opts - `readOnly`: never mint, escrow or certify (GET only); a missing escrow is
223
+ * `E_NEXUS_VAULT_EMPTY`.
224
+ * @returns The key, its version and the trusted signers.
225
+ * @throws {NexusAccountError} `E_NEXUS_VAULT_KEY_UNAVAILABLE` when the key
226
+ * cannot be obtained or verified; `E_NEXUS_VAULT_UNSUPPORTED` when the server
227
+ * has no key escrow route; a mapped API error otherwise.
228
+ */
229
+ export async function unlockNexusAccountKey(conn, opts = {}) {
230
+ const escrowed = await openEscrow(conn);
231
+ if (escrowed === null && opts.readOnly === true) {
232
+ // Nothing was ever pushed from any device: a read has nothing to read, and
233
+ // must not mint the account key as a side effect.
234
+ throw new NexusAccountError('E_NEXUS_VAULT_EMPTY', 'the cloud vault is empty: no device has pushed a snapshot to this account yet', 'run `cleo cloud push` on a device that has the data');
235
+ }
236
+ const unlocked = escrowed ?? (await mintEscrow(conn));
237
+ const trust = opts.readOnly === true
238
+ ? await conn.call('GET', '/v1/devices/trust', DeviceTrustSchema)
239
+ : await ensureCertified(conn, unlocked.mk, unlocked.kv);
240
+ // Read, evaluate and persist the trust state under one lock, so two
241
+ // concurrent commands cannot interleave and lose a narrowed pin.
242
+ const evaluation = conn.state.updateTrust(conn.apiUrl, conn.userId, (current) => {
243
+ const e = certifiedSigners(new Map([[unlocked.kv, unlocked.mk]]), conn.userId, trust, current, unlocked.kv);
244
+ return { trust: e.keyRotated || e.serverError ? current : e.state, result: e };
245
+ });
246
+ if (evaluation.keyRotated || evaluation.serverError) {
247
+ throw keyUnavailable(evaluation.keyRotated
248
+ ? 'the account key was rotated and this device does not hold the new one'
249
+ : 'the server declared an account key version no rotation explains');
250
+ }
251
+ return { masterKey: unlocked.mk, keyVersion: unlocked.kv, signers: evaluation.signers };
252
+ }
253
+ /**
254
+ * Why Cleo Nexus refused this device's first key for a project (403), as an
255
+ * account error with a remedy, or `null` for any other failure. A device may
256
+ * create only version 1, of a keyless project its own user registered
257
+ * (cleo-nexus #33); this function is reached only when this account holds no
258
+ * key for the project (T13098).
259
+ */
260
+ function refusedFirstKey(err, projectId) {
261
+ if (!(err instanceof NexusError) || err.status !== 403)
262
+ return null;
263
+ switch (err.details?.['reason']) {
264
+ case 'not-registrant':
265
+ return keyUnavailable(`project ${projectId} has no key yet, and only a device of the account that registered it may create the first one`, 'run the first `cleo cloud push` from a device of the account that first ran `cleo project link` for this project');
266
+ case 'session-required':
267
+ return keyUnavailable(`project ${projectId} already has a key, but it has not been shared with this account`, 'ask the project owner to share the project key with this account');
268
+ case 'project-role':
269
+ // Checked before the server knows whether the project has a key, so an owner may already
270
+ // have created one and not shared it with this account.
271
+ return keyUnavailable(`this account holds no key for project ${projectId}, and only a project owner can create one`, 'ask a project owner to share the project key with this account, or, if the project has no key yet, to run the first `cleo cloud push`');
272
+ default:
273
+ return null;
274
+ }
275
+ }
276
+ /**
277
+ * The data key of a project stream: unwrap the newest wrapped key, or mint
278
+ * and store one when the project has none yet (its first push).
279
+ *
280
+ * @param conn - A vault connection.
281
+ * @param mk - The unlocked master key.
282
+ * @param projectId - The server's project id.
283
+ * @param mint - Whether a missing key may be created (push: yes; restore: no).
284
+ * @returns The project data key, or `null` when none exists and `mint` is false.
285
+ */
286
+ export async function nexusProjectDataKey(conn, mk, projectId, mint) {
287
+ const path = `/v1/projects/${encodeURIComponent(projectId)}/keys`;
288
+ const read = async () => {
289
+ const list = await conn.find(path, nexusProjectKeysSchema);
290
+ const newest = list?.keys[0];
291
+ if (!newest)
292
+ return null;
293
+ try {
294
+ return unwrapProjectKey(mk, newest.wrappedProjectKey, projectId, newest.keyVersion);
295
+ }
296
+ catch {
297
+ throw keyUnavailable(`the project key of ${projectId} does not open with this account's key`);
298
+ }
299
+ };
300
+ const have = await read();
301
+ if (have !== null || !mint)
302
+ return have;
303
+ const pdk = newProjectKey();
304
+ try {
305
+ await conn.raw('PUT', `${path}/${encodeURIComponent(conn.userId)}`, z.looseObject({}), {
306
+ wrappedProjectKey: wrapProjectKey(mk, pdk, projectId, 1),
307
+ keyVersion: 1,
308
+ // Cleo Nexus accepts a new key version, the first one included, only as a rotation naming
309
+ // the current highest version (cleo-nexus T12856). The two fields stay out of the shared
310
+ // contract until cleo-nexus adds them there too (T064), as the server does.
311
+ rotate: true,
312
+ expectedMax: 0,
313
+ });
314
+ return pdk;
315
+ }
316
+ catch (err) {
317
+ const refused = refusedFirstKey(err, projectId);
318
+ if (refused)
319
+ throw refused;
320
+ if (isConflict(err, 'rotation-stale') || isConflict(err, 'keys-exist')) {
321
+ // Another device created version 1 first: use its key (T13098).
322
+ const won = await read();
323
+ if (won === null) {
324
+ throw keyUnavailable(`the project key of ${projectId} was created by another account and has not been shared with this one`, 'ask the project owner to share the project with this account');
325
+ }
326
+ return won;
327
+ }
328
+ if (isConflict(err)) {
329
+ const e = err;
330
+ const reason = typeof e.details?.['reason'] === 'string' ? ` (${e.details['reason']})` : '';
331
+ throw keyUnavailable(`Cleo Nexus refused to store the project key of ${projectId}${reason}: ${e.serverMessage}`);
332
+ }
333
+ throw nexusApiErrorToAccountError(err);
334
+ }
335
+ }
336
+ /**
337
+ * The data key of the account's `home:` stream (derived from MK, never stored).
338
+ *
339
+ * @param mk - The unlocked master key.
340
+ * @returns The home stream key.
341
+ */
342
+ export function nexusHomeDataKey(mk) {
343
+ return homeStreamKey(mk);
344
+ }
345
+ /** Re-export for callers that only need the URL resolver. */
346
+ export { resolveNexusApiUrl };
347
+ //# sourceMappingURL=nexus-vault-keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nexus-vault-keys.js","sourceRoot":"","sources":["../../src/cloud/nexus-vault-keys.ts"],"names":[],"mappings":"AAAA;;;;;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