harnery 0.33.0 → 0.34.1

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 (657) hide show
  1. package/dist/commander.d.ts.map +1 -1
  2. package/dist/commander.js +4 -0
  3. package/dist/commands/adapter.js +2 -2
  4. package/dist/commands/agents.d.ts +144 -1
  5. package/dist/commands/agents.d.ts.map +1 -1
  6. package/dist/commands/agents.js +1237 -590
  7. package/dist/commands/artifacts.d.ts.map +1 -1
  8. package/dist/commands/artifacts.js +7 -6
  9. package/dist/commands/backup.d.ts +1 -1
  10. package/dist/commands/backup.d.ts.map +1 -1
  11. package/dist/commands/backup.js +29 -16
  12. package/dist/commands/browse.d.ts.map +1 -1
  13. package/dist/commands/browse.js +234 -12
  14. package/dist/commands/checkpoint.d.ts.map +1 -1
  15. package/dist/commands/checkpoint.js +3 -2
  16. package/dist/commands/claude-desktop.d.ts +1 -1
  17. package/dist/commands/claude-desktop.d.ts.map +1 -1
  18. package/dist/commands/claude-desktop.js +3 -74
  19. package/dist/commands/context.js +1 -6
  20. package/dist/commands/decision.d.ts.map +1 -1
  21. package/dist/commands/decision.js +22 -38
  22. package/dist/commands/docs.d.ts.map +1 -1
  23. package/dist/commands/docs.js +91 -28
  24. package/dist/commands/doctor.js +10 -1
  25. package/dist/commands/events.d.ts +5 -0
  26. package/dist/commands/events.d.ts.map +1 -0
  27. package/dist/commands/events.js +189 -0
  28. package/dist/commands/governor.d.ts.map +1 -1
  29. package/dist/commands/governor.js +13 -4
  30. package/dist/commands/init.d.ts +9 -2
  31. package/dist/commands/init.d.ts.map +1 -1
  32. package/dist/commands/init.js +223 -51
  33. package/dist/commands/journal.d.ts.map +1 -1
  34. package/dist/commands/journal.js +4 -13
  35. package/dist/commands/ledger-v3.d.ts +5 -0
  36. package/dist/commands/ledger-v3.d.ts.map +1 -0
  37. package/dist/commands/ledger-v3.js +91 -0
  38. package/dist/commands/presence.d.ts.map +1 -1
  39. package/dist/commands/presence.js +11 -5
  40. package/dist/commands/sync.d.ts +1 -1
  41. package/dist/commands/sync.js +1 -1
  42. package/dist/commands/web.d.ts +6 -0
  43. package/dist/commands/web.d.ts.map +1 -1
  44. package/dist/commands/web.js +67 -7
  45. package/dist/commands/work.d.ts.map +1 -1
  46. package/dist/commands/work.js +22 -5
  47. package/dist/core/adapter.d.ts +5 -0
  48. package/dist/core/adapter.d.ts.map +1 -0
  49. package/dist/core/adapter.js +1 -0
  50. package/dist/core/adapters/attest.d.ts +5 -2
  51. package/dist/core/adapters/attest.d.ts.map +1 -1
  52. package/dist/core/adapters/attest.js +8 -3
  53. package/dist/core/adapters/profiles.d.ts +6 -6
  54. package/dist/core/adapters/profiles.d.ts.map +1 -1
  55. package/dist/core/adapters/profiles.js +4 -4
  56. package/dist/core/agents/canonical-emit.d.ts +17 -15
  57. package/dist/core/agents/canonical-emit.d.ts.map +1 -1
  58. package/dist/core/agents/canonical-emit.js +22 -22
  59. package/dist/core/agents/cli.js +207 -234
  60. package/dist/core/agents/codex-archive-v3.d.ts +14 -0
  61. package/dist/core/agents/codex-archive-v3.d.ts.map +1 -0
  62. package/dist/core/agents/codex-archive-v3.js +110 -0
  63. package/dist/core/agents/coord-client.d.ts +19 -81
  64. package/dist/core/agents/coord-client.d.ts.map +1 -1
  65. package/dist/core/agents/coord-client.js +65 -155
  66. package/dist/core/agents/finalization.d.ts +4 -1
  67. package/dist/core/agents/finalization.d.ts.map +1 -1
  68. package/dist/core/agents/finalization.js +89 -32
  69. package/dist/core/agents/index.d.ts +4 -5
  70. package/dist/core/agents/index.d.ts.map +1 -1
  71. package/dist/core/agents/index.js +4 -5
  72. package/dist/core/agents/live-authority-v3.d.ts +59 -0
  73. package/dist/core/agents/live-authority-v3.d.ts.map +1 -0
  74. package/dist/core/agents/live-authority-v3.js +233 -0
  75. package/dist/core/agents/live-lifecycle-v3.d.ts +20 -0
  76. package/dist/core/agents/live-lifecycle-v3.d.ts.map +1 -0
  77. package/dist/core/agents/live-lifecycle-v3.js +91 -0
  78. package/dist/core/agents/live-observation-v3.d.ts +25 -0
  79. package/dist/core/agents/live-observation-v3.d.ts.map +1 -0
  80. package/dist/core/agents/live-observation-v3.js +157 -0
  81. package/dist/core/agents/render/prompt-context.d.ts +4 -4
  82. package/dist/core/agents/render/prompt-context.d.ts.map +1 -1
  83. package/dist/core/agents/render/prompt-context.js +23 -58
  84. package/dist/core/agents/render/session-context.d.ts +1 -1
  85. package/dist/core/agents/render/session-context.d.ts.map +1 -1
  86. package/dist/core/agents/render/session-context.js +8 -32
  87. package/dist/core/agents/rules/claim-conflict.d.ts +3 -3
  88. package/dist/core/agents/rules/claim-conflict.d.ts.map +1 -1
  89. package/dist/core/agents/rules/claim-conflict.js +79 -127
  90. package/dist/core/agents/rules/commit-conflict.d.ts.map +1 -1
  91. package/dist/core/agents/rules/commit-conflict.js +3 -18
  92. package/dist/core/agents/rules/stop-hook.d.ts +9 -50
  93. package/dist/core/agents/rules/stop-hook.d.ts.map +1 -1
  94. package/dist/core/agents/rules/stop-hook.js +193 -236
  95. package/dist/core/agents/session-events.d.ts +5 -7
  96. package/dist/core/agents/session-events.d.ts.map +1 -1
  97. package/dist/core/agents/session-events.js +127 -95
  98. package/dist/core/agents/session-finalization-state-v3.d.ts +30 -0
  99. package/dist/core/agents/session-finalization-state-v3.d.ts.map +1 -0
  100. package/dist/core/agents/session-finalization-state-v3.js +40 -0
  101. package/dist/core/agents/session-finalizer-v3.d.ts +107 -0
  102. package/dist/core/agents/session-finalizer-v3.d.ts.map +1 -0
  103. package/dist/core/agents/session-finalizer-v3.js +734 -0
  104. package/dist/core/agents/session-name-display.d.ts +40 -0
  105. package/dist/core/agents/session-name-display.d.ts.map +1 -0
  106. package/dist/core/agents/session-name-display.js +119 -0
  107. package/dist/core/agents/state/activity-log.d.ts +3 -3
  108. package/dist/core/agents/state/activity-log.d.ts.map +1 -1
  109. package/dist/core/agents/state/activity-log.js +7 -16
  110. package/dist/core/agents/state/heartbeat-writer.d.ts +23 -55
  111. package/dist/core/agents/state/heartbeat-writer.d.ts.map +1 -1
  112. package/dist/core/agents/state/heartbeat-writer.js +56 -228
  113. package/dist/core/agents/state/live-coordination-view.d.ts +31 -0
  114. package/dist/core/agents/state/live-coordination-view.d.ts.map +1 -0
  115. package/dist/core/agents/state/live-coordination-view.js +209 -0
  116. package/dist/core/agents/state/session-state.d.ts +4 -3
  117. package/dist/core/agents/state/session-state.d.ts.map +1 -1
  118. package/dist/core/agents/state/session-state.js +18 -9
  119. package/dist/core/agents/state/stale-sweep.d.ts +1 -1
  120. package/dist/core/agents/state/stale-sweep.d.ts.map +1 -1
  121. package/dist/core/agents/state/stale-sweep.js +26 -15
  122. package/dist/core/artifacts/index.d.ts.map +1 -1
  123. package/dist/core/artifacts/index.js +5 -7
  124. package/dist/core/config.d.ts +33 -2
  125. package/dist/core/config.d.ts.map +1 -1
  126. package/dist/core/config.js +98 -2
  127. package/dist/core/context/index.d.ts +1 -4
  128. package/dist/core/context/index.d.ts.map +1 -1
  129. package/dist/core/context/index.js +9 -9
  130. package/dist/core/events/span-parent.d.ts +15 -0
  131. package/dist/core/events/span-parent.d.ts.map +1 -0
  132. package/dist/core/events/span-parent.js +34 -0
  133. package/dist/core/events/v3/advance.d.ts +14 -0
  134. package/dist/core/events/v3/advance.d.ts.map +1 -0
  135. package/dist/core/events/v3/advance.js +134 -0
  136. package/dist/core/events/v3/authority-outbox.d.ts +78 -0
  137. package/dist/core/events/v3/authority-outbox.d.ts.map +1 -0
  138. package/dist/core/events/v3/authority-outbox.js +399 -0
  139. package/dist/core/events/v3/base-builder.d.ts +20 -0
  140. package/dist/core/events/v3/base-builder.d.ts.map +1 -0
  141. package/dist/core/events/v3/base-builder.js +29 -0
  142. package/dist/core/events/v3/base-contract.d.ts +7576 -0
  143. package/dist/core/events/v3/base-contract.d.ts.map +1 -0
  144. package/dist/core/events/v3/base-contract.js +647 -0
  145. package/dist/core/events/v3/bootstrap.d.ts +34 -0
  146. package/dist/core/events/v3/bootstrap.d.ts.map +1 -0
  147. package/dist/core/events/v3/bootstrap.js +175 -0
  148. package/dist/core/events/v3/builder.d.ts +20 -0
  149. package/dist/core/events/v3/builder.d.ts.map +1 -0
  150. package/dist/core/events/v3/builder.js +28 -0
  151. package/dist/core/events/v3/canonical.d.ts +31 -0
  152. package/dist/core/events/v3/canonical.d.ts.map +1 -0
  153. package/dist/core/events/v3/canonical.js +100 -0
  154. package/dist/core/events/v3/capabilities.d.ts +31 -0
  155. package/dist/core/events/v3/capabilities.d.ts.map +1 -0
  156. package/dist/core/events/v3/capabilities.js +107 -0
  157. package/dist/core/events/v3/capability-drift.d.ts +22 -0
  158. package/dist/core/events/v3/capability-drift.d.ts.map +1 -0
  159. package/dist/core/events/v3/capability-drift.js +134 -0
  160. package/dist/core/events/v3/catalog.d.ts +38 -0
  161. package/dist/core/events/v3/catalog.d.ts.map +1 -0
  162. package/dist/core/events/v3/catalog.js +135 -0
  163. package/dist/core/events/v3/clock-order.d.ts +34 -0
  164. package/dist/core/events/v3/clock-order.d.ts.map +1 -0
  165. package/dist/core/events/v3/clock-order.js +35 -0
  166. package/dist/core/events/v3/contract.d.ts +171 -0
  167. package/dist/core/events/v3/contract.d.ts.map +1 -0
  168. package/dist/core/events/v3/contract.js +180 -0
  169. package/dist/core/events/v3/control.d.ts +111 -0
  170. package/dist/core/events/v3/control.d.ts.map +1 -0
  171. package/dist/core/events/v3/control.js +419 -0
  172. package/dist/core/events/v3/coordination-view.d.ts +69 -0
  173. package/dist/core/events/v3/coordination-view.d.ts.map +1 -0
  174. package/dist/core/events/v3/coordination-view.js +119 -0
  175. package/dist/core/events/v3/economics.d.ts +77 -0
  176. package/dist/core/events/v3/economics.d.ts.map +1 -0
  177. package/dist/core/events/v3/economics.js +274 -0
  178. package/dist/core/events/v3/finalization-view.d.ts +26 -0
  179. package/dist/core/events/v3/finalization-view.d.ts.map +1 -0
  180. package/dist/core/events/v3/finalization-view.js +37 -0
  181. package/dist/core/events/v3/fingerprint-keys.d.ts +25 -0
  182. package/dist/core/events/v3/fingerprint-keys.d.ts.map +1 -0
  183. package/dist/core/events/v3/fingerprint-keys.js +217 -0
  184. package/dist/core/events/v3/generated.d.ts +4 -0
  185. package/dist/core/events/v3/generated.d.ts.map +1 -0
  186. package/dist/core/events/v3/generated.js +47 -0
  187. package/dist/core/events/v3/ids.d.ts +9 -0
  188. package/dist/core/events/v3/ids.d.ts.map +1 -0
  189. package/dist/core/events/v3/ids.js +25 -0
  190. package/dist/core/events/v3/index.d.ts +35 -0
  191. package/dist/core/events/v3/index.d.ts.map +1 -0
  192. package/dist/core/events/v3/index.js +33 -0
  193. package/dist/core/events/v3/latency.d.ts +63 -0
  194. package/dist/core/events/v3/latency.d.ts.map +1 -0
  195. package/dist/core/events/v3/latency.js +412 -0
  196. package/dist/core/events/v3/live-feed.d.ts +45 -0
  197. package/dist/core/events/v3/live-feed.d.ts.map +1 -0
  198. package/dist/core/events/v3/live-feed.js +246 -0
  199. package/dist/core/events/v3/live-observation.d.ts +35 -0
  200. package/dist/core/events/v3/live-observation.d.ts.map +1 -0
  201. package/dist/core/events/v3/live-observation.js +1 -0
  202. package/dist/core/events/v3/live-routing.d.ts +57 -0
  203. package/dist/core/events/v3/live-routing.d.ts.map +1 -0
  204. package/dist/core/events/v3/live-routing.js +107 -0
  205. package/dist/core/events/v3/producers/command-recorder.d.ts +67 -0
  206. package/dist/core/events/v3/producers/command-recorder.d.ts.map +1 -0
  207. package/dist/core/events/v3/producers/command-recorder.js +477 -0
  208. package/dist/core/events/v3/producers/command.d.ts +50 -0
  209. package/dist/core/events/v3/producers/command.d.ts.map +1 -0
  210. package/dist/core/events/v3/producers/command.js +135 -0
  211. package/dist/core/events/v3/producers/coordination-recorder.d.ts +53 -0
  212. package/dist/core/events/v3/producers/coordination-recorder.d.ts.map +1 -0
  213. package/dist/core/events/v3/producers/coordination-recorder.js +376 -0
  214. package/dist/core/events/v3/producers/coordination.d.ts +90 -0
  215. package/dist/core/events/v3/producers/coordination.d.ts.map +1 -0
  216. package/dist/core/events/v3/producers/coordination.js +229 -0
  217. package/dist/core/events/v3/producers/hook-base.d.ts +54 -0
  218. package/dist/core/events/v3/producers/hook-base.d.ts.map +1 -0
  219. package/dist/core/events/v3/producers/hook-base.js +424 -0
  220. package/dist/core/events/v3/producers/hook.d.ts +29 -0
  221. package/dist/core/events/v3/producers/hook.d.ts.map +1 -0
  222. package/dist/core/events/v3/producers/hook.js +71 -0
  223. package/dist/core/events/v3/producers/intake.d.ts +65 -0
  224. package/dist/core/events/v3/producers/intake.d.ts.map +1 -0
  225. package/dist/core/events/v3/producers/intake.js +244 -0
  226. package/dist/core/events/v3/producers/recorder.d.ts +240 -0
  227. package/dist/core/events/v3/producers/recorder.d.ts.map +1 -0
  228. package/dist/core/events/v3/producers/recorder.js +2176 -0
  229. package/dist/core/events/v3/projection.d.ts +101 -0
  230. package/dist/core/events/v3/projection.d.ts.map +1 -0
  231. package/dist/core/events/v3/projection.js +479 -0
  232. package/dist/core/events/v3/reader.d.ts +75 -0
  233. package/dist/core/events/v3/reader.d.ts.map +1 -0
  234. package/dist/core/events/v3/reader.js +778 -0
  235. package/dist/core/events/v3/recovery-record.d.ts +47 -0
  236. package/dist/core/events/v3/recovery-record.d.ts.map +1 -0
  237. package/dist/core/events/v3/recovery-record.js +167 -0
  238. package/dist/core/events/v3/recovery.d.ts +22 -0
  239. package/dist/core/events/v3/recovery.d.ts.map +1 -0
  240. package/dist/core/events/v3/recovery.js +227 -0
  241. package/dist/core/events/v3/span-state.d.ts +52 -0
  242. package/dist/core/events/v3/span-state.d.ts.map +1 -0
  243. package/dist/core/events/v3/span-state.js +142 -0
  244. package/dist/core/events/v3/targets.d.ts +23 -0
  245. package/dist/core/events/v3/targets.d.ts.map +1 -0
  246. package/dist/core/events/v3/targets.js +134 -0
  247. package/dist/core/events/v3/turn-telemetry.d.ts +41 -0
  248. package/dist/core/events/v3/turn-telemetry.d.ts.map +1 -0
  249. package/dist/core/events/v3/turn-telemetry.js +168 -0
  250. package/dist/core/events/v3/validate.d.ts +9 -0
  251. package/dist/core/events/v3/validate.d.ts.map +1 -0
  252. package/dist/core/events/v3/validate.js +281 -0
  253. package/dist/core/events/v3/writer.d.ts +56 -0
  254. package/dist/core/events/v3/writer.d.ts.map +1 -0
  255. package/dist/core/events/v3/writer.js +335 -0
  256. package/dist/core/governor/index.d.ts +1 -1
  257. package/dist/core/governor/index.d.ts.map +1 -1
  258. package/dist/core/governor/index.js +1 -1
  259. package/dist/core/governor/plan-api.d.ts +2 -1
  260. package/dist/core/governor/plan-api.d.ts.map +1 -1
  261. package/dist/core/governor/plan-api.js +6 -3
  262. package/dist/core/governor/read.d.ts +1 -1
  263. package/dist/core/governor/read.d.ts.map +1 -1
  264. package/dist/core/governor/read.js +1 -1
  265. package/dist/core/governor/state.d.ts +9 -0
  266. package/dist/core/governor/state.d.ts.map +1 -1
  267. package/dist/core/governor/state.js +40 -3
  268. package/dist/core/guard/config.d.ts +5 -0
  269. package/dist/core/guard/config.d.ts.map +1 -0
  270. package/dist/core/guard/config.js +157 -0
  271. package/dist/core/guard/coordinator.d.ts +14 -0
  272. package/dist/core/guard/coordinator.d.ts.map +1 -0
  273. package/dist/core/guard/coordinator.js +173 -0
  274. package/dist/core/guard/evaluator.d.ts +4 -0
  275. package/dist/core/guard/evaluator.d.ts.map +1 -0
  276. package/dist/core/guard/evaluator.js +242 -0
  277. package/dist/core/guard/evidence-v3.d.ts +15 -0
  278. package/dist/core/guard/evidence-v3.d.ts.map +1 -0
  279. package/dist/core/guard/evidence-v3.js +171 -0
  280. package/dist/core/guard/index.d.ts +10 -0
  281. package/dist/core/guard/index.d.ts.map +1 -0
  282. package/dist/core/guard/index.js +6 -0
  283. package/dist/core/guard/live-source-v3.d.ts +40 -0
  284. package/dist/core/guard/live-source-v3.d.ts.map +1 -0
  285. package/dist/core/guard/live-source-v3.js +128 -0
  286. package/dist/core/guard/storage.d.ts +27 -0
  287. package/dist/core/guard/storage.d.ts.map +1 -0
  288. package/dist/core/guard/storage.js +140 -0
  289. package/dist/core/guard/types.d.ts +119 -0
  290. package/dist/core/guard/types.d.ts.map +1 -0
  291. package/dist/core/guard/types.js +1 -0
  292. package/dist/core/hooks/adapter/detect.d.ts +18 -1
  293. package/dist/core/hooks/adapter/detect.d.ts.map +1 -1
  294. package/dist/core/hooks/adapter/detect.js +29 -0
  295. package/dist/core/hooks/adapter/events.d.ts +7 -4
  296. package/dist/core/hooks/adapter/events.d.ts.map +1 -1
  297. package/dist/core/hooks/adapter/events.js +12 -4
  298. package/dist/core/hooks/adapter/output.d.ts +2 -2
  299. package/dist/core/hooks/adapter/output.d.ts.map +1 -1
  300. package/dist/core/hooks/adapter/parse.d.ts +7 -4
  301. package/dist/core/hooks/adapter/parse.d.ts.map +1 -1
  302. package/dist/core/hooks/adapter/parse.js +63 -25
  303. package/dist/core/hooks/adapter/wiring.d.ts +30 -4
  304. package/dist/core/hooks/adapter/wiring.d.ts.map +1 -1
  305. package/dist/core/hooks/adapter/wiring.js +89 -11
  306. package/dist/core/hooks/cli.d.ts +1 -1
  307. package/dist/core/hooks/cli.js +306 -444
  308. package/dist/core/hooks/effects/image-capture.d.ts +20 -34
  309. package/dist/core/hooks/effects/image-capture.d.ts.map +1 -1
  310. package/dist/core/hooks/effects/image-capture.js +212 -221
  311. package/dist/core/hooks/effects/index.d.ts +1 -9
  312. package/dist/core/hooks/effects/index.d.ts.map +1 -1
  313. package/dist/core/hooks/effects/index.js +1 -24
  314. package/dist/core/hooks/events/input-hash.d.ts +7 -0
  315. package/dist/core/hooks/events/input-hash.d.ts.map +1 -0
  316. package/dist/core/hooks/events/input-hash.js +43 -0
  317. package/dist/core/hooks/index.d.ts +4 -3
  318. package/dist/core/hooks/index.d.ts.map +1 -1
  319. package/dist/core/hooks/index.js +2 -3
  320. package/dist/core/hooks/resolve/coord-root.d.ts +1 -1
  321. package/dist/core/hooks/resolve/coord-root.js +1 -1
  322. package/dist/core/hooks/resolve/owner.d.ts +16 -15
  323. package/dist/core/hooks/resolve/owner.d.ts.map +1 -1
  324. package/dist/core/hooks/resolve/owner.js +51 -42
  325. package/dist/core/hooks/resolve/transcript.d.ts +33 -3
  326. package/dist/core/hooks/resolve/transcript.d.ts.map +1 -1
  327. package/dist/core/hooks/resolve/transcript.js +161 -14
  328. package/dist/core/hooks/session-name-presence.d.ts +9 -10
  329. package/dist/core/hooks/session-name-presence.d.ts.map +1 -1
  330. package/dist/core/hooks/session-name-presence.js +15 -15
  331. package/dist/core/hooks/unsafe-cross-shell.d.ts +1 -1
  332. package/dist/core/hooks/unsafe-cross-shell.d.ts.map +1 -1
  333. package/dist/core/journal/index.d.ts +2 -2
  334. package/dist/core/journal/index.d.ts.map +1 -1
  335. package/dist/core/journal/index.js +9 -22
  336. package/dist/core/presence/blob.d.ts +4 -3
  337. package/dist/core/presence/blob.d.ts.map +1 -1
  338. package/dist/core/presence/blob.js +45 -44
  339. package/dist/core/presence/codec-digest.d.ts +29 -0
  340. package/dist/core/presence/codec-digest.d.ts.map +1 -0
  341. package/dist/core/presence/codec-digest.js +170 -0
  342. package/dist/core/presence/relay-client.d.ts +1 -1
  343. package/dist/core/presence/relay-client.d.ts.map +1 -1
  344. package/dist/core/presence/relay-client.js +5 -5
  345. package/dist/core/work/index.d.ts +1 -1
  346. package/dist/core/work/index.d.ts.map +1 -1
  347. package/dist/core/work/index.js +1 -1
  348. package/dist/core/work/read.d.ts +1 -1
  349. package/dist/core/work/read.d.ts.map +1 -1
  350. package/dist/core/work/read.js +1 -1
  351. package/dist/core/work/runner.d.ts.map +1 -1
  352. package/dist/core/work/runner.js +6 -0
  353. package/dist/core/work/state.d.ts +9 -0
  354. package/dist/core/work/state.d.ts.map +1 -1
  355. package/dist/core/work/state.js +17 -3
  356. package/dist/core/workflow/engine.js +24 -25
  357. package/dist/core/workflow/live-session-v3.d.ts +19 -0
  358. package/dist/core/workflow/live-session-v3.d.ts.map +1 -0
  359. package/dist/core/workflow/live-session-v3.js +86 -0
  360. package/dist/core/workflow/scope-id.d.ts +3 -0
  361. package/dist/core/workflow/scope-id.d.ts.map +1 -0
  362. package/dist/core/workflow/scope-id.js +5 -0
  363. package/dist/core/workflow/workspaces/leases.d.ts +4 -0
  364. package/dist/core/workflow/workspaces/leases.d.ts.map +1 -1
  365. package/dist/core/workflow/workspaces/leases.js +53 -19
  366. package/dist/index.d.ts +1 -1
  367. package/dist/index.js +1 -1
  368. package/dist/lib/browser/client.d.ts +41 -0
  369. package/dist/lib/browser/client.d.ts.map +1 -1
  370. package/dist/lib/browser/client.js +203 -0
  371. package/dist/lib/browser/critique.d.ts +28 -2
  372. package/dist/lib/browser/critique.d.ts.map +1 -1
  373. package/dist/lib/browser/critique.js +74 -18
  374. package/dist/lib/browser/geometry.d.ts +1 -1
  375. package/dist/lib/browser/geometry.d.ts.map +1 -1
  376. package/dist/lib/browser/geometry.js +130 -6
  377. package/dist/lib/browser/index.d.ts +3 -0
  378. package/dist/lib/browser/index.d.ts.map +1 -1
  379. package/dist/lib/browser/index.js +3 -0
  380. package/dist/lib/browser/qa-plan.d.ts +174 -0
  381. package/dist/lib/browser/qa-plan.d.ts.map +1 -0
  382. package/dist/lib/browser/qa-plan.js +321 -0
  383. package/dist/lib/browser/qa-reuse.d.ts +99 -0
  384. package/dist/lib/browser/qa-reuse.d.ts.map +1 -0
  385. package/dist/lib/browser/qa-reuse.js +222 -0
  386. package/dist/lib/browser/qa-snapshot.d.ts +64 -0
  387. package/dist/lib/browser/qa-snapshot.d.ts.map +1 -0
  388. package/dist/lib/browser/qa-snapshot.js +171 -0
  389. package/dist/lib/browser/runts.d.ts.map +1 -1
  390. package/dist/lib/browser/runts.js +22 -1
  391. package/dist/lib/browser/tiling.d.ts +71 -0
  392. package/dist/lib/browser/tiling.d.ts.map +1 -0
  393. package/dist/lib/browser/tiling.js +118 -0
  394. package/dist/lib/claude-desktop.d.ts +0 -47
  395. package/dist/lib/claude-desktop.d.ts.map +1 -1
  396. package/dist/lib/claude-desktop.js +1 -169
  397. package/dist/lib/context/index.d.ts +0 -3
  398. package/dist/lib/context/index.d.ts.map +1 -1
  399. package/dist/lib/context/index.js +20 -42
  400. package/dist/lib/council/index.d.ts +2 -2
  401. package/dist/lib/council/index.d.ts.map +1 -1
  402. package/dist/lib/council/index.js +9 -20
  403. package/dist/lib/docs-frontmatter.d.ts +1 -6
  404. package/dist/lib/docs-frontmatter.d.ts.map +1 -1
  405. package/dist/lib/docs-frontmatter.js +12 -78
  406. package/dist/lib/docs-index.d.ts +9 -0
  407. package/dist/lib/docs-index.d.ts.map +1 -1
  408. package/dist/lib/docs-index.js +32 -3
  409. package/dist/lib/docs-lint.d.ts.map +1 -1
  410. package/dist/lib/docs-lint.js +14 -30
  411. package/dist/lib/docs-metadata-audit.d.ts +19 -0
  412. package/dist/lib/docs-metadata-audit.d.ts.map +1 -0
  413. package/dist/lib/docs-metadata-audit.js +132 -0
  414. package/dist/lib/docs-metadata-managed.d.ts +23 -0
  415. package/dist/lib/docs-metadata-managed.d.ts.map +1 -0
  416. package/dist/lib/docs-metadata-managed.js +78 -0
  417. package/dist/lib/docs-metadata-sync.d.ts +20 -0
  418. package/dist/lib/docs-metadata-sync.d.ts.map +1 -0
  419. package/dist/lib/docs-metadata-sync.js +222 -0
  420. package/dist/lib/docs-metadata-v2-schema.d.ts +273 -0
  421. package/dist/lib/docs-metadata-v2-schema.d.ts.map +1 -0
  422. package/dist/lib/docs-metadata-v2-schema.js +134 -0
  423. package/dist/lib/docs-metadata-v2.d.ts +21 -0
  424. package/dist/lib/docs-metadata-v2.d.ts.map +1 -0
  425. package/dist/lib/docs-metadata-v2.js +424 -0
  426. package/dist/lib/docs-new.d.ts +11 -0
  427. package/dist/lib/docs-new.d.ts.map +1 -0
  428. package/dist/lib/docs-new.js +52 -0
  429. package/dist/lib/docs-sweep.d.ts.map +1 -1
  430. package/dist/lib/docs-sweep.js +45 -29
  431. package/dist/lib/headless/index.d.ts +98 -0
  432. package/dist/lib/headless/index.d.ts.map +1 -0
  433. package/dist/lib/headless/index.js +211 -0
  434. package/dist/lib/identities/assume.d.ts +4 -4
  435. package/dist/lib/identities/assume.d.ts.map +1 -1
  436. package/dist/lib/identities/assume.js +52 -68
  437. package/dist/lib/instructions/apply.d.ts +5 -4
  438. package/dist/lib/instructions/apply.d.ts.map +1 -1
  439. package/dist/lib/instructions/apply.js +32 -20
  440. package/dist/lib/instructions/bundle.d.ts +1 -1
  441. package/dist/lib/instructions/bundle.d.ts.map +1 -1
  442. package/dist/lib/instructions/bundle.js +1 -1
  443. package/dist/lib/instructions/splice.d.ts +0 -1
  444. package/dist/lib/instructions/splice.d.ts.map +1 -1
  445. package/dist/lib/instructions/splice.js +22 -6
  446. package/dist/lib/instructions/templates.d.ts +7 -5
  447. package/dist/lib/instructions/templates.d.ts.map +1 -1
  448. package/dist/lib/instructions/templates.js +79 -9
  449. package/package.json +26 -5
  450. package/schemas/config.schema.json +120 -2
  451. package/schemas/docs-metadata-v2.schema.json +441 -0
  452. package/schemas/event-v3.schema.json +24472 -0
  453. package/src/commander.ts +4 -0
  454. package/src/commands/adapter.ts +2 -2
  455. package/src/commands/agents.ts +1530 -593
  456. package/src/commands/artifacts.ts +7 -6
  457. package/src/commands/backup.ts +29 -21
  458. package/src/commands/browse.ts +349 -8
  459. package/src/commands/checkpoint.ts +4 -3
  460. package/src/commands/claude-desktop.ts +2 -101
  461. package/src/commands/context.ts +1 -6
  462. package/src/commands/decision.ts +27 -44
  463. package/src/commands/docs.ts +100 -33
  464. package/src/commands/doctor.ts +14 -1
  465. package/src/commands/events.ts +256 -0
  466. package/src/commands/governor.ts +18 -4
  467. package/src/commands/init.ts +253 -57
  468. package/src/commands/instructions.ts +1 -1
  469. package/src/commands/journal.ts +4 -13
  470. package/src/commands/ledger-v3.ts +111 -0
  471. package/src/commands/presence.ts +11 -10
  472. package/src/commands/sync.ts +1 -1
  473. package/src/commands/web.ts +67 -8
  474. package/src/commands/work.ts +28 -5
  475. package/src/core/adapter.ts +5 -0
  476. package/src/core/adapters/attest.ts +8 -3
  477. package/src/core/adapters/profiles.ts +4 -6
  478. package/src/core/agents/canonical-emit.ts +34 -25
  479. package/src/core/agents/cli.ts +236 -262
  480. package/src/core/agents/codex-archive-v3.ts +138 -0
  481. package/src/core/agents/coord-client.ts +75 -188
  482. package/src/core/agents/finalization.ts +120 -38
  483. package/src/core/agents/index.ts +4 -5
  484. package/src/core/agents/live-authority-v3.ts +375 -0
  485. package/src/core/agents/live-lifecycle-v3.ts +140 -0
  486. package/src/core/agents/live-observation-v3.ts +216 -0
  487. package/src/core/agents/render/prompt-context.ts +29 -60
  488. package/src/core/agents/render/session-context.ts +10 -31
  489. package/src/core/agents/rules/claim-conflict.ts +85 -126
  490. package/src/core/agents/rules/commit-conflict.ts +3 -14
  491. package/src/core/agents/rules/stop-hook.ts +239 -293
  492. package/src/core/agents/session-events.ts +137 -104
  493. package/src/core/agents/session-finalization-state-v3.ts +90 -0
  494. package/src/core/agents/session-finalizer-v3.ts +953 -0
  495. package/src/core/agents/session-name-display.ts +149 -0
  496. package/src/core/agents/state/activity-log.ts +6 -14
  497. package/src/core/agents/state/heartbeat-writer.ts +82 -277
  498. package/src/core/agents/state/live-coordination-view.ts +290 -0
  499. package/src/core/agents/state/session-state.ts +24 -12
  500. package/src/core/agents/state/stale-sweep.ts +40 -17
  501. package/src/core/artifacts/index.ts +4 -5
  502. package/src/core/config.ts +148 -3
  503. package/src/core/context/index.ts +9 -17
  504. package/src/core/events/span-parent.ts +46 -0
  505. package/src/core/events/v3/advance.ts +168 -0
  506. package/src/core/events/v3/authority-outbox.ts +548 -0
  507. package/src/core/events/v3/base-builder.ts +60 -0
  508. package/src/core/events/v3/base-contract.ts +882 -0
  509. package/src/core/events/v3/bootstrap.ts +226 -0
  510. package/src/core/events/v3/builder.ts +59 -0
  511. package/src/core/events/v3/canonical.ts +153 -0
  512. package/src/core/events/v3/capabilities.ts +171 -0
  513. package/src/core/events/v3/capability-drift.ts +177 -0
  514. package/src/core/events/v3/catalog.ts +202 -0
  515. package/src/core/events/v3/clock-order.ts +41 -0
  516. package/src/core/events/v3/contract.ts +365 -0
  517. package/src/core/events/v3/control.ts +576 -0
  518. package/src/core/events/v3/coordination-view.ts +193 -0
  519. package/src/core/events/v3/economics.ts +384 -0
  520. package/src/core/events/v3/finalization-view.ts +67 -0
  521. package/src/core/events/v3/fingerprint-keys.ts +260 -0
  522. package/src/core/events/v3/generated.ts +48 -0
  523. package/src/core/events/v3/ids.ts +33 -0
  524. package/src/core/events/v3/index.ts +322 -0
  525. package/src/core/events/v3/latency.ts +551 -0
  526. package/src/core/events/v3/live-feed.ts +319 -0
  527. package/src/core/events/v3/live-observation.ts +39 -0
  528. package/src/core/events/v3/live-routing.ts +135 -0
  529. package/src/core/events/v3/producers/command-recorder.ts +631 -0
  530. package/src/core/events/v3/producers/command.ts +201 -0
  531. package/src/core/events/v3/producers/coordination-recorder.ts +538 -0
  532. package/src/core/events/v3/producers/coordination.ts +355 -0
  533. package/src/core/events/v3/producers/hook-base.ts +578 -0
  534. package/src/core/events/v3/producers/hook.ts +119 -0
  535. package/src/core/events/v3/producers/intake.ts +319 -0
  536. package/src/core/events/v3/producers/recorder.ts +2805 -0
  537. package/src/core/events/v3/projection.ts +653 -0
  538. package/src/core/events/v3/reader.ts +1127 -0
  539. package/src/core/events/v3/recovery-record.ts +244 -0
  540. package/src/core/events/v3/recovery.ts +271 -0
  541. package/src/core/events/v3/span-state.ts +187 -0
  542. package/src/core/events/v3/targets.ts +182 -0
  543. package/src/core/events/v3/turn-telemetry.ts +259 -0
  544. package/src/core/events/v3/validate.ts +361 -0
  545. package/src/core/events/v3/writer.ts +419 -0
  546. package/src/core/governor/index.ts +3 -0
  547. package/src/core/governor/plan-api.ts +10 -2
  548. package/src/core/governor/read.ts +3 -0
  549. package/src/core/governor/state.ts +52 -5
  550. package/src/core/guard/config.ts +206 -0
  551. package/src/core/guard/coordinator.ts +227 -0
  552. package/src/core/guard/evaluator.ts +343 -0
  553. package/src/core/guard/evidence-v3.ts +227 -0
  554. package/src/core/guard/index.ts +35 -0
  555. package/src/core/guard/live-source-v3.ts +204 -0
  556. package/src/core/guard/storage.ts +188 -0
  557. package/src/core/guard/types.ts +152 -0
  558. package/src/core/hooks/adapter/detect.ts +28 -1
  559. package/src/core/hooks/adapter/events.ts +14 -6
  560. package/src/core/hooks/adapter/output.ts +7 -2
  561. package/src/core/hooks/adapter/parse.ts +80 -38
  562. package/src/core/hooks/adapter/wiring.ts +119 -13
  563. package/src/core/hooks/cli.ts +352 -466
  564. package/src/core/hooks/effects/image-capture.ts +228 -238
  565. package/src/core/hooks/effects/index.ts +1 -36
  566. package/src/core/hooks/events/input-hash.ts +47 -0
  567. package/src/core/hooks/index.ts +4 -11
  568. package/src/core/hooks/resolve/coord-root.ts +1 -1
  569. package/src/core/hooks/resolve/owner.ts +52 -45
  570. package/src/core/hooks/resolve/transcript.ts +171 -14
  571. package/src/core/hooks/session-name-presence.ts +14 -15
  572. package/src/core/hooks/unsafe-cross-shell.ts +1 -1
  573. package/src/core/journal/index.ts +15 -22
  574. package/src/core/presence/blob.ts +48 -41
  575. package/src/core/presence/codec-digest.ts +215 -0
  576. package/src/core/presence/relay-client.ts +5 -5
  577. package/src/core/work/index.ts +3 -0
  578. package/src/core/work/read.ts +3 -0
  579. package/src/core/work/runner.ts +6 -0
  580. package/src/core/work/state.ts +27 -3
  581. package/src/core/workflow/engine.ts +24 -24
  582. package/src/core/workflow/live-session-v3.ts +126 -0
  583. package/src/core/workflow/scope-id.ts +6 -0
  584. package/src/core/workflow/workspaces/leases.ts +56 -19
  585. package/src/index.ts +1 -1
  586. package/src/lib/browser/client.ts +230 -0
  587. package/src/lib/browser/critique.ts +104 -27
  588. package/src/lib/browser/geometry.ts +143 -14
  589. package/src/lib/browser/index.ts +34 -0
  590. package/src/lib/browser/qa-plan.ts +501 -0
  591. package/src/lib/browser/qa-reuse.ts +306 -0
  592. package/src/lib/browser/qa-snapshot.ts +223 -0
  593. package/src/lib/browser/runts.ts +27 -2
  594. package/src/lib/browser/tiling.ts +164 -0
  595. package/src/lib/claude-desktop.ts +1 -232
  596. package/src/lib/context/index.ts +22 -46
  597. package/src/lib/council/index.ts +9 -21
  598. package/src/lib/docs-frontmatter.ts +8 -79
  599. package/src/lib/docs-index.ts +33 -3
  600. package/src/lib/docs-lint.ts +15 -29
  601. package/src/lib/docs-metadata-audit.ts +166 -0
  602. package/src/lib/docs-metadata-managed.ts +83 -0
  603. package/src/lib/docs-metadata-sync.ts +262 -0
  604. package/src/lib/docs-metadata-v2-schema.ts +138 -0
  605. package/src/lib/docs-metadata-v2.ts +646 -0
  606. package/src/lib/docs-new.ts +63 -0
  607. package/src/lib/docs-sweep.ts +42 -28
  608. package/src/lib/headless/index.ts +287 -0
  609. package/src/lib/identities/assume.ts +67 -86
  610. package/src/lib/instructions/apply.ts +33 -20
  611. package/src/lib/instructions/bundle.ts +2 -2
  612. package/src/lib/instructions/splice.ts +21 -7
  613. package/src/lib/instructions/templates.ts +85 -13
  614. package/dist/core/agents/cli-emit.d.ts +0 -27
  615. package/dist/core/agents/cli-emit.d.ts.map +0 -1
  616. package/dist/core/agents/cli-emit.js +0 -57
  617. package/dist/core/agents/codex-replay.d.ts +0 -29
  618. package/dist/core/agents/codex-replay.d.ts.map +0 -1
  619. package/dist/core/agents/codex-replay.js +0 -138
  620. package/dist/core/agents/events/consume.d.ts +0 -82
  621. package/dist/core/agents/events/consume.d.ts.map +0 -1
  622. package/dist/core/agents/events/consume.js +0 -195
  623. package/dist/core/agents/events/emit.d.ts +0 -42
  624. package/dist/core/agents/events/emit.d.ts.map +0 -1
  625. package/dist/core/agents/events/emit.js +0 -75
  626. package/dist/core/agents/events/ulid.d.ts +0 -11
  627. package/dist/core/agents/events/ulid.d.ts.map +0 -1
  628. package/dist/core/agents/events/ulid.js +0 -47
  629. package/dist/core/agents/state/heartbeat-projector.d.ts +0 -76
  630. package/dist/core/agents/state/heartbeat-projector.d.ts.map +0 -1
  631. package/dist/core/agents/state/heartbeat-projector.js +0 -581
  632. package/dist/core/hooks/events/emit.d.ts +0 -31
  633. package/dist/core/hooks/events/emit.d.ts.map +0 -1
  634. package/dist/core/hooks/events/emit.js +0 -93
  635. package/dist/core/hooks/events/rotate.d.ts +0 -43
  636. package/dist/core/hooks/events/rotate.d.ts.map +0 -1
  637. package/dist/core/hooks/events/rotate.js +0 -142
  638. package/dist/core/hooks/events/schema.d.ts +0 -341
  639. package/dist/core/hooks/events/schema.d.ts.map +0 -1
  640. package/dist/core/hooks/events/schema.js +0 -12
  641. package/dist/core/hooks/events/ulid.d.ts +0 -10
  642. package/dist/core/hooks/events/ulid.d.ts.map +0 -1
  643. package/dist/core/hooks/events/ulid.js +0 -47
  644. package/dist/lib/docs-frontmatter-migrate.d.ts +0 -33
  645. package/dist/lib/docs-frontmatter-migrate.d.ts.map +0 -1
  646. package/dist/lib/docs-frontmatter-migrate.js +0 -364
  647. package/src/core/agents/cli-emit.ts +0 -64
  648. package/src/core/agents/codex-replay.ts +0 -163
  649. package/src/core/agents/events/consume.ts +0 -254
  650. package/src/core/agents/events/emit.ts +0 -115
  651. package/src/core/agents/events/ulid.ts +0 -51
  652. package/src/core/agents/state/heartbeat-projector.ts +0 -645
  653. package/src/core/hooks/events/emit.ts +0 -125
  654. package/src/core/hooks/events/rotate.ts +0 -151
  655. package/src/core/hooks/events/schema.ts +0 -582
  656. package/src/core/hooks/events/ulid.ts +0 -51
  657. package/src/lib/docs-frontmatter-migrate.ts +0 -427
@@ -0,0 +1,576 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { buildEventV3 } from "./builder.ts";
4
+ import { canonicalJsonV3, sha256V3 } from "./canonical.ts";
5
+ import type { EventV3 } from "./contract.ts";
6
+ import { EVENT_V3_SCHEMA_DIGEST } from "./generated.ts";
7
+ import { activationIdV3, eventIdV3, genesisIdV3 } from "./ids.ts";
8
+ import { type ReadLedgerV3Result, readLedgerV3 } from "./reader.ts";
9
+ import { validateEventV3 } from "./validate.ts";
10
+ import { writeEventV3 } from "./writer.ts";
11
+
12
+ export const EVENT_V3_GENESIS_MANIFEST = ".harnery/ledgers/v3/genesis.json" as const;
13
+ export const EVENT_V3_ACTIVATION_MANIFEST = ".harnery/ledgers/v3/activation.json" as const;
14
+
15
+ type GenesisEventV3 = Extract<EventV3, { event_type: "ledger.genesis" }>;
16
+ type ActivationEventV3 = Extract<EventV3, { event_type: "ledger.activated" }>;
17
+
18
+ export interface CandidateProfileV3 {
19
+ initial_schema_digest: `sha256:${string}`;
20
+ contract_source_digest: `sha256:${string}`;
21
+ harnery_commit: string;
22
+ host_repository_commit: string;
23
+ producer_build_ids: string[];
24
+ adapter_capability_profile_digests: string[];
25
+ config_digest: `sha256:${string}`;
26
+ canonicalizer_version: "harnery-jcs-nfc-v1";
27
+ fingerprint_version: string;
28
+ privacy_key_epoch: `pep_${string}`;
29
+ candidate_created_at: string;
30
+ }
31
+
32
+ export interface CandidateGenesisManifestV3 {
33
+ manifest_version: 1;
34
+ kind: "candidate_genesis";
35
+ profile: CandidateProfileV3;
36
+ event: GenesisEventV3;
37
+ }
38
+
39
+ export interface ActivationManifestV3 {
40
+ manifest_version: 1;
41
+ kind: "activation";
42
+ activation_id: `act_${string}`;
43
+ genesis_id: `gex_${string}`;
44
+ candidate_manifest_digest: `sha256:${string}`;
45
+ approval_record_id: string;
46
+ activation_approved_at: string;
47
+ event: ActivationEventV3;
48
+ }
49
+
50
+ export interface ControlProducerV3 {
51
+ producer_id: `prd_${string}`;
52
+ boot_id: `boot_${string}`;
53
+ sequence: number;
54
+ build_id: `build_${string}`;
55
+ platform: "linux" | "windows" | "macos" | "unknown";
56
+ bridge?: "codex-wsl";
57
+ }
58
+
59
+ export interface BuildCandidateGenesisManifestV3Input {
60
+ profile: CandidateProfileV3;
61
+ root_id: `root_${string}`;
62
+ instance_id: `inst_${string}`;
63
+ producer: ControlProducerV3;
64
+ genesis_id?: `gex_${string}`;
65
+ event_id?: `evt_${string}`;
66
+ }
67
+
68
+ export interface BuildActivationManifestV3Input {
69
+ candidate: CandidateGenesisManifestV3;
70
+ approval_record_id: string;
71
+ activation_approved_at: string;
72
+ producer: ControlProducerV3;
73
+ activation_id?: `act_${string}`;
74
+ event_id?: `evt_${string}`;
75
+ }
76
+
77
+ export type ControlManifestValidationV3<T> = { ok: true; value: T } | { ok: false; reason: string };
78
+
79
+ export type EventV3ControlState =
80
+ | { state: "closed"; reason: "no_candidate" }
81
+ | {
82
+ state: "repairable";
83
+ reason: "genesis_event_missing" | "activation_event_missing";
84
+ genesis: CandidateGenesisManifestV3;
85
+ activation?: ActivationManifestV3;
86
+ }
87
+ | {
88
+ state: "candidate";
89
+ genesis: CandidateGenesisManifestV3;
90
+ candidate_manifest_digest: `sha256:${string}`;
91
+ }
92
+ | {
93
+ state: "active";
94
+ genesis: CandidateGenesisManifestV3;
95
+ activation: ActivationManifestV3;
96
+ candidate_manifest_digest: `sha256:${string}`;
97
+ }
98
+ | { state: "invalid"; reason: string };
99
+
100
+ export type EventV3WriteMode = "candidate" | "active";
101
+
102
+ /** Build a complete immutable candidate packet without writing it or opening a gate. */
103
+ export function buildCandidateGenesisManifestV3(
104
+ input: BuildCandidateGenesisManifestV3Input,
105
+ ): CandidateGenesisManifestV3 {
106
+ const profile: CandidateProfileV3 = {
107
+ ...input.profile,
108
+ producer_build_ids: [...input.profile.producer_build_ids].sort(),
109
+ adapter_capability_profile_digests: [
110
+ ...input.profile.adapter_capability_profile_digests,
111
+ ].sort(),
112
+ };
113
+ const event = buildEventV3("ledger.genesis", {
114
+ event_id: input.event_id,
115
+ producer: { ...input.producer, component: "recovery" },
116
+ scope: { root_id: input.root_id, instance_id: input.instance_id },
117
+ links: { caused_by: [] },
118
+ provenance: controlProvenance("cutover.genesis", input.instance_id),
119
+ observed_at: profile.candidate_created_at,
120
+ recorded_at: profile.candidate_created_at,
121
+ payload: {
122
+ genesis_id: input.genesis_id ?? genesisIdV3(),
123
+ genesis_profile_digest: candidateProfileDigestV3(profile),
124
+ contract_digest: profile.contract_source_digest,
125
+ generated_schema_digest: profile.initial_schema_digest,
126
+ canonicalizer: profile.canonicalizer_version,
127
+ privacy_epoch_id: profile.privacy_key_epoch,
128
+ candidate_created_at: profile.candidate_created_at,
129
+ },
130
+ });
131
+ const manifest: CandidateGenesisManifestV3 = {
132
+ manifest_version: 1,
133
+ kind: "candidate_genesis",
134
+ profile,
135
+ event,
136
+ };
137
+ const validated = validateCandidateGenesisManifestV3(manifest);
138
+ if (!validated.ok) throw new Error(`candidate_genesis_invalid:${validated.reason}`);
139
+ return validated.value;
140
+ }
141
+
142
+ /** Build an approval-bound activation packet without writing it or opening a gate. */
143
+ export function buildActivationManifestV3(
144
+ input: BuildActivationManifestV3Input,
145
+ ): ActivationManifestV3 {
146
+ const candidate = validateCandidateGenesisManifestV3(input.candidate);
147
+ if (!candidate.ok) throw new Error(`candidate_genesis_invalid:${candidate.reason}`);
148
+ const eventId = input.event_id ?? eventIdV3();
149
+ const activationId = input.activation_id ?? activationIdV3();
150
+ const candidateDigest = candidateManifestDigestV3(candidate.value);
151
+ const genesisId = candidate.value.event.payload.genesis_id as `gex_${string}`;
152
+ const scope = candidate.value.event.scope as {
153
+ root_id: `root_${string}`;
154
+ instance_id: `inst_${string}`;
155
+ };
156
+ const event = buildEventV3("ledger.activated", {
157
+ event_id: eventId,
158
+ producer: { ...input.producer, component: "recovery" },
159
+ scope,
160
+ links: { caused_by: [candidate.value.event.event_id] },
161
+ provenance: controlProvenance("cutover.activation", scope.instance_id),
162
+ observed_at: input.activation_approved_at,
163
+ recorded_at: input.activation_approved_at,
164
+ payload: {
165
+ activation_id: activationId,
166
+ genesis_id: genesisId,
167
+ candidate_digest: candidateDigest,
168
+ approval_record_id: input.approval_record_id,
169
+ eligible_after_event_id: eventId,
170
+ activated_at: input.activation_approved_at,
171
+ },
172
+ });
173
+ const manifest: ActivationManifestV3 = {
174
+ manifest_version: 1,
175
+ kind: "activation",
176
+ activation_id: activationId,
177
+ genesis_id: genesisId,
178
+ candidate_manifest_digest: candidateDigest,
179
+ approval_record_id: input.approval_record_id,
180
+ activation_approved_at: input.activation_approved_at,
181
+ event,
182
+ };
183
+ const validated = validateActivationManifestV3(manifest, candidate.value);
184
+ if (!validated.ok) throw new Error(`activation_invalid:${validated.reason}`);
185
+ return validated.value;
186
+ }
187
+
188
+ /** Validate an in-memory candidate with the same strict rules as the live gate. */
189
+ export function validateCandidateGenesisManifestV3(
190
+ value: unknown,
191
+ ): ControlManifestValidationV3<CandidateGenesisManifestV3> {
192
+ return parseGenesisManifestValue(value);
193
+ }
194
+
195
+ /** Validate an in-memory activation against one exact candidate packet. */
196
+ export function validateActivationManifestV3(
197
+ value: unknown,
198
+ candidate: CandidateGenesisManifestV3,
199
+ ): ControlManifestValidationV3<ActivationManifestV3> {
200
+ const validatedCandidate = validateCandidateGenesisManifestV3(candidate);
201
+ if (!validatedCandidate.ok) return fail(`candidate_${validatedCandidate.reason}`);
202
+ return parseActivationManifestValue(
203
+ value,
204
+ validatedCandidate.value,
205
+ candidateManifestDigestV3(validatedCandidate.value),
206
+ );
207
+ }
208
+
209
+ /**
210
+ * Resolve the session/evidence gate from exact control-file and ledger-event pairs.
211
+ * This function never repairs or creates state. Any ambiguity keeps the gate closed.
212
+ */
213
+ export function readEventV3ControlState(coordRoot: string): EventV3ControlState {
214
+ const genesisPath = join(coordRoot, EVENT_V3_GENESIS_MANIFEST);
215
+ const activationPath = join(coordRoot, EVENT_V3_ACTIVATION_MANIFEST);
216
+ const hasGenesis = existsSync(genesisPath);
217
+ const hasActivation = existsSync(activationPath);
218
+ if (!hasGenesis && !hasActivation) {
219
+ const ledger = readControlLedger(coordRoot);
220
+ const hasUnboundControlEvent = ledger.events.some(
221
+ ({ event }) =>
222
+ event.event_type === "ledger.genesis" || event.event_type === "ledger.activated",
223
+ );
224
+ if (hasUnboundControlEvent) {
225
+ return { state: "invalid", reason: "control_event_without_manifest" };
226
+ }
227
+ return { state: "closed", reason: "no_candidate" };
228
+ }
229
+ if (!hasGenesis) return { state: "invalid", reason: "activation_without_genesis_manifest" };
230
+
231
+ const genesisResult = readGenesisManifest(genesisPath);
232
+ if (!genesisResult.ok) return { state: "invalid", reason: genesisResult.reason };
233
+ const genesis = genesisResult.value;
234
+ const candidateDigest = candidateManifestDigestV3(genesis);
235
+ const ledger = readControlLedger(coordRoot);
236
+ if (!ledger.complete) {
237
+ return { state: "invalid", reason: "ledger_integrity_failure" };
238
+ }
239
+ const genesisPair = exactEventPair(
240
+ ledger.events.map((entry) => entry.event),
241
+ genesis.event,
242
+ );
243
+ if (genesisPair === "conflict") return { state: "invalid", reason: "genesis_event_mismatch" };
244
+ if (genesisPair === "missing") {
245
+ return hasActivation
246
+ ? { state: "invalid", reason: "activation_before_genesis_event" }
247
+ : { state: "repairable", reason: "genesis_event_missing", genesis };
248
+ }
249
+ if (!hasActivation) {
250
+ if (ledger.events.some(({ event }) => event.event_type === "ledger.activated")) {
251
+ return { state: "invalid", reason: "activation_event_without_manifest" };
252
+ }
253
+ return { state: "candidate", genesis, candidate_manifest_digest: candidateDigest };
254
+ }
255
+
256
+ const activationResult = readActivationManifest(activationPath, genesis, candidateDigest);
257
+ if (!activationResult.ok) return { state: "invalid", reason: activationResult.reason };
258
+ const activation = activationResult.value;
259
+ const activationPair = exactEventPair(
260
+ ledger.events.map((entry) => entry.event),
261
+ activation.event,
262
+ );
263
+ if (activationPair === "conflict") {
264
+ return { state: "invalid", reason: "activation_event_mismatch" };
265
+ }
266
+ if (activationPair === "missing") {
267
+ return {
268
+ state: "repairable",
269
+ reason: "activation_event_missing",
270
+ genesis,
271
+ activation,
272
+ };
273
+ }
274
+ return {
275
+ state: "active",
276
+ genesis,
277
+ activation,
278
+ candidate_manifest_digest: candidateDigest,
279
+ };
280
+ }
281
+
282
+ export function eventV3WriteGateOpen(coordRoot: string, mode: EventV3WriteMode): boolean {
283
+ const control = readEventV3ControlState(coordRoot);
284
+ return mode === "candidate" ? control.state === "candidate" : control.state === "active";
285
+ }
286
+
287
+ /** Repair only a manifest-first crash by appending the exact pre-minted event. */
288
+ export function repairEventV3ControlPair(coordRoot: string): EventV3ControlState {
289
+ const control = readEventV3ControlState(coordRoot);
290
+ if (control.state !== "repairable") return control;
291
+ const event =
292
+ control.reason === "genesis_event_missing" ? control.genesis.event : control.activation?.event;
293
+ if (!event) return { state: "invalid", reason: "repair_event_unavailable" };
294
+ const result = writeEventV3(coordRoot, event);
295
+ if (result.state !== "committed") {
296
+ return { state: "invalid", reason: "control_event_repair_not_committed" };
297
+ }
298
+ return readEventV3ControlState(coordRoot);
299
+ }
300
+
301
+ export function candidateProfileDigestV3(profile: CandidateProfileV3): `sha256:${string}` {
302
+ return sha256V3(canonicalJsonV3(profile));
303
+ }
304
+
305
+ export function candidateManifestDigestV3(
306
+ manifest: CandidateGenesisManifestV3,
307
+ ): `sha256:${string}` {
308
+ return sha256V3(canonicalJsonV3(manifest));
309
+ }
310
+
311
+ function readGenesisManifest(path: string): ParseResult<CandidateGenesisManifestV3> {
312
+ const parsed = readJsonObject(path);
313
+ if (!parsed.ok) return parsed;
314
+ return parseGenesisManifestValue(parsed.value);
315
+ }
316
+
317
+ function parseGenesisManifestValue(value: unknown): ParseResult<CandidateGenesisManifestV3> {
318
+ if (!isObject(value)) return fail("genesis_manifest_not_object");
319
+ if (!exactKeys(value, ["event", "kind", "manifest_version", "profile"])) {
320
+ return fail("genesis_manifest_shape_invalid");
321
+ }
322
+ if (value.manifest_version !== 1 || value.kind !== "candidate_genesis") {
323
+ return fail("genesis_manifest_version_invalid");
324
+ }
325
+ const profile = parseCandidateProfile(value.profile);
326
+ if (!profile.ok) return profile;
327
+ const validation = validateEventV3(value.event);
328
+ if (!validation.ok || validation.event?.event_type !== "ledger.genesis") {
329
+ return fail("genesis_event_invalid");
330
+ }
331
+ const event = validation.event as GenesisEventV3;
332
+ if (event.producer.sequence !== 1) {
333
+ return fail("genesis_producer_sequence_invalid");
334
+ }
335
+ if (
336
+ event.contract.schema_digest !== EVENT_V3_SCHEMA_DIGEST ||
337
+ event.payload.genesis_profile_digest !== candidateProfileDigestV3(profile.value) ||
338
+ event.payload.contract_digest !== profile.value.contract_source_digest ||
339
+ event.payload.generated_schema_digest !== profile.value.initial_schema_digest ||
340
+ event.payload.canonicalizer !== profile.value.canonicalizer_version ||
341
+ event.payload.privacy_epoch_id !== profile.value.privacy_key_epoch ||
342
+ event.payload.candidate_created_at !== profile.value.candidate_created_at
343
+ ) {
344
+ return fail("genesis_profile_binding_mismatch");
345
+ }
346
+ return {
347
+ ok: true,
348
+ value: { manifest_version: 1, kind: "candidate_genesis", profile: profile.value, event },
349
+ };
350
+ }
351
+
352
+ function readActivationManifest(
353
+ path: string,
354
+ genesis: CandidateGenesisManifestV3,
355
+ candidateDigest: `sha256:${string}`,
356
+ ): ParseResult<ActivationManifestV3> {
357
+ const parsed = readJsonObject(path);
358
+ if (!parsed.ok) return parsed;
359
+ return parseActivationManifestValue(parsed.value, genesis, candidateDigest);
360
+ }
361
+
362
+ function parseActivationManifestValue(
363
+ value: unknown,
364
+ genesis: CandidateGenesisManifestV3,
365
+ candidateDigest: `sha256:${string}`,
366
+ ): ParseResult<ActivationManifestV3> {
367
+ if (!isObject(value)) return fail("activation_manifest_not_object");
368
+ if (
369
+ !exactKeys(value, [
370
+ "activation_approved_at",
371
+ "activation_id",
372
+ "approval_record_id",
373
+ "candidate_manifest_digest",
374
+ "event",
375
+ "genesis_id",
376
+ "kind",
377
+ "manifest_version",
378
+ ])
379
+ ) {
380
+ return fail("activation_manifest_shape_invalid");
381
+ }
382
+ if (value.manifest_version !== 1 || value.kind !== "activation") {
383
+ return fail("activation_manifest_version_invalid");
384
+ }
385
+ const activationId =
386
+ typeof value.activation_id === "string" && /^act_[0-9a-f-]{36}$/.test(value.activation_id)
387
+ ? value.activation_id
388
+ : undefined;
389
+ const genesisId = safeString(value.genesis_id, "gex_");
390
+ const approvalRecordId = safeToken(value.approval_record_id);
391
+ const approvedAt = safeTimestamp(value.activation_approved_at);
392
+ if (!activationId || !genesisId || !approvalRecordId || !approvedAt) {
393
+ return fail("activation_manifest_fields_invalid");
394
+ }
395
+ if (value.candidate_manifest_digest !== candidateDigest) {
396
+ return fail("activation_candidate_digest_mismatch");
397
+ }
398
+ const validation = validateEventV3(value.event);
399
+ if (!validation.ok || validation.event?.event_type !== "ledger.activated") {
400
+ return fail("activation_event_invalid");
401
+ }
402
+ const event = validation.event as ActivationEventV3;
403
+ if (!activationProducerSequenceValid(genesis.event, event)) {
404
+ return fail("activation_producer_sequence_invalid");
405
+ }
406
+ if (
407
+ genesisId !== genesis.event.payload.genesis_id ||
408
+ event.payload.activation_id !== activationId ||
409
+ event.payload.genesis_id !== genesisId ||
410
+ event.payload.candidate_digest !== candidateDigest ||
411
+ event.payload.approval_record_id !== approvalRecordId ||
412
+ event.payload.activated_at !== approvedAt
413
+ ) {
414
+ return fail("activation_profile_binding_mismatch");
415
+ }
416
+ return {
417
+ ok: true,
418
+ value: {
419
+ manifest_version: 1,
420
+ kind: "activation",
421
+ activation_id: activationId as `act_${string}`,
422
+ genesis_id: genesisId as `gex_${string}`,
423
+ candidate_manifest_digest: candidateDigest,
424
+ approval_record_id: approvalRecordId,
425
+ activation_approved_at: approvedAt,
426
+ event,
427
+ },
428
+ };
429
+ }
430
+
431
+ /** Mirror the reader's sequence key: a continuing boot advances, while a new boot starts at one. */
432
+ function activationProducerSequenceValid(
433
+ genesis: GenesisEventV3,
434
+ activation: ActivationEventV3,
435
+ ): boolean {
436
+ const sameBoot =
437
+ activation.producer.producer_id === genesis.producer.producer_id &&
438
+ activation.producer.boot_id === genesis.producer.boot_id;
439
+ return sameBoot
440
+ ? activation.producer.sequence === genesis.producer.sequence + 1
441
+ : activation.producer.sequence === 1;
442
+ }
443
+
444
+ function parseCandidateProfile(value: unknown): ParseResult<CandidateProfileV3> {
445
+ if (!isObject(value)) return fail("genesis_profile_invalid");
446
+ const keys = [
447
+ "adapter_capability_profile_digests",
448
+ "candidate_created_at",
449
+ "canonicalizer_version",
450
+ "config_digest",
451
+ "contract_source_digest",
452
+ "fingerprint_version",
453
+ "harnery_commit",
454
+ "host_repository_commit",
455
+ "initial_schema_digest",
456
+ "privacy_key_epoch",
457
+ "producer_build_ids",
458
+ ];
459
+ if (!exactKeys(value, keys)) return fail("genesis_profile_shape_invalid");
460
+ if (
461
+ isSha256(value.initial_schema_digest) &&
462
+ value.initial_schema_digest !== EVENT_V3_SCHEMA_DIGEST
463
+ ) {
464
+ return fail("genesis_schema_digest_incompatible");
465
+ }
466
+ if (
467
+ !isSha256(value.initial_schema_digest) ||
468
+ !isSha256(value.contract_source_digest) ||
469
+ !isSha256(value.config_digest) ||
470
+ value.canonicalizer_version !== "harnery-jcs-nfc-v1" ||
471
+ !safeString(value.privacy_key_epoch, "pep_") ||
472
+ !safeToken(value.harnery_commit) ||
473
+ !safeToken(value.host_repository_commit) ||
474
+ !safeToken(value.fingerprint_version) ||
475
+ !safeTimestamp(value.candidate_created_at) ||
476
+ !sortedSafeTokenArray(value.producer_build_ids) ||
477
+ !sortedSha256Array(value.adapter_capability_profile_digests)
478
+ ) {
479
+ return fail("genesis_profile_fields_invalid");
480
+ }
481
+ return { ok: true, value: value as unknown as CandidateProfileV3 };
482
+ }
483
+
484
+ function exactEventPair(events: EventV3[], expected: EventV3): "exact" | "missing" | "conflict" {
485
+ const matches = events.filter((event) => event.event_id === expected.event_id);
486
+ if (matches.length === 0) return "missing";
487
+ const expectedRow = canonicalJsonV3(expected);
488
+ return matches.every((event) => canonicalJsonV3(event) === expectedRow) ? "exact" : "conflict";
489
+ }
490
+
491
+ function readControlLedger(coordRoot: string): ReadLedgerV3Result {
492
+ const ledger = readLedgerV3(coordRoot);
493
+ // An immutable manifest is published before its pre-minted control event.
494
+ // During that repairable window an empty physical ledger necessarily reports
495
+ // missing_genesis; the control pair owns that one diagnostic and repairs it.
496
+ const diagnostics = ledger.diagnostics.filter(({ code }) => code !== "missing_genesis");
497
+ return { ...ledger, diagnostics, complete: diagnostics.length === 0 };
498
+ }
499
+
500
+ type ParseResult<T> = ControlManifestValidationV3<T>;
501
+
502
+ function controlProvenance(sourceEvent: string, subjectInstanceId: `inst_${string}`) {
503
+ return {
504
+ source_event: sourceEvent,
505
+ attestation: "operator" as const,
506
+ confidence: "exact" as const,
507
+ attribution: {
508
+ method: "explicit_argument" as const,
509
+ state: "verified" as const,
510
+ subject_instance_id: subjectInstanceId,
511
+ },
512
+ };
513
+ }
514
+
515
+ function readJsonObject(path: string): ParseResult<Record<string, unknown>> {
516
+ try {
517
+ const value: unknown = JSON.parse(readFileSync(path, "utf8"));
518
+ return isObject(value) ? { ok: true, value } : fail("control_manifest_not_object");
519
+ } catch {
520
+ return fail("control_manifest_unreadable");
521
+ }
522
+ }
523
+
524
+ function fail<T>(reason: string): ParseResult<T> {
525
+ return { ok: false, reason };
526
+ }
527
+
528
+ function isObject(value: unknown): value is Record<string, unknown> {
529
+ return !!value && typeof value === "object" && !Array.isArray(value);
530
+ }
531
+
532
+ function exactKeys(value: Record<string, unknown>, expected: string[]): boolean {
533
+ return Object.keys(value).sort().join("\0") === [...expected].sort().join("\0");
534
+ }
535
+
536
+ function safeToken(value: unknown): string | undefined {
537
+ return typeof value === "string" && /^[a-zA-Z0-9][a-zA-Z0-9._:/+-]{0,127}$/.test(value)
538
+ ? value
539
+ : undefined;
540
+ }
541
+
542
+ function safeString(value: unknown, prefix: string): string | undefined {
543
+ return typeof value === "string" && value.startsWith(prefix) && value.length <= 128
544
+ ? value
545
+ : undefined;
546
+ }
547
+
548
+ function safeTimestamp(value: unknown): string | undefined {
549
+ return typeof value === "string" && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(value)
550
+ ? value
551
+ : undefined;
552
+ }
553
+
554
+ function isSha256(value: unknown): value is `sha256:${string}` {
555
+ return typeof value === "string" && /^sha256:[a-f0-9]{64}$/.test(value);
556
+ }
557
+
558
+ function sortedSafeTokenArray(value: unknown): value is string[] {
559
+ return (
560
+ Array.isArray(value) &&
561
+ value.length > 0 &&
562
+ value.length <= 64 &&
563
+ value.every((item, index) => index === 0 || value[index - 1]! < item) &&
564
+ value.every((item) => safeToken(item) !== undefined)
565
+ );
566
+ }
567
+
568
+ function sortedSha256Array(value: unknown): value is string[] {
569
+ return (
570
+ Array.isArray(value) &&
571
+ value.length > 0 &&
572
+ value.length <= 64 &&
573
+ value.every((item, index) => index === 0 || value[index - 1]! < item) &&
574
+ value.every(isSha256)
575
+ );
576
+ }