harnery 0.32.0 → 0.34.0

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