harnery 0.35.0 → 0.37.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 (843) hide show
  1. package/dist/commander.d.ts +30 -5
  2. package/dist/commander.d.ts.map +1 -1
  3. package/dist/commander.js +128 -96
  4. package/dist/commands/agents.d.ts +23 -3
  5. package/dist/commands/agents.d.ts.map +1 -1
  6. package/dist/commands/agents.js +464 -242
  7. package/dist/commands/artifacts.d.ts.map +1 -1
  8. package/dist/commands/artifacts.js +26 -1
  9. package/dist/commands/backup.d.ts.map +1 -1
  10. package/dist/commands/backup.js +10 -10
  11. package/dist/commands/browse-session.d.ts.map +1 -1
  12. package/dist/commands/browse-session.js +12 -0
  13. package/dist/commands/browse.d.ts +1 -1
  14. package/dist/commands/browse.d.ts.map +1 -1
  15. package/dist/commands/browse.js +16 -4
  16. package/dist/commands/conversations.d.ts +10 -0
  17. package/dist/commands/conversations.d.ts.map +1 -0
  18. package/dist/commands/conversations.js +201 -0
  19. package/dist/commands/deinit.d.ts.map +1 -1
  20. package/dist/commands/deinit.js +5 -0
  21. package/dist/commands/diagnostics.d.ts +4 -0
  22. package/dist/commands/diagnostics.d.ts.map +1 -0
  23. package/dist/commands/diagnostics.js +229 -0
  24. package/dist/commands/docs.d.ts.map +1 -1
  25. package/dist/commands/docs.js +13 -2
  26. package/dist/commands/doctor.d.ts +5 -0
  27. package/dist/commands/doctor.d.ts.map +1 -1
  28. package/dist/commands/doctor.js +51 -7
  29. package/dist/commands/fetch.js +6 -5
  30. package/dist/commands/files.d.ts +34 -0
  31. package/dist/commands/files.d.ts.map +1 -0
  32. package/dist/commands/files.js +166 -0
  33. package/dist/commands/governor.d.ts.map +1 -1
  34. package/dist/commands/governor.js +18 -12
  35. package/dist/commands/inbox.d.ts +5 -0
  36. package/dist/commands/inbox.d.ts.map +1 -0
  37. package/dist/commands/inbox.js +57 -0
  38. package/dist/commands/init.d.ts +4 -5
  39. package/dist/commands/init.d.ts.map +1 -1
  40. package/dist/commands/init.js +63 -13
  41. package/dist/commands/ledger-v3.d.ts.map +1 -1
  42. package/dist/commands/ledger-v3.js +417 -2
  43. package/dist/commands/logs.d.ts +4 -0
  44. package/dist/commands/logs.d.ts.map +1 -0
  45. package/dist/commands/logs.js +169 -0
  46. package/dist/commands/messages.d.ts +5 -0
  47. package/dist/commands/messages.d.ts.map +1 -0
  48. package/dist/commands/messages.js +45 -0
  49. package/dist/commands/outline.d.ts +1 -1
  50. package/dist/commands/outline.d.ts.map +1 -1
  51. package/dist/commands/outline.js +2 -2
  52. package/dist/commands/qa-run.d.ts +4 -0
  53. package/dist/commands/qa-run.d.ts.map +1 -0
  54. package/dist/commands/qa-run.js +141 -0
  55. package/dist/commands/read.d.ts +1 -1
  56. package/dist/commands/read.d.ts.map +1 -1
  57. package/dist/commands/read.js +2 -2
  58. package/dist/commands/resources.d.ts +4 -0
  59. package/dist/commands/resources.d.ts.map +1 -0
  60. package/dist/commands/resources.js +29 -0
  61. package/dist/commands/semantic.d.ts.map +1 -1
  62. package/dist/commands/semantic.js +54 -2
  63. package/dist/commands/storage.d.ts +4 -0
  64. package/dist/commands/storage.d.ts.map +1 -0
  65. package/dist/commands/storage.js +238 -0
  66. package/dist/commands/supervisor.d.ts +4 -0
  67. package/dist/commands/supervisor.d.ts.map +1 -0
  68. package/dist/commands/supervisor.js +101 -0
  69. package/dist/commands/tunnel.d.ts +5 -1
  70. package/dist/commands/tunnel.d.ts.map +1 -1
  71. package/dist/commands/tunnel.js +44 -31
  72. package/dist/commands/web.d.ts +3 -0
  73. package/dist/commands/web.d.ts.map +1 -1
  74. package/dist/commands/web.js +84 -7
  75. package/dist/commands/work.js +3 -3
  76. package/dist/commands/workflow.d.ts.map +1 -1
  77. package/dist/commands/workflow.js +17 -13
  78. package/dist/core/adapters/profiles.d.ts +1 -1
  79. package/dist/core/agents/cli.js +215 -41
  80. package/dist/core/agents/health.d.ts +17 -0
  81. package/dist/core/agents/health.d.ts.map +1 -0
  82. package/dist/core/agents/health.js +109 -0
  83. package/dist/core/agents/live-authority-v3.d.ts +47 -1
  84. package/dist/core/agents/live-authority-v3.d.ts.map +1 -1
  85. package/dist/core/agents/live-authority-v3.js +244 -10
  86. package/dist/core/agents/live-lifecycle-v3.js +6 -1
  87. package/dist/core/agents/live-observation-v3.d.ts.map +1 -1
  88. package/dist/core/agents/live-observation-v3.js +6 -1
  89. package/dist/core/agents/mailbox.d.ts +92 -0
  90. package/dist/core/agents/mailbox.d.ts.map +1 -0
  91. package/dist/core/agents/mailbox.js +325 -0
  92. package/dist/core/agents/reconcile-coordination-v3.d.ts +44 -0
  93. package/dist/core/agents/reconcile-coordination-v3.d.ts.map +1 -0
  94. package/dist/core/agents/reconcile-coordination-v3.js +58 -0
  95. package/dist/core/agents/render/prompt-context.d.ts +14 -3
  96. package/dist/core/agents/render/prompt-context.d.ts.map +1 -1
  97. package/dist/core/agents/render/prompt-context.js +54 -16
  98. package/dist/core/agents/render/session-context.d.ts +8 -0
  99. package/dist/core/agents/render/session-context.d.ts.map +1 -1
  100. package/dist/core/agents/render/session-context.js +34 -3
  101. package/dist/core/agents/rules/commit-conflict.d.ts.map +1 -1
  102. package/dist/core/agents/rules/commit-conflict.js +50 -1
  103. package/dist/core/agents/rules/stop-hook.d.ts +2 -0
  104. package/dist/core/agents/rules/stop-hook.d.ts.map +1 -1
  105. package/dist/core/agents/rules/stop-hook.js +93 -16
  106. package/dist/core/agents/rules/verdict.d.ts +1 -0
  107. package/dist/core/agents/rules/verdict.d.ts.map +1 -1
  108. package/dist/core/agents/session-events.d.ts.map +1 -1
  109. package/dist/core/agents/session-events.js +4 -0
  110. package/dist/core/agents/session-finalization-state-v3.js +1 -1
  111. package/dist/core/agents/session-finalizer-v3.js +9 -2
  112. package/dist/core/agents/state/activity-log.d.ts +3 -0
  113. package/dist/core/agents/state/activity-log.d.ts.map +1 -1
  114. package/dist/core/agents/state/activity-log.js +6 -3
  115. package/dist/core/agents/state/heartbeat-writer.d.ts +6 -0
  116. package/dist/core/agents/state/heartbeat-writer.d.ts.map +1 -1
  117. package/dist/core/agents/state/heartbeat-writer.js +18 -0
  118. package/dist/core/agents/state/live-coordination-view.d.ts +5 -7
  119. package/dist/core/agents/state/live-coordination-view.d.ts.map +1 -1
  120. package/dist/core/agents/state/live-coordination-view.js +15 -90
  121. package/dist/core/agents/state/live-coordination-writer.d.ts +12 -0
  122. package/dist/core/agents/state/live-coordination-writer.d.ts.map +1 -0
  123. package/dist/core/agents/state/live-coordination-writer.js +92 -0
  124. package/dist/core/artifacts/index.d.ts +47 -1
  125. package/dist/core/artifacts/index.d.ts.map +1 -1
  126. package/dist/core/artifacts/index.js +191 -6
  127. package/dist/core/config.d.ts +74 -4
  128. package/dist/core/config.d.ts.map +1 -1
  129. package/dist/core/config.js +141 -4
  130. package/dist/core/conversations/archive.d.ts +49 -0
  131. package/dist/core/conversations/archive.d.ts.map +1 -0
  132. package/dist/core/conversations/archive.js +136 -0
  133. package/dist/core/conversations/catalog.d.ts +10 -0
  134. package/dist/core/conversations/catalog.d.ts.map +1 -0
  135. package/dist/core/conversations/catalog.js +72 -0
  136. package/dist/core/conversations/context-pack.d.ts +6 -0
  137. package/dist/core/conversations/context-pack.d.ts.map +1 -0
  138. package/dist/core/conversations/context-pack.js +60 -0
  139. package/dist/core/conversations/contract.d.ts +155 -0
  140. package/dist/core/conversations/contract.d.ts.map +1 -0
  141. package/dist/core/conversations/contract.js +1 -0
  142. package/dist/core/conversations/evaluation.d.ts +16 -0
  143. package/dist/core/conversations/evaluation.d.ts.map +1 -0
  144. package/dist/core/conversations/evaluation.js +9 -0
  145. package/dist/core/conversations/index.d.ts +10 -0
  146. package/dist/core/conversations/index.d.ts.map +1 -0
  147. package/dist/core/conversations/index.js +9 -0
  148. package/dist/core/conversations/lifecycle.d.ts +28 -0
  149. package/dist/core/conversations/lifecycle.d.ts.map +1 -0
  150. package/dist/core/conversations/lifecycle.js +29 -0
  151. package/dist/core/conversations/normalize.d.ts +14 -0
  152. package/dist/core/conversations/normalize.d.ts.map +1 -0
  153. package/dist/core/conversations/normalize.js +82 -0
  154. package/dist/core/conversations/query.d.ts +8 -0
  155. package/dist/core/conversations/query.d.ts.map +1 -0
  156. package/dist/core/conversations/query.js +280 -0
  157. package/dist/core/conversations/search-index.d.ts +9 -0
  158. package/dist/core/conversations/search-index.d.ts.map +1 -0
  159. package/dist/core/conversations/search-index.js +29 -0
  160. package/dist/core/diagnostics/advice.d.ts +9 -0
  161. package/dist/core/diagnostics/advice.d.ts.map +1 -0
  162. package/dist/core/diagnostics/advice.js +112 -0
  163. package/dist/core/diagnostics/bundle.d.ts +35 -0
  164. package/dist/core/diagnostics/bundle.d.ts.map +1 -0
  165. package/dist/core/diagnostics/bundle.js +874 -0
  166. package/dist/core/diagnostics/comparison.d.ts +5 -0
  167. package/dist/core/diagnostics/comparison.d.ts.map +1 -0
  168. package/dist/core/diagnostics/comparison.js +444 -0
  169. package/dist/core/diagnostics/contract.d.ts +245 -0
  170. package/dist/core/diagnostics/contract.d.ts.map +1 -0
  171. package/dist/core/diagnostics/contract.js +18 -0
  172. package/dist/core/diagnostics/identity.d.ts +3 -0
  173. package/dist/core/diagnostics/identity.d.ts.map +1 -0
  174. package/dist/core/diagnostics/identity.js +10 -0
  175. package/dist/core/diagnostics/index.d.ts +8 -0
  176. package/dist/core/diagnostics/index.d.ts.map +1 -0
  177. package/dist/core/diagnostics/index.js +7 -0
  178. package/dist/core/diagnostics/replay.d.ts +8 -0
  179. package/dist/core/diagnostics/replay.d.ts.map +1 -0
  180. package/dist/core/diagnostics/replay.js +213 -0
  181. package/dist/core/diagnostics/sanitize.d.ts +9 -0
  182. package/dist/core/diagnostics/sanitize.d.ts.map +1 -0
  183. package/dist/core/diagnostics/sanitize.js +84 -0
  184. package/dist/core/events/legacy-storage/canary.d.ts +18 -0
  185. package/dist/core/events/legacy-storage/canary.d.ts.map +1 -0
  186. package/dist/core/events/legacy-storage/canary.js +150 -0
  187. package/dist/core/events/legacy-storage/compression.d.ts +13 -0
  188. package/dist/core/events/legacy-storage/compression.d.ts.map +1 -0
  189. package/dist/core/events/legacy-storage/compression.js +107 -0
  190. package/dist/core/events/legacy-storage/fence.d.ts +15 -0
  191. package/dist/core/events/legacy-storage/fence.d.ts.map +1 -0
  192. package/dist/core/events/legacy-storage/fence.js +115 -0
  193. package/dist/core/events/legacy-storage/index.d.ts +7 -0
  194. package/dist/core/events/legacy-storage/index.d.ts.map +1 -0
  195. package/dist/core/events/legacy-storage/index.js +6 -0
  196. package/dist/core/events/legacy-storage/inventory.d.ts +10 -0
  197. package/dist/core/events/legacy-storage/inventory.d.ts.map +1 -0
  198. package/dist/core/events/legacy-storage/inventory.js +40 -0
  199. package/dist/core/events/legacy-storage/manifest.d.ts +23 -0
  200. package/dist/core/events/legacy-storage/manifest.d.ts.map +1 -0
  201. package/dist/core/events/legacy-storage/manifest.js +108 -0
  202. package/dist/core/events/legacy-storage/reader.d.ts +15 -0
  203. package/dist/core/events/legacy-storage/reader.d.ts.map +1 -0
  204. package/dist/core/events/legacy-storage/reader.js +154 -0
  205. package/dist/core/events/v3/archive-retention.d.ts +33 -0
  206. package/dist/core/events/v3/archive-retention.d.ts.map +1 -0
  207. package/dist/core/events/v3/archive-retention.js +195 -0
  208. package/dist/core/events/v3/authority-outbox.d.ts +7 -2
  209. package/dist/core/events/v3/authority-outbox.d.ts.map +1 -1
  210. package/dist/core/events/v3/authority-outbox.js +16 -3
  211. package/dist/core/events/v3/base-contract.d.ts +81 -41
  212. package/dist/core/events/v3/base-contract.d.ts.map +1 -1
  213. package/dist/core/events/v3/base-contract.js +17 -7
  214. package/dist/core/events/v3/bootstrap.d.ts +39 -0
  215. package/dist/core/events/v3/bootstrap.d.ts.map +1 -1
  216. package/dist/core/events/v3/bootstrap.js +167 -3
  217. package/dist/core/events/v3/capabilities.d.ts +1 -1
  218. package/dist/core/events/v3/capabilities.d.ts.map +1 -1
  219. package/dist/core/events/v3/capabilities.js +4 -3
  220. package/dist/core/events/v3/control-witness.d.ts +44 -0
  221. package/dist/core/events/v3/control-witness.d.ts.map +1 -0
  222. package/dist/core/events/v3/control-witness.js +233 -0
  223. package/dist/core/events/v3/control-writer.d.ts +4 -0
  224. package/dist/core/events/v3/control-writer.d.ts.map +1 -0
  225. package/dist/core/events/v3/control-writer.js +16 -0
  226. package/dist/core/events/v3/control.d.ts +8 -2
  227. package/dist/core/events/v3/control.d.ts.map +1 -1
  228. package/dist/core/events/v3/control.js +46 -18
  229. package/dist/core/events/v3/coordination-transaction-recovery.d.ts +42 -0
  230. package/dist/core/events/v3/coordination-transaction-recovery.d.ts.map +1 -0
  231. package/dist/core/events/v3/coordination-transaction-recovery.js +342 -0
  232. package/dist/core/events/v3/coordination-view.d.ts.map +1 -1
  233. package/dist/core/events/v3/coordination-view.js +16 -1
  234. package/dist/core/events/v3/generated.d.ts +1 -1
  235. package/dist/core/events/v3/generated.js +1 -1
  236. package/dist/core/events/v3/index.d.ts +5 -2
  237. package/dist/core/events/v3/index.d.ts.map +1 -1
  238. package/dist/core/events/v3/index.js +4 -1
  239. package/dist/core/events/v3/live-route-observer.d.ts +31 -0
  240. package/dist/core/events/v3/live-route-observer.d.ts.map +1 -0
  241. package/dist/core/events/v3/live-route-observer.js +58 -0
  242. package/dist/core/events/v3/live-routing.d.ts +13 -21
  243. package/dist/core/events/v3/live-routing.d.ts.map +1 -1
  244. package/dist/core/events/v3/live-routing.js +46 -41
  245. package/dist/core/events/v3/producers/coordination-recorder.d.ts +11 -1
  246. package/dist/core/events/v3/producers/coordination-recorder.d.ts.map +1 -1
  247. package/dist/core/events/v3/producers/coordination-recorder.js +76 -10
  248. package/dist/core/events/v3/producers/diagnostic-summaries.d.ts +129 -0
  249. package/dist/core/events/v3/producers/diagnostic-summaries.d.ts.map +1 -0
  250. package/dist/core/events/v3/producers/diagnostic-summaries.js +499 -0
  251. package/dist/core/events/v3/producers/hook-base.d.ts +1 -1
  252. package/dist/core/events/v3/producers/hook-base.d.ts.map +1 -1
  253. package/dist/core/events/v3/producers/hook-base.js +14 -3
  254. package/dist/core/events/v3/producers/intake.d.ts +7 -0
  255. package/dist/core/events/v3/producers/intake.d.ts.map +1 -1
  256. package/dist/core/events/v3/producers/intake.js +26 -2
  257. package/dist/core/events/v3/producers/producer-state-observer.d.ts +8 -0
  258. package/dist/core/events/v3/producers/producer-state-observer.d.ts.map +1 -0
  259. package/dist/core/events/v3/producers/producer-state-observer.js +45 -0
  260. package/dist/core/events/v3/producers/recorder.d.ts +71 -1
  261. package/dist/core/events/v3/producers/recorder.d.ts.map +1 -1
  262. package/dist/core/events/v3/producers/recorder.js +441 -25
  263. package/dist/core/events/v3/reader.d.ts +51 -0
  264. package/dist/core/events/v3/reader.d.ts.map +1 -1
  265. package/dist/core/events/v3/reader.js +181 -1
  266. package/dist/core/events/v3/rotation-config.d.ts +9 -0
  267. package/dist/core/events/v3/rotation-config.d.ts.map +1 -0
  268. package/dist/core/events/v3/rotation-config.js +91 -0
  269. package/dist/core/events/v3/runtime-build.d.ts +11 -0
  270. package/dist/core/events/v3/runtime-build.d.ts.map +1 -0
  271. package/dist/core/events/v3/runtime-build.js +39 -0
  272. package/dist/core/events/v3/runtime-identity.d.ts +5 -0
  273. package/dist/core/events/v3/runtime-identity.d.ts.map +1 -0
  274. package/dist/core/events/v3/runtime-identity.js +18 -0
  275. package/dist/core/events/v3/runtime-telemetry-capabilities.d.ts +6 -5
  276. package/dist/core/events/v3/runtime-telemetry-capabilities.d.ts.map +1 -1
  277. package/dist/core/events/v3/runtime-telemetry-capabilities.js +1 -1
  278. package/dist/core/events/v3/support-storage/classify.d.ts +46 -0
  279. package/dist/core/events/v3/support-storage/classify.d.ts.map +1 -0
  280. package/dist/core/events/v3/support-storage/classify.js +149 -0
  281. package/dist/core/events/v3/support-storage/eligibility.d.ts +29 -0
  282. package/dist/core/events/v3/support-storage/eligibility.d.ts.map +1 -0
  283. package/dist/core/events/v3/support-storage/eligibility.js +35 -0
  284. package/dist/core/events/v3/support-storage/index.d.ts +10 -0
  285. package/dist/core/events/v3/support-storage/index.d.ts.map +1 -0
  286. package/dist/core/events/v3/support-storage/index.js +9 -0
  287. package/dist/core/events/v3/support-storage/inventory.d.ts +30 -0
  288. package/dist/core/events/v3/support-storage/inventory.d.ts.map +1 -0
  289. package/dist/core/events/v3/support-storage/inventory.js +94 -0
  290. package/dist/core/events/v3/support-storage/logical-authority.d.ts +14 -0
  291. package/dist/core/events/v3/support-storage/logical-authority.d.ts.map +1 -0
  292. package/dist/core/events/v3/support-storage/logical-authority.js +104 -0
  293. package/dist/core/events/v3/support-storage/maintenance.d.ts +98 -0
  294. package/dist/core/events/v3/support-storage/maintenance.d.ts.map +1 -0
  295. package/dist/core/events/v3/support-storage/maintenance.js +352 -0
  296. package/dist/core/events/v3/support-storage/pack-contract.d.ts +59 -0
  297. package/dist/core/events/v3/support-storage/pack-contract.d.ts.map +1 -0
  298. package/dist/core/events/v3/support-storage/pack-contract.js +249 -0
  299. package/dist/core/events/v3/support-storage/pack-reader.d.ts +34 -0
  300. package/dist/core/events/v3/support-storage/pack-reader.d.ts.map +1 -0
  301. package/dist/core/events/v3/support-storage/pack-reader.js +258 -0
  302. package/dist/core/events/v3/support-storage/pack-writer.d.ts +30 -0
  303. package/dist/core/events/v3/support-storage/pack-writer.d.ts.map +1 -0
  304. package/dist/core/events/v3/support-storage/pack-writer.js +268 -0
  305. package/dist/core/events/v3/support-storage/recovery.d.ts +15 -0
  306. package/dist/core/events/v3/support-storage/recovery.d.ts.map +1 -0
  307. package/dist/core/events/v3/support-storage/recovery.js +22 -0
  308. package/dist/core/events/v3/turn-telemetry.d.ts +14 -8
  309. package/dist/core/events/v3/turn-telemetry.d.ts.map +1 -1
  310. package/dist/core/events/v3/turn-telemetry.js +32 -2
  311. package/dist/core/events/v3/writer.d.ts +13 -1
  312. package/dist/core/events/v3/writer.d.ts.map +1 -1
  313. package/dist/core/events/v3/writer.js +126 -12
  314. package/dist/core/governor/plan-read.d.ts.map +1 -1
  315. package/dist/core/governor/plan-read.js +5 -21
  316. package/dist/core/governor/planning.js +6 -8
  317. package/dist/core/governor/service-read.d.ts +12 -0
  318. package/dist/core/governor/service-read.d.ts.map +1 -1
  319. package/dist/core/governor/service-read.js +266 -2
  320. package/dist/core/governor/service.d.ts +1 -0
  321. package/dist/core/governor/service.d.ts.map +1 -1
  322. package/dist/core/governor/service.js +53 -18
  323. package/dist/core/guard/evidence-v3.d.ts.map +1 -1
  324. package/dist/core/guard/evidence-v3.js +2 -0
  325. package/dist/core/hooks/adapter/events.d.ts.map +1 -1
  326. package/dist/core/hooks/adapter/events.js +1 -0
  327. package/dist/core/hooks/adapter/output.d.ts +12 -2
  328. package/dist/core/hooks/adapter/output.d.ts.map +1 -1
  329. package/dist/core/hooks/adapter/output.js +23 -5
  330. package/dist/core/hooks/adapter/runtime-telemetry.d.ts +27 -4
  331. package/dist/core/hooks/adapter/runtime-telemetry.d.ts.map +1 -1
  332. package/dist/core/hooks/adapter/runtime-telemetry.js +307 -6
  333. package/dist/core/hooks/cli.js +380 -207
  334. package/dist/core/hooks/effects/image-capture.d.ts +1 -1
  335. package/dist/core/hooks/effects/image-capture.d.ts.map +1 -1
  336. package/dist/core/hooks/effects/image-capture.js +4 -2
  337. package/dist/core/hooks/health.d.ts +59 -0
  338. package/dist/core/hooks/health.d.ts.map +1 -0
  339. package/dist/core/hooks/health.js +84 -0
  340. package/dist/core/hooks/remediation-cap.d.ts +8 -3
  341. package/dist/core/hooks/remediation-cap.d.ts.map +1 -1
  342. package/dist/core/hooks/remediation-cap.js +3 -11
  343. package/dist/core/hooks/resolve/coord-root.d.ts +22 -9
  344. package/dist/core/hooks/resolve/coord-root.d.ts.map +1 -1
  345. package/dist/core/hooks/resolve/coord-root.js +92 -11
  346. package/dist/core/hooks/resolve/owner.d.ts.map +1 -1
  347. package/dist/core/hooks/resolve/owner.js +5 -0
  348. package/dist/core/hooks/resolve/transcript.d.ts +8 -0
  349. package/dist/core/hooks/resolve/transcript.d.ts.map +1 -1
  350. package/dist/core/hooks/resolve/transcript.js +11 -0
  351. package/dist/core/inbox/contract.d.ts +64 -0
  352. package/dist/core/inbox/contract.d.ts.map +1 -0
  353. package/dist/core/inbox/contract.js +13 -0
  354. package/dist/core/inbox/index.d.ts +5 -0
  355. package/dist/core/inbox/index.d.ts.map +1 -0
  356. package/dist/core/inbox/index.js +4 -0
  357. package/dist/core/inbox/lifecycle.d.ts +22 -0
  358. package/dist/core/inbox/lifecycle.d.ts.map +1 -0
  359. package/dist/core/inbox/lifecycle.js +41 -0
  360. package/dist/core/inbox/service.d.ts +36 -0
  361. package/dist/core/inbox/service.d.ts.map +1 -0
  362. package/dist/core/inbox/service.js +210 -0
  363. package/dist/core/inbox/watcher.d.ts +7 -0
  364. package/dist/core/inbox/watcher.d.ts.map +1 -0
  365. package/dist/core/inbox/watcher.js +26 -0
  366. package/dist/core/presence/codec-digest.d.ts.map +1 -1
  367. package/dist/core/presence/codec-digest.js +14 -3
  368. package/dist/core/presence/relay-client.d.ts +1 -0
  369. package/dist/core/presence/relay-client.d.ts.map +1 -1
  370. package/dist/core/presence/relay-client.js +52 -8
  371. package/dist/core/resources/contract.d.ts +90 -0
  372. package/dist/core/resources/contract.d.ts.map +1 -0
  373. package/dist/core/resources/contract.js +2 -0
  374. package/dist/core/resources/index.d.ts +6 -0
  375. package/dist/core/resources/index.d.ts.map +1 -0
  376. package/dist/core/resources/index.js +5 -0
  377. package/dist/core/resources/sampler.d.ts +27 -0
  378. package/dist/core/resources/sampler.d.ts.map +1 -0
  379. package/dist/core/resources/sampler.js +357 -0
  380. package/dist/core/resources/service-status.d.ts +3 -0
  381. package/dist/core/resources/service-status.d.ts.map +1 -0
  382. package/dist/core/resources/service-status.js +48 -0
  383. package/dist/core/resources/service.d.ts +26 -0
  384. package/dist/core/resources/service.d.ts.map +1 -0
  385. package/dist/core/resources/service.js +292 -0
  386. package/dist/core/resources/storage.d.ts +13 -0
  387. package/dist/core/resources/storage.d.ts.map +1 -0
  388. package/dist/core/resources/storage.js +30 -0
  389. package/dist/core/semantic/adapters.d.ts +11 -8
  390. package/dist/core/semantic/adapters.d.ts.map +1 -1
  391. package/dist/core/semantic/adapters.js +169 -31
  392. package/dist/core/semantic/contract.d.ts +532 -48
  393. package/dist/core/semantic/contract.d.ts.map +1 -1
  394. package/dist/core/semantic/contract.js +104 -3
  395. package/dist/core/semantic/index.d.ts +7 -3
  396. package/dist/core/semantic/index.d.ts.map +1 -1
  397. package/dist/core/semantic/index.js +7 -3
  398. package/dist/core/semantic/once.d.ts +6 -1
  399. package/dist/core/semantic/once.d.ts.map +1 -1
  400. package/dist/core/semantic/once.js +80 -9
  401. package/dist/core/semantic/prompt.d.ts.map +1 -1
  402. package/dist/core/semantic/prompt.js +14 -1
  403. package/dist/core/semantic/review.d.ts +144 -0
  404. package/dist/core/semantic/review.d.ts.map +1 -0
  405. package/dist/core/semantic/review.js +544 -0
  406. package/dist/core/semantic/routes.d.ts +10 -0
  407. package/dist/core/semantic/routes.d.ts.map +1 -0
  408. package/dist/core/semantic/routes.js +21 -0
  409. package/dist/core/semantic/scheduler.d.ts +14 -3
  410. package/dist/core/semantic/scheduler.d.ts.map +1 -1
  411. package/dist/core/semantic/scheduler.js +30 -6
  412. package/dist/core/semantic/service-status.d.ts +20 -0
  413. package/dist/core/semantic/service-status.d.ts.map +1 -1
  414. package/dist/core/semantic/service-status.js +60 -4
  415. package/dist/core/semantic/service.d.ts +1 -0
  416. package/dist/core/semantic/service.d.ts.map +1 -1
  417. package/dist/core/semantic/service.js +104 -15
  418. package/dist/core/semantic/soak.d.ts +75 -0
  419. package/dist/core/semantic/soak.d.ts.map +1 -0
  420. package/dist/core/semantic/soak.js +476 -0
  421. package/dist/core/semantic/storage.d.ts +11 -1
  422. package/dist/core/semantic/storage.d.ts.map +1 -1
  423. package/dist/core/semantic/storage.js +4 -3
  424. package/dist/core/semantic/usage.d.ts +43 -0
  425. package/dist/core/semantic/usage.d.ts.map +1 -0
  426. package/dist/core/semantic/usage.js +193 -0
  427. package/dist/core/semantic/validate.d.ts +3 -1
  428. package/dist/core/semantic/validate.d.ts.map +1 -1
  429. package/dist/core/semantic/validate.js +34 -1
  430. package/dist/core/storage/atomic-json.d.ts +3 -0
  431. package/dist/core/storage/atomic-json.d.ts.map +1 -0
  432. package/dist/core/storage/atomic-json.js +15 -0
  433. package/dist/core/storage/buffer.d.ts +28 -0
  434. package/dist/core/storage/buffer.d.ts.map +1 -0
  435. package/dist/core/storage/buffer.js +101 -0
  436. package/dist/core/storage/builtins.d.ts +3 -0
  437. package/dist/core/storage/builtins.d.ts.map +1 -0
  438. package/dist/core/storage/builtins.js +722 -0
  439. package/dist/core/storage/catalog.d.ts +19 -0
  440. package/dist/core/storage/catalog.d.ts.map +1 -0
  441. package/dist/core/storage/catalog.js +365 -0
  442. package/dist/core/storage/config.d.ts +16 -0
  443. package/dist/core/storage/config.d.ts.map +1 -0
  444. package/dist/core/storage/config.js +311 -0
  445. package/dist/core/storage/contract.d.ts +275 -0
  446. package/dist/core/storage/contract.d.ts.map +1 -0
  447. package/dist/core/storage/contract.js +3 -0
  448. package/dist/core/storage/durable-history.d.ts +36 -0
  449. package/dist/core/storage/durable-history.d.ts.map +1 -0
  450. package/dist/core/storage/durable-history.js +606 -0
  451. package/dist/core/storage/health.d.ts +4 -0
  452. package/dist/core/storage/health.d.ts.map +1 -0
  453. package/dist/core/storage/health.js +65 -0
  454. package/dist/core/storage/index.d.ts +16 -0
  455. package/dist/core/storage/index.d.ts.map +1 -0
  456. package/dist/core/storage/index.js +15 -0
  457. package/dist/core/storage/inventory.d.ts +25 -0
  458. package/dist/core/storage/inventory.d.ts.map +1 -0
  459. package/dist/core/storage/inventory.js +666 -0
  460. package/dist/core/storage/jsonl.d.ts +52 -0
  461. package/dist/core/storage/jsonl.d.ts.map +1 -0
  462. package/dist/core/storage/jsonl.js +156 -0
  463. package/dist/core/storage/log-retention.d.ts +52 -0
  464. package/dist/core/storage/log-retention.d.ts.map +1 -0
  465. package/dist/core/storage/log-retention.js +419 -0
  466. package/dist/core/storage/logger.d.ts +84 -0
  467. package/dist/core/storage/logger.d.ts.map +1 -0
  468. package/dist/core/storage/logger.js +413 -0
  469. package/dist/core/storage/maintenance-providers.d.ts +26 -0
  470. package/dist/core/storage/maintenance-providers.d.ts.map +1 -0
  471. package/dist/core/storage/maintenance-providers.js +141 -0
  472. package/dist/core/storage/maintenance.d.ts +125 -0
  473. package/dist/core/storage/maintenance.d.ts.map +1 -0
  474. package/dist/core/storage/maintenance.js +609 -0
  475. package/dist/core/storage/metrics.d.ts +60 -0
  476. package/dist/core/storage/metrics.d.ts.map +1 -0
  477. package/dist/core/storage/metrics.js +134 -0
  478. package/dist/core/storage/policy.d.ts +7 -0
  479. package/dist/core/storage/policy.d.ts.map +1 -0
  480. package/dist/core/storage/policy.js +110 -0
  481. package/dist/core/storage/process-log.d.ts +38 -0
  482. package/dist/core/storage/process-log.d.ts.map +1 -0
  483. package/dist/core/storage/process-log.js +165 -0
  484. package/dist/core/storage/query.d.ts +48 -0
  485. package/dist/core/storage/query.d.ts.map +1 -0
  486. package/dist/core/storage/query.js +346 -0
  487. package/dist/core/storage/receipts.d.ts +23 -0
  488. package/dist/core/storage/receipts.d.ts.map +1 -0
  489. package/dist/core/storage/receipts.js +117 -0
  490. package/dist/core/storage/segments.d.ts +84 -0
  491. package/dist/core/storage/segments.d.ts.map +1 -0
  492. package/dist/core/storage/segments.js +542 -0
  493. package/dist/core/storage/sink-graph.d.ts +65 -0
  494. package/dist/core/storage/sink-graph.d.ts.map +1 -0
  495. package/dist/core/storage/sink-graph.js +213 -0
  496. package/dist/core/storage/storm-control.d.ts +23 -0
  497. package/dist/core/storage/storm-control.d.ts.map +1 -0
  498. package/dist/core/storage/storm-control.js +59 -0
  499. package/dist/core/supervisor/activity.d.ts +4 -0
  500. package/dist/core/supervisor/activity.d.ts.map +1 -0
  501. package/dist/core/supervisor/activity.js +141 -0
  502. package/dist/core/supervisor/contract.d.ts +268 -0
  503. package/dist/core/supervisor/contract.d.ts.map +1 -0
  504. package/dist/core/supervisor/contract.js +35 -0
  505. package/dist/core/supervisor/explanations.d.ts +4 -0
  506. package/dist/core/supervisor/explanations.d.ts.map +1 -0
  507. package/dist/core/supervisor/explanations.js +71 -0
  508. package/dist/core/supervisor/findings.d.ts +20 -0
  509. package/dist/core/supervisor/findings.d.ts.map +1 -0
  510. package/dist/core/supervisor/findings.js +399 -0
  511. package/dist/core/supervisor/history.d.ts +9 -0
  512. package/dist/core/supervisor/history.d.ts.map +1 -0
  513. package/dist/core/supervisor/history.js +46 -0
  514. package/dist/core/supervisor/hook-health-alerts.d.ts +14 -0
  515. package/dist/core/supervisor/hook-health-alerts.d.ts.map +1 -0
  516. package/dist/core/supervisor/hook-health-alerts.js +70 -0
  517. package/dist/core/supervisor/hook-health-storage.d.ts +5 -0
  518. package/dist/core/supervisor/hook-health-storage.d.ts.map +1 -0
  519. package/dist/core/supervisor/hook-health-storage.js +24 -0
  520. package/dist/core/supervisor/hook-health.d.ts +72 -0
  521. package/dist/core/supervisor/hook-health.d.ts.map +1 -0
  522. package/dist/core/supervisor/hook-health.js +203 -0
  523. package/dist/core/supervisor/hooks.d.ts +10 -0
  524. package/dist/core/supervisor/hooks.d.ts.map +1 -0
  525. package/dist/core/supervisor/hooks.js +28 -0
  526. package/dist/core/supervisor/index.d.ts +15 -0
  527. package/dist/core/supervisor/index.d.ts.map +1 -0
  528. package/dist/core/supervisor/index.js +14 -0
  529. package/dist/core/supervisor/log-feed.d.ts +9 -0
  530. package/dist/core/supervisor/log-feed.d.ts.map +1 -0
  531. package/dist/core/supervisor/log-feed.js +103 -0
  532. package/dist/core/supervisor/service.d.ts +29 -0
  533. package/dist/core/supervisor/service.d.ts.map +1 -0
  534. package/dist/core/supervisor/service.js +450 -0
  535. package/dist/core/supervisor/services.d.ts +11 -0
  536. package/dist/core/supervisor/services.d.ts.map +1 -0
  537. package/dist/core/supervisor/services.js +155 -0
  538. package/dist/core/supervisor/status.d.ts +3 -0
  539. package/dist/core/supervisor/status.d.ts.map +1 -0
  540. package/dist/core/supervisor/status.js +48 -0
  541. package/dist/core/supervisor/storage.d.ts +30 -0
  542. package/dist/core/supervisor/storage.d.ts.map +1 -0
  543. package/dist/core/supervisor/storage.js +73 -0
  544. package/dist/core/supervisor/timeline.d.ts +3 -0
  545. package/dist/core/supervisor/timeline.d.ts.map +1 -0
  546. package/dist/core/supervisor/timeline.js +87 -0
  547. package/dist/core/work/state.d.ts.map +1 -1
  548. package/dist/core/work/state.js +10 -14
  549. package/dist/core/workflow/admission.d.ts +23 -0
  550. package/dist/core/workflow/admission.d.ts.map +1 -0
  551. package/dist/core/workflow/admission.js +136 -0
  552. package/dist/core/workflow/engine.d.ts.map +1 -1
  553. package/dist/core/workflow/engine.js +77 -2
  554. package/dist/core/workflow/index.d.ts +3 -2
  555. package/dist/core/workflow/index.d.ts.map +1 -1
  556. package/dist/core/workflow/index.js +2 -1
  557. package/dist/core/workflow/live-session-v3.d.ts.map +1 -1
  558. package/dist/core/workflow/live-session-v3.js +2 -1
  559. package/dist/core/workflow/proof.d.ts +2 -1
  560. package/dist/core/workflow/proof.d.ts.map +1 -1
  561. package/dist/core/workflow/proof.js +39 -1
  562. package/dist/core/workflow/run-state.d.ts +3 -2
  563. package/dist/core/workflow/run-state.d.ts.map +1 -1
  564. package/dist/core/workflow/run-state.js +8 -1
  565. package/dist/core/workflow/types.d.ts +33 -1
  566. package/dist/core/workflow/types.d.ts.map +1 -1
  567. package/dist/core/workflow/types.js +2 -1
  568. package/dist/index.d.ts +2 -0
  569. package/dist/index.d.ts.map +1 -1
  570. package/dist/index.js +2 -0
  571. package/dist/lazy-commands.d.ts +26 -0
  572. package/dist/lazy-commands.d.ts.map +1 -0
  573. package/dist/lazy-commands.js +210 -0
  574. package/dist/lib/browser/client.d.ts +5 -0
  575. package/dist/lib/browser/client.d.ts.map +1 -1
  576. package/dist/lib/browser/client.js +1 -0
  577. package/dist/lib/browser/index.d.ts +2 -0
  578. package/dist/lib/browser/index.d.ts.map +1 -1
  579. package/dist/lib/browser/index.js +2 -0
  580. package/dist/lib/browser/qa-run-contracts.d.ts +173 -0
  581. package/dist/lib/browser/qa-run-contracts.d.ts.map +1 -0
  582. package/dist/lib/browser/qa-run-contracts.js +226 -0
  583. package/dist/lib/browser/qa-run.d.ts +51 -0
  584. package/dist/lib/browser/qa-run.d.ts.map +1 -0
  585. package/dist/lib/browser/qa-run.js +684 -0
  586. package/dist/lib/coord-root-id.d.ts +9 -0
  587. package/dist/lib/coord-root-id.d.ts.map +1 -0
  588. package/dist/lib/coord-root-id.js +17 -0
  589. package/dist/lib/docs-lint.d.ts +2 -0
  590. package/dist/lib/docs-lint.d.ts.map +1 -1
  591. package/dist/lib/docs-lint.js +45 -80
  592. package/dist/lib/docs-metadata-audit.d.ts +3 -0
  593. package/dist/lib/docs-metadata-audit.d.ts.map +1 -1
  594. package/dist/lib/docs-metadata-audit.js +13 -23
  595. package/dist/lib/docs-metadata-sync.d.ts +1 -0
  596. package/dist/lib/docs-metadata-sync.d.ts.map +1 -1
  597. package/dist/lib/docs-metadata-sync.js +28 -10
  598. package/dist/lib/docs-repository-view.d.ts +22 -0
  599. package/dist/lib/docs-repository-view.d.ts.map +1 -0
  600. package/dist/lib/docs-repository-view.js +185 -0
  601. package/dist/lib/http/client.d.ts +11 -5
  602. package/dist/lib/http/client.d.ts.map +1 -1
  603. package/dist/lib/http/client.js +22 -4
  604. package/dist/lib/http/index.d.ts +1 -1
  605. package/dist/lib/http/index.d.ts.map +1 -1
  606. package/dist/lib/http/index.js +1 -1
  607. package/dist/lib/indexer-exclusions.d.ts +27 -0
  608. package/dist/lib/indexer-exclusions.d.ts.map +1 -0
  609. package/dist/lib/indexer-exclusions.js +176 -0
  610. package/dist/lib/instructions/apply.d.ts +3 -1
  611. package/dist/lib/instructions/apply.d.ts.map +1 -1
  612. package/dist/lib/instructions/apply.js +74 -3
  613. package/dist/lib/instructions/templates.d.ts.map +1 -1
  614. package/dist/lib/instructions/templates.js +11 -0
  615. package/dist/lib/local-file-url.d.ts +9 -0
  616. package/dist/lib/local-file-url.d.ts.map +1 -0
  617. package/dist/lib/local-file-url.js +20 -0
  618. package/dist/lib/web-performance.d.ts +118 -0
  619. package/dist/lib/web-performance.d.ts.map +1 -0
  620. package/dist/lib/web-performance.js +192 -0
  621. package/package.json +40 -2
  622. package/schemas/config.schema.json +58 -0
  623. package/schemas/event-v3.schema.json +324 -112
  624. package/src/commander.ts +488 -95
  625. package/src/commands/agents.ts +617 -237
  626. package/src/commands/artifacts.ts +40 -2
  627. package/src/commands/backup.ts +18 -14
  628. package/src/commands/browse-session.ts +12 -0
  629. package/src/commands/browse.ts +21 -7
  630. package/src/commands/conversations.ts +279 -0
  631. package/src/commands/deinit.ts +6 -0
  632. package/src/commands/diagnostics.ts +271 -0
  633. package/src/commands/docs.ts +25 -6
  634. package/src/commands/doctor.ts +75 -9
  635. package/src/commands/fetch.ts +7 -6
  636. package/src/commands/files.ts +243 -0
  637. package/src/commands/governor.ts +21 -12
  638. package/src/commands/inbox.ts +61 -0
  639. package/src/commands/init.ts +78 -16
  640. package/src/commands/ledger-v3.ts +503 -1
  641. package/src/commands/logs.ts +224 -0
  642. package/src/commands/messages.ts +61 -0
  643. package/src/commands/outline.ts +6 -2
  644. package/src/commands/qa-run.ts +184 -0
  645. package/src/commands/read.ts +6 -2
  646. package/src/commands/resources.ts +38 -0
  647. package/src/commands/semantic.ts +66 -1
  648. package/src/commands/storage.ts +310 -0
  649. package/src/commands/supervisor.ts +141 -0
  650. package/src/commands/tunnel.ts +66 -52
  651. package/src/commands/web.ts +96 -7
  652. package/src/commands/work.ts +3 -3
  653. package/src/commands/workflow.ts +21 -13
  654. package/src/core/agents/cli.ts +265 -55
  655. package/src/core/agents/health.ts +142 -0
  656. package/src/core/agents/live-authority-v3.ts +341 -10
  657. package/src/core/agents/live-lifecycle-v3.ts +6 -1
  658. package/src/core/agents/live-observation-v3.ts +6 -1
  659. package/src/core/agents/mailbox.ts +373 -0
  660. package/src/core/agents/reconcile-coordination-v3.ts +77 -0
  661. package/src/core/agents/render/prompt-context.ts +66 -15
  662. package/src/core/agents/render/session-context.ts +37 -3
  663. package/src/core/agents/rules/commit-conflict.ts +58 -1
  664. package/src/core/agents/rules/stop-hook.ts +105 -20
  665. package/src/core/agents/rules/verdict.ts +1 -0
  666. package/src/core/agents/session-events.ts +4 -0
  667. package/src/core/agents/session-finalization-state-v3.ts +1 -1
  668. package/src/core/agents/session-finalizer-v3.ts +8 -2
  669. package/src/core/agents/state/activity-log.ts +7 -2
  670. package/src/core/agents/state/heartbeat-writer.ts +27 -0
  671. package/src/core/agents/state/live-coordination-view.ts +16 -105
  672. package/src/core/agents/state/live-coordination-writer.ts +141 -0
  673. package/src/core/artifacts/index.ts +260 -11
  674. package/src/core/config.ts +235 -5
  675. package/src/core/conversations/archive.ts +237 -0
  676. package/src/core/conversations/catalog.ts +79 -0
  677. package/src/core/conversations/context-pack.ts +72 -0
  678. package/src/core/conversations/contract.ts +178 -0
  679. package/src/core/conversations/evaluation.ts +30 -0
  680. package/src/core/conversations/index.ts +9 -0
  681. package/src/core/conversations/lifecycle.ts +63 -0
  682. package/src/core/conversations/normalize.ts +105 -0
  683. package/src/core/conversations/query.ts +318 -0
  684. package/src/core/conversations/search-index.ts +48 -0
  685. package/src/core/diagnostics/advice.ts +147 -0
  686. package/src/core/diagnostics/bundle.ts +1142 -0
  687. package/src/core/diagnostics/comparison.ts +565 -0
  688. package/src/core/diagnostics/contract.ts +311 -0
  689. package/src/core/diagnostics/identity.ts +11 -0
  690. package/src/core/diagnostics/index.ts +7 -0
  691. package/src/core/diagnostics/replay.ts +314 -0
  692. package/src/core/diagnostics/sanitize.ts +97 -0
  693. package/src/core/events/legacy-storage/canary.ts +177 -0
  694. package/src/core/events/legacy-storage/compression.ts +130 -0
  695. package/src/core/events/legacy-storage/fence.ts +129 -0
  696. package/src/core/events/legacy-storage/index.ts +6 -0
  697. package/src/core/events/legacy-storage/inventory.ts +51 -0
  698. package/src/core/events/legacy-storage/manifest.ts +136 -0
  699. package/src/core/events/legacy-storage/reader.ts +178 -0
  700. package/src/core/events/v3/archive-retention.ts +251 -0
  701. package/src/core/events/v3/authority-outbox.ts +22 -1
  702. package/src/core/events/v3/base-contract.ts +17 -7
  703. package/src/core/events/v3/bootstrap.ts +195 -2
  704. package/src/core/events/v3/capabilities.ts +5 -3
  705. package/src/core/events/v3/control-witness.ts +339 -0
  706. package/src/core/events/v3/control-writer.ts +16 -0
  707. package/src/core/events/v3/control.ts +54 -18
  708. package/src/core/events/v3/coordination-transaction-recovery.ts +477 -0
  709. package/src/core/events/v3/coordination-view.ts +17 -1
  710. package/src/core/events/v3/generated.ts +1 -1
  711. package/src/core/events/v3/index.ts +14 -2
  712. package/src/core/events/v3/live-route-observer.ts +80 -0
  713. package/src/core/events/v3/live-routing.ts +65 -46
  714. package/src/core/events/v3/producers/coordination-recorder.ts +95 -10
  715. package/src/core/events/v3/producers/diagnostic-summaries.ts +593 -0
  716. package/src/core/events/v3/producers/hook-base.ts +15 -3
  717. package/src/core/events/v3/producers/intake.ts +31 -2
  718. package/src/core/events/v3/producers/producer-state-observer.ts +52 -0
  719. package/src/core/events/v3/producers/recorder.ts +681 -34
  720. package/src/core/events/v3/reader.ts +243 -2
  721. package/src/core/events/v3/rotation-config.ts +98 -0
  722. package/src/core/events/v3/runtime-build.ts +41 -0
  723. package/src/core/events/v3/runtime-identity.ts +16 -0
  724. package/src/core/events/v3/runtime-telemetry-capabilities.ts +14 -8
  725. package/src/core/events/v3/support-storage/classify.ts +209 -0
  726. package/src/core/events/v3/support-storage/eligibility.ts +58 -0
  727. package/src/core/events/v3/support-storage/index.ts +9 -0
  728. package/src/core/events/v3/support-storage/inventory.ts +135 -0
  729. package/src/core/events/v3/support-storage/logical-authority.ts +117 -0
  730. package/src/core/events/v3/support-storage/maintenance.ts +501 -0
  731. package/src/core/events/v3/support-storage/pack-contract.ts +337 -0
  732. package/src/core/events/v3/support-storage/pack-reader.ts +346 -0
  733. package/src/core/events/v3/support-storage/pack-writer.ts +352 -0
  734. package/src/core/events/v3/support-storage/recovery.ts +43 -0
  735. package/src/core/events/v3/turn-telemetry.ts +58 -7
  736. package/src/core/events/v3/writer.ts +168 -16
  737. package/src/core/governor/plan-read.ts +5 -18
  738. package/src/core/governor/planning.ts +5 -8
  739. package/src/core/governor/service-read.ts +320 -2
  740. package/src/core/governor/service.ts +49 -22
  741. package/src/core/guard/evidence-v3.ts +1 -0
  742. package/src/core/hooks/adapter/events.ts +1 -0
  743. package/src/core/hooks/adapter/output.ts +23 -5
  744. package/src/core/hooks/adapter/runtime-telemetry.ts +408 -13
  745. package/src/core/hooks/cli.ts +404 -233
  746. package/src/core/hooks/effects/image-capture.ts +4 -1
  747. package/src/core/hooks/health.ts +146 -0
  748. package/src/core/hooks/remediation-cap.ts +12 -6
  749. package/src/core/hooks/resolve/coord-root.ts +91 -11
  750. package/src/core/hooks/resolve/owner.ts +4 -0
  751. package/src/core/hooks/resolve/transcript.ts +18 -0
  752. package/src/core/inbox/contract.ts +81 -0
  753. package/src/core/inbox/index.ts +4 -0
  754. package/src/core/inbox/lifecycle.ts +104 -0
  755. package/src/core/inbox/service.ts +305 -0
  756. package/src/core/inbox/watcher.ts +36 -0
  757. package/src/core/presence/codec-digest.ts +15 -9
  758. package/src/core/presence/relay-client.ts +55 -7
  759. package/src/core/resources/contract.ts +98 -0
  760. package/src/core/resources/index.ts +5 -0
  761. package/src/core/resources/sampler.ts +458 -0
  762. package/src/core/resources/service-status.ts +62 -0
  763. package/src/core/resources/service.ts +337 -0
  764. package/src/core/resources/storage.ts +44 -0
  765. package/src/core/semantic/adapters.ts +200 -41
  766. package/src/core/semantic/contract.ts +135 -3
  767. package/src/core/semantic/index.ts +76 -2
  768. package/src/core/semantic/once.ts +93 -7
  769. package/src/core/semantic/prompt.ts +13 -1
  770. package/src/core/semantic/review.ts +803 -0
  771. package/src/core/semantic/routes.ts +30 -0
  772. package/src/core/semantic/scheduler.ts +49 -5
  773. package/src/core/semantic/service-status.ts +99 -5
  774. package/src/core/semantic/service.ts +116 -15
  775. package/src/core/semantic/soak.ts +638 -0
  776. package/src/core/semantic/storage.ts +20 -6
  777. package/src/core/semantic/usage.ts +272 -0
  778. package/src/core/semantic/validate.ts +31 -0
  779. package/src/core/storage/atomic-json.ts +15 -0
  780. package/src/core/storage/buffer.ts +124 -0
  781. package/src/core/storage/builtins.ts +972 -0
  782. package/src/core/storage/catalog.ts +467 -0
  783. package/src/core/storage/config.ts +423 -0
  784. package/src/core/storage/contract.ts +342 -0
  785. package/src/core/storage/durable-history.ts +738 -0
  786. package/src/core/storage/health.ts +76 -0
  787. package/src/core/storage/index.ts +15 -0
  788. package/src/core/storage/inventory.ts +859 -0
  789. package/src/core/storage/jsonl.ts +213 -0
  790. package/src/core/storage/log-retention.ts +555 -0
  791. package/src/core/storage/logger.ts +548 -0
  792. package/src/core/storage/maintenance-providers.ts +200 -0
  793. package/src/core/storage/maintenance.ts +929 -0
  794. package/src/core/storage/metrics.ts +199 -0
  795. package/src/core/storage/policy.ts +141 -0
  796. package/src/core/storage/process-log.ts +203 -0
  797. package/src/core/storage/query.ts +418 -0
  798. package/src/core/storage/receipts.ts +162 -0
  799. package/src/core/storage/segments.ts +721 -0
  800. package/src/core/storage/sink-graph.ts +343 -0
  801. package/src/core/storage/storm-control.ts +91 -0
  802. package/src/core/supervisor/activity.ts +193 -0
  803. package/src/core/supervisor/contract.ts +312 -0
  804. package/src/core/supervisor/explanations.ts +104 -0
  805. package/src/core/supervisor/findings.ts +788 -0
  806. package/src/core/supervisor/history.ts +61 -0
  807. package/src/core/supervisor/hook-health-alerts.ts +108 -0
  808. package/src/core/supervisor/hook-health-storage.ts +25 -0
  809. package/src/core/supervisor/hook-health.ts +301 -0
  810. package/src/core/supervisor/hooks.ts +35 -0
  811. package/src/core/supervisor/index.ts +14 -0
  812. package/src/core/supervisor/log-feed.ts +131 -0
  813. package/src/core/supervisor/service.ts +511 -0
  814. package/src/core/supervisor/services.ts +203 -0
  815. package/src/core/supervisor/status.ts +59 -0
  816. package/src/core/supervisor/storage.ts +126 -0
  817. package/src/core/supervisor/timeline.ts +133 -0
  818. package/src/core/work/state.ts +12 -21
  819. package/src/core/workflow/admission.ts +215 -0
  820. package/src/core/workflow/engine.ts +93 -1
  821. package/src/core/workflow/index.ts +10 -0
  822. package/src/core/workflow/live-session-v3.ts +2 -4
  823. package/src/core/workflow/proof.ts +54 -1
  824. package/src/core/workflow/run-state.ts +13 -1
  825. package/src/core/workflow/types.ts +39 -1
  826. package/src/index.ts +2 -0
  827. package/src/lazy-commands.ts +294 -0
  828. package/src/lib/browser/client.ts +6 -0
  829. package/src/lib/browser/index.ts +29 -0
  830. package/src/lib/browser/qa-run-contracts.ts +380 -0
  831. package/src/lib/browser/qa-run.ts +784 -0
  832. package/src/lib/coord-root-id.ts +23 -0
  833. package/src/lib/docs-lint.ts +58 -77
  834. package/src/lib/docs-metadata-audit.ts +26 -21
  835. package/src/lib/docs-metadata-sync.ts +32 -9
  836. package/src/lib/docs-repository-view.ts +220 -0
  837. package/src/lib/http/client.ts +44 -8
  838. package/src/lib/http/index.ts +6 -1
  839. package/src/lib/indexer-exclusions.ts +173 -0
  840. package/src/lib/instructions/apply.ts +81 -2
  841. package/src/lib/instructions/templates.ts +11 -0
  842. package/src/lib/local-file-url.ts +31 -0
  843. package/src/lib/web-performance.ts +335 -0
@@ -0,0 +1,136 @@
1
+ export interface LegacyV1SegmentManifest {
2
+ format: "harnery-legacy-v1-segment";
3
+ format_version: 1;
4
+ segment_id: `v1s_${string}`;
5
+ source: {
6
+ filename: string;
7
+ bytes: number;
8
+ digest: `sha256:${string}`;
9
+ row_count: number;
10
+ minimum_recorded_at: string | null;
11
+ maximum_recorded_at: string | null;
12
+ };
13
+ payload: {
14
+ algorithm: "gzip";
15
+ path: string;
16
+ bytes: number;
17
+ digest: `sha256:${string}`;
18
+ };
19
+ minimum_harnery_version: string;
20
+ created_at: string;
21
+ }
22
+
23
+ export function validateLegacyV1SegmentManifest(value: unknown): LegacyV1SegmentManifest {
24
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
25
+ throw new Error("legacy_v1_manifest_invalid");
26
+ }
27
+ const manifest = value as Record<string, unknown>;
28
+ exact(manifest, [
29
+ "format",
30
+ "format_version",
31
+ "segment_id",
32
+ "source",
33
+ "payload",
34
+ "minimum_harnery_version",
35
+ "created_at",
36
+ ]);
37
+ if (manifest.format !== "harnery-legacy-v1-segment" || manifest.format_version !== 1) {
38
+ throw new Error("legacy_v1_manifest_version_unsupported");
39
+ }
40
+ const segmentId = text(manifest.segment_id);
41
+ if (!/^v1s_[0-9a-f]{32}$/.test(segmentId)) throw new Error("legacy_v1_segment_id_invalid");
42
+ const source = object(manifest.source);
43
+ exact(source, [
44
+ "filename",
45
+ "bytes",
46
+ "digest",
47
+ "row_count",
48
+ "minimum_recorded_at",
49
+ "maximum_recorded_at",
50
+ ]);
51
+ const filename = text(source.filename);
52
+ if (!/^events.+\.ndjson$/.test(filename) || filename.includes("/") || filename.includes("\\")) {
53
+ throw new Error("legacy_v1_source_filename_invalid");
54
+ }
55
+ const minimum = nullableTimestamp(source.minimum_recorded_at);
56
+ const maximum = nullableTimestamp(source.maximum_recorded_at);
57
+ if ((minimum === null) !== (maximum === null) || (minimum && maximum && minimum > maximum)) {
58
+ throw new Error("legacy_v1_manifest_time_range_invalid");
59
+ }
60
+ const payload = object(manifest.payload);
61
+ exact(payload, ["algorithm", "path", "bytes", "digest"]);
62
+ if (payload.algorithm !== "gzip" || payload.path !== `${segmentId}.ndjson.gz`) {
63
+ throw new Error("legacy_v1_payload_contract_invalid");
64
+ }
65
+ const version = text(manifest.minimum_harnery_version);
66
+ if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version)) {
67
+ throw new Error("legacy_v1_minimum_version_invalid");
68
+ }
69
+ return {
70
+ format: "harnery-legacy-v1-segment",
71
+ format_version: 1,
72
+ segment_id: segmentId as `v1s_${string}`,
73
+ source: {
74
+ filename,
75
+ bytes: integer(source.bytes),
76
+ digest: digest(source.digest),
77
+ row_count: integer(source.row_count),
78
+ minimum_recorded_at: minimum,
79
+ maximum_recorded_at: maximum,
80
+ },
81
+ payload: {
82
+ algorithm: "gzip",
83
+ path: text(payload.path),
84
+ bytes: integer(payload.bytes),
85
+ digest: digest(payload.digest),
86
+ },
87
+ minimum_harnery_version: version,
88
+ created_at: timestamp(manifest.created_at),
89
+ };
90
+ }
91
+
92
+ function object(value: unknown): Record<string, unknown> {
93
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
94
+ throw new Error("legacy_v1_manifest_object_invalid");
95
+ }
96
+ return value as Record<string, unknown>;
97
+ }
98
+
99
+ function exact(value: Record<string, unknown>, keys: string[]): void {
100
+ if (Object.keys(value).sort().join("\0") !== [...keys].sort().join("\0")) {
101
+ throw new Error("legacy_v1_manifest_unknown_field");
102
+ }
103
+ }
104
+
105
+ function text(value: unknown): string {
106
+ if (typeof value !== "string") throw new Error("legacy_v1_manifest_string_invalid");
107
+ return value;
108
+ }
109
+
110
+ function integer(value: unknown): number {
111
+ if (!Number.isSafeInteger(value) || (value as number) < 0) {
112
+ throw new Error("legacy_v1_manifest_integer_invalid");
113
+ }
114
+ return value as number;
115
+ }
116
+
117
+ function digest(value: unknown): `sha256:${string}` {
118
+ const result = text(value);
119
+ if (!/^sha256:[0-9a-f]{64}$/.test(result)) throw new Error("legacy_v1_manifest_digest_invalid");
120
+ return result as `sha256:${string}`;
121
+ }
122
+
123
+ function timestamp(value: unknown): string {
124
+ const result = text(value);
125
+ if (
126
+ !/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{3}Z$/.test(result) ||
127
+ !Number.isFinite(Date.parse(result))
128
+ ) {
129
+ throw new Error("legacy_v1_manifest_timestamp_invalid");
130
+ }
131
+ return result;
132
+ }
133
+
134
+ function nullableTimestamp(value: unknown): string | null {
135
+ return value === null ? null : timestamp(value);
136
+ }
@@ -0,0 +1,178 @@
1
+ import { createHash } from "node:crypto";
2
+ import { constants, createReadStream } from "node:fs";
3
+ import { lstat, open, realpath } from "node:fs/promises";
4
+ import { dirname, isAbsolute, relative, resolve } from "node:path";
5
+ import { createGunzip } from "node:zlib";
6
+ import { type LegacyV1SegmentManifest, validateLegacyV1SegmentManifest } from "./manifest.ts";
7
+
8
+ export interface LegacyV1LogicalRow {
9
+ row_number: number;
10
+ bytes: Buffer;
11
+ }
12
+
13
+ export interface LegacyV1ReaderLimits {
14
+ max_manifest_bytes?: number;
15
+ max_payload_bytes?: number;
16
+ max_decompressed_bytes?: number;
17
+ max_row_bytes?: number;
18
+ max_rows?: number;
19
+ fault?: (boundary: "after_source_digest", path: string) => void;
20
+ }
21
+
22
+ const DEFAULTS: Required<Omit<LegacyV1ReaderLimits, "fault">> = {
23
+ max_manifest_bytes: 1024 * 1024,
24
+ max_payload_bytes: 8 * 1024 * 1024 * 1024,
25
+ max_decompressed_bytes: 16 * 1024 * 1024 * 1024,
26
+ max_row_bytes: 64 * 1024 * 1024,
27
+ max_rows: 20_000_000,
28
+ };
29
+
30
+ /** Stream rows from one loose sealed segment or one manifest-bound gzip canary. */
31
+ export async function* streamLegacyV1Rows(
32
+ sourcePath: string,
33
+ limits: LegacyV1ReaderLimits = {},
34
+ ): AsyncGenerator<LegacyV1LogicalRow> {
35
+ const bounded = { ...DEFAULTS, ...limits };
36
+ const source = resolve(sourcePath);
37
+ let input = source;
38
+ let expectedRows: number | undefined;
39
+ let expectedSourceBytes: number | undefined;
40
+ let expectedSourceDigest: `sha256:${string}` | undefined;
41
+ let expectedPayloadBytes: number | undefined;
42
+ let expectedPayloadDigest: `sha256:${string}` | undefined;
43
+ let containmentRoot: string | undefined;
44
+ if (source.endsWith(".manifest.json")) {
45
+ const manifestHandle = await openStableRegularFile(source, undefined, "manifest");
46
+ let manifest: LegacyV1SegmentManifest;
47
+ try {
48
+ const stat = await manifestHandle.stat();
49
+ if (stat.size > bounded.max_manifest_bytes) throw new Error("legacy_v1_manifest_too_large");
50
+ manifest = validateLegacyV1SegmentManifest(
51
+ JSON.parse(await manifestHandle.readFile("utf8")) as unknown,
52
+ );
53
+ } finally {
54
+ await manifestHandle.close();
55
+ }
56
+ const directory = await realpath(dirname(source));
57
+ containmentRoot = directory;
58
+ input = resolve(directory, manifest.payload.path);
59
+ expectedRows = manifest.source.row_count;
60
+ expectedSourceBytes = manifest.source.bytes;
61
+ expectedSourceDigest = manifest.source.digest;
62
+ expectedPayloadBytes = manifest.payload.bytes;
63
+ expectedPayloadDigest = manifest.payload.digest;
64
+ }
65
+
66
+ const compressed = source.endsWith(".manifest.json") || source.endsWith(".gz");
67
+ const kind = source.endsWith(".manifest.json") ? "payload" : "segment";
68
+ const inputHandle = await openStableRegularFile(input, containmentRoot, kind);
69
+ try {
70
+ const inputStat = await inputHandle.stat();
71
+ if (source.endsWith(".manifest.json")) {
72
+ if (inputStat.size !== expectedPayloadBytes)
73
+ throw new Error("legacy_v1_payload_length_mismatch");
74
+ if (inputStat.size > bounded.max_payload_bytes)
75
+ throw new Error("legacy_v1_payload_too_large");
76
+ if ((await hashHandle(input, inputHandle)) !== expectedPayloadDigest) {
77
+ throw new Error("legacy_v1_payload_digest_mismatch");
78
+ }
79
+ }
80
+ limits.fault?.("after_source_digest", input);
81
+ const file = createReadStream(input, { fd: inputHandle.fd, autoClose: false, start: 0 });
82
+ const stream = compressed ? file.pipe(createGunzip()) : file;
83
+ let pending: Buffer<ArrayBufferLike> = Buffer.alloc(0);
84
+ let rows = 0;
85
+ let decompressed = 0;
86
+ const sourceHash = createHash("sha256");
87
+ for await (const current of stream) {
88
+ const chunk = current as Buffer;
89
+ decompressed += chunk.length;
90
+ sourceHash.update(chunk);
91
+ if (decompressed > bounded.max_decompressed_bytes) {
92
+ throw new Error("legacy_v1_decompression_bound_exceeded");
93
+ }
94
+ pending = pending.length === 0 ? chunk : Buffer.concat([pending, chunk]);
95
+ if (pending.length > bounded.max_row_bytes && !pending.includes(0x0a)) {
96
+ throw new Error("legacy_v1_row_bound_exceeded");
97
+ }
98
+ let newline = pending.indexOf(0x0a);
99
+ while (newline >= 0) {
100
+ const row = pending.subarray(0, newline);
101
+ pending = pending.subarray(newline + 1);
102
+ if (row.length === 0) throw new Error("legacy_v1_empty_row");
103
+ if (row.length > bounded.max_row_bytes) throw new Error("legacy_v1_row_bound_exceeded");
104
+ rows += 1;
105
+ if (rows > bounded.max_rows) throw new Error("legacy_v1_row_count_bound_exceeded");
106
+ yield { row_number: rows, bytes: Buffer.from(row) };
107
+ newline = pending.indexOf(0x0a);
108
+ }
109
+ }
110
+ if (pending.length !== 0) throw new Error("legacy_v1_segment_unterminated_or_truncated");
111
+ if (expectedRows !== undefined && rows !== expectedRows)
112
+ throw new Error("legacy_v1_row_count_mismatch");
113
+ if (expectedSourceBytes !== undefined && decompressed !== expectedSourceBytes) {
114
+ throw new Error("legacy_v1_source_length_mismatch");
115
+ }
116
+ const digest = `sha256:${sourceHash.digest("hex")}`;
117
+ if (expectedSourceDigest !== undefined && digest !== expectedSourceDigest) {
118
+ throw new Error("legacy_v1_source_digest_mismatch");
119
+ }
120
+ } finally {
121
+ await inputHandle.close();
122
+ }
123
+ }
124
+
125
+ async function hashHandle(
126
+ path: string,
127
+ handle: Awaited<ReturnType<typeof open>>,
128
+ ): Promise<`sha256:${string}`> {
129
+ const hash = createHash("sha256");
130
+ const stream = createReadStream(path, { fd: handle.fd, autoClose: false, start: 0 });
131
+ for await (const current of stream) hash.update(current as Buffer);
132
+ return `sha256:${hash.digest("hex")}`;
133
+ }
134
+
135
+ async function openStableRegularFile(
136
+ path: string,
137
+ containmentRoot: string | undefined,
138
+ kind: "manifest" | "payload" | "segment",
139
+ ) {
140
+ const before = await lstat(path);
141
+ if (!before.isFile() || before.isSymbolicLink()) throw new Error(`legacy_v1_${kind}_not_regular`);
142
+ const beforeReal = await realpath(path);
143
+ if (containmentRoot) assertContained(containmentRoot, beforeReal);
144
+ const handle = await open(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
145
+ try {
146
+ const opened = await handle.stat();
147
+ const after = await lstat(path);
148
+ const afterReal = await realpath(path);
149
+ if (
150
+ !opened.isFile() ||
151
+ !after.isFile() ||
152
+ after.isSymbolicLink() ||
153
+ opened.dev !== before.dev ||
154
+ opened.ino !== before.ino ||
155
+ opened.dev !== after.dev ||
156
+ opened.ino !== after.ino ||
157
+ beforeReal !== afterReal
158
+ )
159
+ throw new Error(`legacy_v1_${kind}_changed_during_open`);
160
+ if (containmentRoot) assertContained(containmentRoot, afterReal);
161
+ return handle;
162
+ } catch (error) {
163
+ await handle.close();
164
+ throw error;
165
+ }
166
+ }
167
+
168
+ function assertContained(root: string, candidate: string): void {
169
+ const path = relative(root, candidate);
170
+ if (
171
+ path === "" ||
172
+ (path !== ".." &&
173
+ !path.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) &&
174
+ !isAbsolute(path))
175
+ )
176
+ return;
177
+ throw new Error("legacy_v1_payload_escape");
178
+ }
@@ -0,0 +1,251 @@
1
+ /** Bounded retention for complete, closed Event Ledger V3 epochs. */
2
+
3
+ import {
4
+ existsSync,
5
+ lstatSync,
6
+ mkdirSync,
7
+ readdirSync,
8
+ readFileSync,
9
+ rmSync,
10
+ writeFileSync,
11
+ } from "node:fs";
12
+ import { basename, join, relative, resolve } from "node:path";
13
+ import {
14
+ artifactAutoCleanIntervalHours,
15
+ type EventLedgerArchivePolicy,
16
+ eventLedgerArchivePolicy,
17
+ } from "../../config.ts";
18
+
19
+ export type EventV3ArchiveClassification =
20
+ | "retained"
21
+ | "expired"
22
+ | "over-budget"
23
+ | "protected-minimum"
24
+ | "unmanaged"
25
+ | "symlink"
26
+ | "unknown";
27
+
28
+ export interface EventV3ArchiveEntry {
29
+ name: string;
30
+ path: string;
31
+ relative_path: string;
32
+ classification: EventV3ArchiveClassification;
33
+ reason: string;
34
+ action: "keep" | "would-delete" | "deleted";
35
+ bytes: number | null;
36
+ last_modified_at: string | null;
37
+ }
38
+
39
+ export interface EventV3ArchiveAutoCleanResult {
40
+ ran: boolean;
41
+ reason: "swept" | "disabled" | "fresh" | "no-root";
42
+ deleted: number;
43
+ bytes: number;
44
+ }
45
+
46
+ const ARCHIVE_PATTERN = /^epoch-[0-9]+(?:-[0-9]+)?$/;
47
+ const AUTO_CLEAN_STAMP = ".harnery/event-v3-archive-auto-clean.json";
48
+
49
+ export function eventV3ArchivesRoot(repoRoot: string): string {
50
+ return join(resolve(repoRoot), ".harnery", "ledgers", "v3-archives");
51
+ }
52
+
53
+ export function inventoryEventV3Archives(
54
+ repoRoot: string,
55
+ opts: { now?: Date; policy?: EventLedgerArchivePolicy } = {},
56
+ ): EventV3ArchiveEntry[] {
57
+ const root = eventV3ArchivesRoot(repoRoot);
58
+ if (!existsSync(root)) return [];
59
+ const now = opts.now ?? new Date();
60
+ const policy = opts.policy ?? eventLedgerArchivePolicy(repoRoot);
61
+ const rows = readdirSync(root)
62
+ .sort()
63
+ .map((name) => classifyArchive(repoRoot, join(root, name)));
64
+ const managed = rows.filter(
65
+ (row) => row.classification === "retained" && row.bytes !== null && row.last_modified_at,
66
+ );
67
+ const newestFirst = [...managed].sort((left, right) => right.name.localeCompare(left.name));
68
+ const protectedNames = new Set(newestFirst.slice(0, policy.keepMin).map((row) => row.name));
69
+ const cutoff = now.getTime() - policy.maxAgeDays * 24 * 60 * 60 * 1000;
70
+
71
+ for (const row of managed) {
72
+ if (protectedNames.has(row.name)) {
73
+ row.classification = "protected-minimum";
74
+ row.reason = `one of the newest ${policy.keepMin} complete epochs`;
75
+ continue;
76
+ }
77
+ if (Date.parse(row.last_modified_at!) <= cutoff) {
78
+ row.classification = "expired";
79
+ row.reason = `closed epoch is older than ${policy.maxAgeDays} days`;
80
+ row.action = "would-delete";
81
+ }
82
+ }
83
+
84
+ let retainedBytes = managed.reduce((sum, row) => sum + (row.bytes ?? 0), 0);
85
+ retainedBytes -= managed.reduce(
86
+ (sum, row) => sum + (row.action === "would-delete" ? (row.bytes ?? 0) : 0),
87
+ 0,
88
+ );
89
+ const budgetCandidates = managed
90
+ .filter((row) => row.classification === "retained")
91
+ .sort((left, right) => left.name.localeCompare(right.name));
92
+ for (const row of budgetCandidates) {
93
+ if (retainedBytes <= policy.maxBytes) break;
94
+ row.classification = "over-budget";
95
+ row.reason = `closed-epoch budget is ${policy.maxBytes} bytes; oldest epochs are removed first`;
96
+ row.action = "would-delete";
97
+ retainedBytes -= row.bytes ?? 0;
98
+ }
99
+ return rows;
100
+ }
101
+
102
+ export function cleanEventV3Archives(
103
+ repoRoot: string,
104
+ opts: { yes?: boolean; now?: Date; policy?: EventLedgerArchivePolicy } = {},
105
+ ): EventV3ArchiveEntry[] {
106
+ const rows = inventoryEventV3Archives(repoRoot, opts);
107
+ if (!opts.yes) return rows;
108
+ return rows.map((entry) => {
109
+ if (entry.action !== "would-delete") return entry;
110
+ const current = inventoryEventV3Archives(repoRoot, opts).find((row) => row.path === entry.path);
111
+ if (!current) {
112
+ return { ...entry, classification: "unknown", reason: "entry disappeared", action: "keep" };
113
+ }
114
+ if (
115
+ current.action !== "would-delete" ||
116
+ current.bytes !== entry.bytes ||
117
+ current.last_modified_at !== entry.last_modified_at
118
+ ) {
119
+ return current;
120
+ }
121
+ try {
122
+ const stat = lstatSync(current.path);
123
+ if (!stat.isDirectory() || stat.isSymbolicLink() || !ARCHIVE_PATTERN.test(current.name)) {
124
+ return {
125
+ ...current,
126
+ classification: "unknown",
127
+ reason: "entry changed before deletion",
128
+ action: "keep",
129
+ };
130
+ }
131
+ rmSync(current.path, { recursive: true, force: false });
132
+ return { ...current, action: "deleted" };
133
+ } catch (error) {
134
+ return {
135
+ ...current,
136
+ classification: "unknown",
137
+ reason: `entry changed or could not be deleted: ${error instanceof Error ? error.message : String(error)}`,
138
+ action: "keep",
139
+ };
140
+ }
141
+ });
142
+ }
143
+
144
+ export function autoCleanEventV3Archives(
145
+ repoRoot: string,
146
+ opts: { now?: Date } = {},
147
+ ): EventV3ArchiveAutoCleanResult {
148
+ const now = opts.now ?? new Date();
149
+ const root = eventV3ArchivesRoot(repoRoot);
150
+ if (!existsSync(root)) return { ran: false, reason: "no-root", deleted: 0, bytes: 0 };
151
+ const policy = eventLedgerArchivePolicy(repoRoot);
152
+ if (!policy.autoClean) return { ran: false, reason: "disabled", deleted: 0, bytes: 0 };
153
+ const stampPath = join(resolve(repoRoot), AUTO_CLEAN_STAMP);
154
+ const intervalMs = artifactAutoCleanIntervalHours() * 60 * 60 * 1000;
155
+ try {
156
+ const stamp = JSON.parse(readFileSync(stampPath, "utf8")) as { last_run_at?: string };
157
+ const last = Date.parse(stamp.last_run_at ?? "");
158
+ if (Number.isFinite(last) && now.getTime() - last < intervalMs) {
159
+ return { ran: false, reason: "fresh", deleted: 0, bytes: 0 };
160
+ }
161
+ } catch {
162
+ // Missing or unreadable stamp: sweep now.
163
+ }
164
+ mkdirSync(join(resolve(repoRoot), ".harnery"), { recursive: true });
165
+ writeFileSync(stampPath, `${JSON.stringify({ last_run_at: now.toISOString() }, null, 2)}\n`);
166
+ const rows = cleanEventV3Archives(repoRoot, { yes: true, now, policy });
167
+ const deletedRows = rows.filter((row) => row.action === "deleted");
168
+ const result = {
169
+ ran: true as const,
170
+ reason: "swept" as const,
171
+ deleted: deletedRows.length,
172
+ bytes: deletedRows.reduce((sum, row) => sum + (row.bytes ?? 0), 0),
173
+ };
174
+ writeFileSync(
175
+ stampPath,
176
+ `${JSON.stringify({ last_run_at: now.toISOString(), ...result }, null, 2)}\n`,
177
+ );
178
+ return result;
179
+ }
180
+
181
+ function classifyArchive(repoRoot: string, path: string): EventV3ArchiveEntry {
182
+ const name = basename(path);
183
+ const base: EventV3ArchiveEntry = {
184
+ name,
185
+ path,
186
+ relative_path: relative(repoRoot, path),
187
+ classification: "retained",
188
+ reason: "closed epoch is inside the retention window",
189
+ action: "keep",
190
+ bytes: null,
191
+ last_modified_at: null,
192
+ };
193
+ try {
194
+ const stat = lstatSync(path);
195
+ if (stat.isSymbolicLink()) {
196
+ return {
197
+ ...base,
198
+ classification: "symlink",
199
+ reason: "symlinks are never traversed or deleted",
200
+ bytes: stat.size,
201
+ };
202
+ }
203
+ if (!stat.isDirectory() || !ARCHIVE_PATTERN.test(name)) {
204
+ return {
205
+ ...base,
206
+ classification: "unmanaged",
207
+ reason: "entry is not a complete named epoch",
208
+ };
209
+ }
210
+ const measured = measureTree(path);
211
+ if (!measured) {
212
+ return {
213
+ ...base,
214
+ classification: "unknown",
215
+ reason: "one or more epoch paths are unreadable",
216
+ };
217
+ }
218
+ return {
219
+ ...base,
220
+ bytes: measured.bytes,
221
+ last_modified_at: new Date(measured.lastModifiedMs).toISOString(),
222
+ };
223
+ } catch (error) {
224
+ return {
225
+ ...base,
226
+ classification: "unknown",
227
+ reason: `cannot inspect archive: ${error instanceof Error ? error.message : String(error)}`,
228
+ };
229
+ }
230
+ }
231
+
232
+ function measureTree(path: string): { bytes: number; lastModifiedMs: number } | null {
233
+ try {
234
+ const stat = lstatSync(path);
235
+ if (stat.isSymbolicLink() || stat.isFile()) {
236
+ return { bytes: stat.size, lastModifiedMs: stat.mtimeMs };
237
+ }
238
+ if (!stat.isDirectory()) return { bytes: 0, lastModifiedMs: stat.mtimeMs };
239
+ let bytes = stat.size;
240
+ let lastModifiedMs = stat.mtimeMs;
241
+ for (const child of readdirSync(path)) {
242
+ const measured = measureTree(join(path, child));
243
+ if (!measured) return null;
244
+ bytes += measured.bytes;
245
+ lastModifiedMs = Math.max(lastModifiedMs, measured.lastModifiedMs);
246
+ }
247
+ return { bytes, lastModifiedMs };
248
+ } catch {
249
+ return null;
250
+ }
251
+ }
@@ -14,9 +14,15 @@ import { join } from "node:path";
14
14
  import { fsyncParentDirectory } from "../../workflow/durable-record.ts";
15
15
  import { canonicalJsonV3, sha256V3 } from "./canonical.ts";
16
16
  import type { EventV3 } from "./contract.ts";
17
+ import { liveGenesisIdV3 } from "./control.ts";
17
18
  import { assertEventV3 } from "./validate.ts";
18
19
  import { ensureEventV3Layout, eventV3Paths, writeEventV3 } from "./writer.ts";
19
20
 
21
+ export interface AuthorityEpochFenceV3 {
22
+ /** Genesis id of the epoch the transaction's event was produced for. */
23
+ expectedGenesisId?: `gex_${string}`;
24
+ }
25
+
20
26
  const SHA256_PATTERN = /^sha256:[a-f0-9]{64}$/;
21
27
  const INSTANCE_PATTERN = /^inst_[a-zA-Z0-9._-]{1,128}$/;
22
28
  const TX_PATTERN = /^txn_[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
@@ -146,9 +152,13 @@ export function buildAuthorityTransactionV3(
146
152
  export function publishAuthorityTransactionV3(
147
153
  coordRoot: string,
148
154
  transaction: AuthorityTransactionV3,
155
+ fence: AuthorityEpochFenceV3 = {},
149
156
  ): AuthorityTransactionV3 {
150
157
  validateTransaction(transaction);
151
158
  const paths = ensureEventV3Layout(coordRoot);
159
+ if (fence.expectedGenesisId && liveGenesisIdV3(coordRoot) !== fence.expectedGenesisId) {
160
+ throw new Error("authority transaction epoch was replaced before publication");
161
+ }
152
162
  const readyPath = authorityReadyPath(paths.authorityOutbox, transaction.transaction_id);
153
163
  const serialized = `${canonicalJsonV3(transaction)}\n`;
154
164
  if (existsSync(readyPath)) {
@@ -173,6 +183,7 @@ export function reconcileAuthorityTransactionV3(
173
183
  coordRoot: string,
174
184
  transactionId: string,
175
185
  reconciler: AuthorityReconcilerV3,
186
+ fence: AuthorityEpochFenceV3 = {},
176
187
  ): AuthorityReceiptV3 {
177
188
  assertTransactionId(transactionId);
178
189
  const paths = ensureEventV3Layout(coordRoot);
@@ -191,7 +202,12 @@ export function reconcileAuthorityTransactionV3(
191
202
  }
192
203
  const event = JSON.parse(transaction.event_row) as unknown;
193
204
  assertEventV3(event);
194
- writeEventV3(coordRoot, event);
205
+ const durability = writeEventV3(coordRoot, event, {
206
+ ...(fence.expectedGenesisId ? { expectedGenesisId: fence.expectedGenesisId } : {}),
207
+ });
208
+ if (durability.state === "epoch_replaced") {
209
+ throw new Error("authority transaction epoch was replaced before its event committed");
210
+ }
195
211
  const receipt: AuthorityReceiptV3 = {
196
212
  format: "harnery-event-v3-authority-receipt",
197
213
  format_version: 1,
@@ -222,6 +238,11 @@ export function listPendingAuthorityTransactionsV3(coordRoot: string): Authority
222
238
  .map((name) => readAuthorityTransactionV3(join(outbox, name)));
223
239
  }
224
240
 
241
+ export function authorityRecoveryIntentPathV3(coordRoot: string, transactionId: string): string {
242
+ assertTransactionId(transactionId);
243
+ return join(eventV3Paths(coordRoot).root, "authority-recoveries", `${transactionId}.ready.json`);
244
+ }
245
+
225
246
  export function readAuthorityTransactionV3(path: string): AuthorityTransactionV3 {
226
247
  const serialized = readFileSync(path, "utf8");
227
248
  let parsed: unknown;
@@ -109,6 +109,8 @@ const RuntimeTelemetryCapabilityValueV3BaseSchema = StrictObject({
109
109
  source: SafeToken,
110
110
  completeness: Type.Union([
111
111
  Type.Literal("exact"),
112
+ Type.Literal("inferred"),
113
+ Type.Literal("percentage_only"),
112
114
  Type.Literal("lower_bound"),
113
115
  Type.Literal("unknown"),
114
116
  ]),
@@ -430,13 +432,21 @@ const AuthorityReferenceSchema = StrictObject({
430
432
  record_id: Type.Optional(SafeToken),
431
433
  });
432
434
 
433
- const MeasurementSchema = StrictObject({
434
- used_tokens: Type.Integer({ minimum: 0 }),
435
- limit_tokens: Type.Integer({ minimum: 1 }),
436
- remaining_tokens: Type.Optional(Type.Integer({ minimum: 0 })),
437
- measured_at: Timestamp,
438
- method: SafeToken,
439
- });
435
+ const MeasurementSchema = Type.Union([
436
+ StrictObject({
437
+ used_tokens: Type.Integer({ minimum: 0 }),
438
+ limit_tokens: Type.Integer({ minimum: 1 }),
439
+ remaining_tokens: Type.Optional(Type.Integer({ minimum: 0 })),
440
+ measured_at: Timestamp,
441
+ method: SafeToken,
442
+ }),
443
+ StrictObject({
444
+ used_percent: Type.Number({ minimum: 0, maximum: 100 }),
445
+ remaining_percent: Type.Optional(Type.Number({ minimum: 0, maximum: 100 })),
446
+ measured_at: Timestamp,
447
+ method: SafeToken,
448
+ }),
449
+ ]);
440
450
 
441
451
  const ArtifactReferenceSchema = StrictObject({
442
452
  artifact_id: Type.String({ pattern: "^art_[a-zA-Z0-9._-]{1,128}$" }),