@saihm/shm 0.0.0-stage → 0.38.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (672) hide show
  1. package/LICENSE +97 -0
  2. package/NOTICE +12 -0
  3. package/README.md +159 -2
  4. package/dist/adapter/epoch.d.ts +4 -0
  5. package/dist/adapter/epoch.d.ts.map +1 -0
  6. package/dist/adapter/epoch.js +16 -0
  7. package/dist/adapter/epoch.js.map +1 -0
  8. package/dist/adapter/frontmatter.d.ts +19 -0
  9. package/dist/adapter/frontmatter.d.ts.map +1 -0
  10. package/dist/adapter/frontmatter.js +95 -0
  11. package/dist/adapter/frontmatter.js.map +1 -0
  12. package/dist/adapter/index.d.ts +4 -0
  13. package/dist/adapter/index.d.ts.map +1 -0
  14. package/dist/adapter/index.js +4 -0
  15. package/dist/adapter/index.js.map +1 -0
  16. package/dist/adapter/markdown_dir_port.d.ts +48 -0
  17. package/dist/adapter/markdown_dir_port.d.ts.map +1 -0
  18. package/dist/adapter/markdown_dir_port.js +175 -0
  19. package/dist/adapter/markdown_dir_port.js.map +1 -0
  20. package/dist/aggregate/document_aggregation.d.ts +40 -0
  21. package/dist/aggregate/document_aggregation.d.ts.map +1 -0
  22. package/dist/aggregate/document_aggregation.js +101 -0
  23. package/dist/aggregate/document_aggregation.js.map +1 -0
  24. package/dist/aggregate/index.d.ts +2 -0
  25. package/dist/aggregate/index.d.ts.map +1 -0
  26. package/dist/aggregate/index.js +2 -0
  27. package/dist/aggregate/index.js.map +1 -0
  28. package/dist/answer/answer_layer.d.ts +33 -0
  29. package/dist/answer/answer_layer.d.ts.map +1 -0
  30. package/dist/answer/answer_layer.js +75 -0
  31. package/dist/answer/answer_layer.js.map +1 -0
  32. package/dist/answer/caching_body_source.d.ts +42 -0
  33. package/dist/answer/caching_body_source.d.ts.map +1 -0
  34. package/dist/answer/caching_body_source.js +120 -0
  35. package/dist/answer/caching_body_source.js.map +1 -0
  36. package/dist/answer/claude_cli_backend.d.ts +10 -0
  37. package/dist/answer/claude_cli_backend.d.ts.map +1 -0
  38. package/dist/answer/claude_cli_backend.js +60 -0
  39. package/dist/answer/claude_cli_backend.js.map +1 -0
  40. package/dist/answer/context.d.ts +6 -0
  41. package/dist/answer/context.d.ts.map +1 -0
  42. package/dist/answer/context.js +83 -0
  43. package/dist/answer/context.js.map +1 -0
  44. package/dist/answer/corpus_warmer.d.ts +44 -0
  45. package/dist/answer/corpus_warmer.d.ts.map +1 -0
  46. package/dist/answer/corpus_warmer.js +80 -0
  47. package/dist/answer/corpus_warmer.js.map +1 -0
  48. package/dist/answer/gate.d.ts +3 -0
  49. package/dist/answer/gate.d.ts.map +1 -0
  50. package/dist/answer/gate.js +35 -0
  51. package/dist/answer/gate.js.map +1 -0
  52. package/dist/answer/index.d.ts +20 -0
  53. package/dist/answer/index.d.ts.map +1 -0
  54. package/dist/answer/index.js +11 -0
  55. package/dist/answer/index.js.map +1 -0
  56. package/dist/answer/own_cell_body_source.d.ts +34 -0
  57. package/dist/answer/own_cell_body_source.d.ts.map +1 -0
  58. package/dist/answer/own_cell_body_source.js +66 -0
  59. package/dist/answer/own_cell_body_source.js.map +1 -0
  60. package/dist/answer/persistent_body_source.d.ts +50 -0
  61. package/dist/answer/persistent_body_source.d.ts.map +1 -0
  62. package/dist/answer/persistent_body_source.js +173 -0
  63. package/dist/answer/persistent_body_source.js.map +1 -0
  64. package/dist/answer/saihm_body_source.d.ts +27 -0
  65. package/dist/answer/saihm_body_source.d.ts.map +1 -0
  66. package/dist/answer/saihm_body_source.js +88 -0
  67. package/dist/answer/saihm_body_source.js.map +1 -0
  68. package/dist/answer/structured_answerer.d.ts +23 -0
  69. package/dist/answer/structured_answerer.d.ts.map +1 -0
  70. package/dist/answer/structured_answerer.js +103 -0
  71. package/dist/answer/structured_answerer.js.map +1 -0
  72. package/dist/answer/supersede.d.ts +12 -0
  73. package/dist/answer/supersede.d.ts.map +1 -0
  74. package/dist/answer/supersede.js +27 -0
  75. package/dist/answer/supersede.js.map +1 -0
  76. package/dist/answer/types.d.ts +53 -0
  77. package/dist/answer/types.d.ts.map +1 -0
  78. package/dist/answer/types.js +2 -0
  79. package/dist/answer/types.js.map +1 -0
  80. package/dist/assemble/brief.d.ts +83 -0
  81. package/dist/assemble/brief.d.ts.map +1 -0
  82. package/dist/assemble/brief.js +312 -0
  83. package/dist/assemble/brief.js.map +1 -0
  84. package/dist/assemble/index.d.ts +4 -0
  85. package/dist/assemble/index.d.ts.map +1 -0
  86. package/dist/assemble/index.js +4 -0
  87. package/dist/assemble/index.js.map +1 -0
  88. package/dist/assemble/posture.d.ts +23 -0
  89. package/dist/assemble/posture.d.ts.map +1 -0
  90. package/dist/assemble/posture.js +68 -0
  91. package/dist/assemble/posture.js.map +1 -0
  92. package/dist/assemble/thread.d.ts +53 -0
  93. package/dist/assemble/thread.d.ts.map +1 -0
  94. package/dist/assemble/thread.js +122 -0
  95. package/dist/assemble/thread.js.map +1 -0
  96. package/dist/attention/index.d.ts +5 -0
  97. package/dist/attention/index.d.ts.map +1 -0
  98. package/dist/attention/index.js +3 -0
  99. package/dist/attention/index.js.map +1 -0
  100. package/dist/attention/obligations.d.ts +23 -0
  101. package/dist/attention/obligations.d.ts.map +1 -0
  102. package/dist/attention/obligations.js +110 -0
  103. package/dist/attention/obligations.js.map +1 -0
  104. package/dist/attention/queue.d.ts +38 -0
  105. package/dist/attention/queue.d.ts.map +1 -0
  106. package/dist/attention/queue.js +102 -0
  107. package/dist/attention/queue.js.map +1 -0
  108. package/dist/claim/index.d.ts +23 -0
  109. package/dist/claim/index.d.ts.map +1 -0
  110. package/dist/claim/index.js +57 -0
  111. package/dist/claim/index.js.map +1 -0
  112. package/dist/claim/withdrawn.d.ts +17 -0
  113. package/dist/claim/withdrawn.d.ts.map +1 -0
  114. package/dist/claim/withdrawn.js +41 -0
  115. package/dist/claim/withdrawn.js.map +1 -0
  116. package/dist/compliance/index.d.ts +3 -0
  117. package/dist/compliance/index.d.ts.map +1 -0
  118. package/dist/compliance/index.js +3 -0
  119. package/dist/compliance/index.js.map +1 -0
  120. package/dist/compliance/report.d.ts +123 -0
  121. package/dist/compliance/report.d.ts.map +1 -0
  122. package/dist/compliance/report.js +295 -0
  123. package/dist/compliance/report.js.map +1 -0
  124. package/dist/compliance/trail.d.ts +180 -0
  125. package/dist/compliance/trail.d.ts.map +1 -0
  126. package/dist/compliance/trail.js +130 -0
  127. package/dist/compliance/trail.js.map +1 -0
  128. package/dist/consolidate/body_redundancy.d.ts +54 -0
  129. package/dist/consolidate/body_redundancy.d.ts.map +1 -0
  130. package/dist/consolidate/body_redundancy.js +150 -0
  131. package/dist/consolidate/body_redundancy.js.map +1 -0
  132. package/dist/consolidate/consolidator.d.ts +62 -0
  133. package/dist/consolidate/consolidator.d.ts.map +1 -0
  134. package/dist/consolidate/consolidator.js +260 -0
  135. package/dist/consolidate/consolidator.js.map +1 -0
  136. package/dist/consolidate/index.d.ts +4 -0
  137. package/dist/consolidate/index.d.ts.map +1 -0
  138. package/dist/consolidate/index.js +4 -0
  139. package/dist/consolidate/index.js.map +1 -0
  140. package/dist/consolidate/index_guard.d.ts +63 -0
  141. package/dist/consolidate/index_guard.d.ts.map +1 -0
  142. package/dist/consolidate/index_guard.js +212 -0
  143. package/dist/consolidate/index_guard.js.map +1 -0
  144. package/dist/coordination/identity.d.ts +39 -0
  145. package/dist/coordination/identity.d.ts.map +1 -0
  146. package/dist/coordination/identity.js +97 -0
  147. package/dist/coordination/identity.js.map +1 -0
  148. package/dist/coordination/inbound.d.ts +41 -0
  149. package/dist/coordination/inbound.d.ts.map +1 -0
  150. package/dist/coordination/inbound.js +119 -0
  151. package/dist/coordination/inbound.js.map +1 -0
  152. package/dist/coordination/index.d.ts +12 -0
  153. package/dist/coordination/index.d.ts.map +1 -0
  154. package/dist/coordination/index.js +7 -0
  155. package/dist/coordination/index.js.map +1 -0
  156. package/dist/coordination/note_lineage.d.ts +50 -0
  157. package/dist/coordination/note_lineage.d.ts.map +1 -0
  158. package/dist/coordination/note_lineage.js +132 -0
  159. package/dist/coordination/note_lineage.js.map +1 -0
  160. package/dist/coordination/outbound.d.ts +33 -0
  161. package/dist/coordination/outbound.d.ts.map +1 -0
  162. package/dist/coordination/outbound.js +69 -0
  163. package/dist/coordination/outbound.js.map +1 -0
  164. package/dist/coordination/share_states.d.ts +178 -0
  165. package/dist/coordination/share_states.d.ts.map +1 -0
  166. package/dist/coordination/share_states.js +864 -0
  167. package/dist/coordination/share_states.js.map +1 -0
  168. package/dist/coordination/untrusted_text.d.ts +3 -0
  169. package/dist/coordination/untrusted_text.d.ts.map +1 -0
  170. package/dist/coordination/untrusted_text.js +21 -0
  171. package/dist/coordination/untrusted_text.js.map +1 -0
  172. package/dist/deref/dereference.d.ts +68 -0
  173. package/dist/deref/dereference.d.ts.map +1 -0
  174. package/dist/deref/dereference.js +199 -0
  175. package/dist/deref/dereference.js.map +1 -0
  176. package/dist/deref/index.d.ts +3 -0
  177. package/dist/deref/index.d.ts.map +1 -0
  178. package/dist/deref/index.js +3 -0
  179. package/dist/deref/index.js.map +1 -0
  180. package/dist/deref/policy.d.ts +76 -0
  181. package/dist/deref/policy.d.ts.map +1 -0
  182. package/dist/deref/policy.js +281 -0
  183. package/dist/deref/policy.js.map +1 -0
  184. package/dist/derived/checkpoint.d.ts +22 -0
  185. package/dist/derived/checkpoint.d.ts.map +1 -0
  186. package/dist/derived/checkpoint.js +92 -0
  187. package/dist/derived/checkpoint.js.map +1 -0
  188. package/dist/derived/codec.d.ts +26 -0
  189. package/dist/derived/codec.d.ts.map +1 -0
  190. package/dist/derived/codec.js +116 -0
  191. package/dist/derived/codec.js.map +1 -0
  192. package/dist/derived/cycle.d.ts +96 -0
  193. package/dist/derived/cycle.d.ts.map +1 -0
  194. package/dist/derived/cycle.js +199 -0
  195. package/dist/derived/cycle.js.map +1 -0
  196. package/dist/derived/index.d.ts +7 -0
  197. package/dist/derived/index.d.ts.map +1 -0
  198. package/dist/derived/index.js +7 -0
  199. package/dist/derived/index.js.map +1 -0
  200. package/dist/derived/ledger.d.ts +54 -0
  201. package/dist/derived/ledger.d.ts.map +1 -0
  202. package/dist/derived/ledger.js +123 -0
  203. package/dist/derived/ledger.js.map +1 -0
  204. package/dist/derived/lineage_index.d.ts +17 -0
  205. package/dist/derived/lineage_index.d.ts.map +1 -0
  206. package/dist/derived/lineage_index.js +51 -0
  207. package/dist/derived/lineage_index.js.map +1 -0
  208. package/dist/derived/store.d.ts +92 -0
  209. package/dist/derived/store.d.ts.map +1 -0
  210. package/dist/derived/store.js +230 -0
  211. package/dist/derived/store.js.map +1 -0
  212. package/dist/embed/index.d.ts +5 -0
  213. package/dist/embed/index.d.ts.map +1 -0
  214. package/dist/embed/index.js +4 -0
  215. package/dist/embed/index.js.map +1 -0
  216. package/dist/embed/local_minilm.d.ts +9 -0
  217. package/dist/embed/local_minilm.d.ts.map +1 -0
  218. package/dist/embed/local_minilm.js +31 -0
  219. package/dist/embed/local_minilm.js.map +1 -0
  220. package/dist/embed/remote_http.d.ts +26 -0
  221. package/dist/embed/remote_http.d.ts.map +1 -0
  222. package/dist/embed/remote_http.js +40 -0
  223. package/dist/embed/remote_http.js.map +1 -0
  224. package/dist/embed/router.d.ts +16 -0
  225. package/dist/embed/router.d.ts.map +1 -0
  226. package/dist/embed/router.js +47 -0
  227. package/dist/embed/router.js.map +1 -0
  228. package/dist/embed/types.d.ts +23 -0
  229. package/dist/embed/types.d.ts.map +1 -0
  230. package/dist/embed/types.js +2 -0
  231. package/dist/embed/types.js.map +1 -0
  232. package/dist/entitlement/entitlement.d.ts +24 -0
  233. package/dist/entitlement/entitlement.d.ts.map +1 -0
  234. package/dist/entitlement/entitlement.js +78 -0
  235. package/dist/entitlement/entitlement.js.map +1 -0
  236. package/dist/entitlement/index.d.ts +2 -0
  237. package/dist/entitlement/index.d.ts.map +1 -0
  238. package/dist/entitlement/index.js +2 -0
  239. package/dist/entitlement/index.js.map +1 -0
  240. package/dist/erasure/bus.d.ts +18 -0
  241. package/dist/erasure/bus.d.ts.map +1 -0
  242. package/dist/erasure/bus.js +56 -0
  243. package/dist/erasure/bus.js.map +1 -0
  244. package/dist/erasure/changes_feed.d.ts +125 -0
  245. package/dist/erasure/changes_feed.d.ts.map +1 -0
  246. package/dist/erasure/changes_feed.js +252 -0
  247. package/dist/erasure/changes_feed.js.map +1 -0
  248. package/dist/erasure/changes_reader.d.ts +44 -0
  249. package/dist/erasure/changes_reader.d.ts.map +1 -0
  250. package/dist/erasure/changes_reader.js +184 -0
  251. package/dist/erasure/changes_reader.js.map +1 -0
  252. package/dist/erasure/feed_watcher.d.ts +140 -0
  253. package/dist/erasure/feed_watcher.d.ts.map +1 -0
  254. package/dist/erasure/feed_watcher.js +418 -0
  255. package/dist/erasure/feed_watcher.js.map +1 -0
  256. package/dist/erasure/index.d.ts +15 -0
  257. package/dist/erasure/index.d.ts.map +1 -0
  258. package/dist/erasure/index.js +8 -0
  259. package/dist/erasure/index.js.map +1 -0
  260. package/dist/erasure/index_watcher.d.ts +28 -0
  261. package/dist/erasure/index_watcher.d.ts.map +1 -0
  262. package/dist/erasure/index_watcher.js +87 -0
  263. package/dist/erasure/index_watcher.js.map +1 -0
  264. package/dist/erasure/reconcile.d.ts +72 -0
  265. package/dist/erasure/reconcile.d.ts.map +1 -0
  266. package/dist/erasure/reconcile.js +125 -0
  267. package/dist/erasure/reconcile.js.map +1 -0
  268. package/dist/erasure/withheld_store.d.ts +30 -0
  269. package/dist/erasure/withheld_store.d.ts.map +1 -0
  270. package/dist/erasure/withheld_store.js +91 -0
  271. package/dist/erasure/withheld_store.js.map +1 -0
  272. package/dist/fleet/index.d.ts +2 -0
  273. package/dist/fleet/index.d.ts.map +1 -0
  274. package/dist/fleet/index.js +2 -0
  275. package/dist/fleet/index.js.map +1 -0
  276. package/dist/fleet/knowledge.d.ts +74 -0
  277. package/dist/fleet/knowledge.d.ts.map +1 -0
  278. package/dist/fleet/knowledge.js +178 -0
  279. package/dist/fleet/knowledge.js.map +1 -0
  280. package/dist/gate/index.d.ts +5 -0
  281. package/dist/gate/index.d.ts.map +1 -0
  282. package/dist/gate/index.js +3 -0
  283. package/dist/gate/index.js.map +1 -0
  284. package/dist/gate/scope.d.ts +21 -0
  285. package/dist/gate/scope.d.ts.map +1 -0
  286. package/dist/gate/scope.js +40 -0
  287. package/dist/gate/scope.js.map +1 -0
  288. package/dist/gate/symmetry.d.ts +55 -0
  289. package/dist/gate/symmetry.d.ts.map +1 -0
  290. package/dist/gate/symmetry.js +162 -0
  291. package/dist/gate/symmetry.js.map +1 -0
  292. package/dist/history/answerable.d.ts +51 -0
  293. package/dist/history/answerable.d.ts.map +1 -0
  294. package/dist/history/answerable.js +112 -0
  295. package/dist/history/answerable.js.map +1 -0
  296. package/dist/history/index.d.ts +2 -0
  297. package/dist/history/index.d.ts.map +1 -0
  298. package/dist/history/index.js +2 -0
  299. package/dist/history/index.js.map +1 -0
  300. package/dist/host/adapter.d.ts +69 -0
  301. package/dist/host/adapter.d.ts.map +1 -0
  302. package/dist/host/adapter.js +159 -0
  303. package/dist/host/adapter.js.map +1 -0
  304. package/dist/host/cli.d.ts +3 -0
  305. package/dist/host/cli.d.ts.map +1 -0
  306. package/dist/host/cli.js +44 -0
  307. package/dist/host/cli.js.map +1 -0
  308. package/dist/host/client.d.ts +22 -0
  309. package/dist/host/client.d.ts.map +1 -0
  310. package/dist/host/client.js +135 -0
  311. package/dist/host/client.js.map +1 -0
  312. package/dist/host/compaction.d.ts +16 -0
  313. package/dist/host/compaction.d.ts.map +1 -0
  314. package/dist/host/compaction.js +89 -0
  315. package/dist/host/compaction.js.map +1 -0
  316. package/dist/host/event.d.ts +22 -0
  317. package/dist/host/event.d.ts.map +1 -0
  318. package/dist/host/event.js +47 -0
  319. package/dist/host/event.js.map +1 -0
  320. package/dist/host/index.d.ts +10 -0
  321. package/dist/host/index.d.ts.map +1 -0
  322. package/dist/host/index.js +10 -0
  323. package/dist/host/index.js.map +1 -0
  324. package/dist/host/reply.d.ts +11 -0
  325. package/dist/host/reply.d.ts.map +1 -0
  326. package/dist/host/reply.js +24 -0
  327. package/dist/host/reply.js.map +1 -0
  328. package/dist/host/session_brief.d.ts +80 -0
  329. package/dist/host/session_brief.d.ts.map +1 -0
  330. package/dist/host/session_brief.js +294 -0
  331. package/dist/host/session_brief.js.map +1 -0
  332. package/dist/host/session_start_event.d.ts +12 -0
  333. package/dist/host/session_start_event.d.ts.map +1 -0
  334. package/dist/host/session_start_event.js +35 -0
  335. package/dist/host/session_start_event.js.map +1 -0
  336. package/dist/host/sessions.d.ts +8 -0
  337. package/dist/host/sessions.d.ts.map +1 -0
  338. package/dist/host/sessions.js +32 -0
  339. package/dist/host/sessions.js.map +1 -0
  340. package/dist/host/socket_path.d.ts +3 -0
  341. package/dist/host/socket_path.d.ts.map +1 -0
  342. package/dist/host/socket_path.js +14 -0
  343. package/dist/host/socket_path.js.map +1 -0
  344. package/dist/inbound/index.d.ts +8 -0
  345. package/dist/inbound/index.d.ts.map +1 -0
  346. package/dist/inbound/index.js +5 -0
  347. package/dist/inbound/index.js.map +1 -0
  348. package/dist/index.d.ts +108 -0
  349. package/dist/index.d.ts.map +1 -0
  350. package/dist/index.js +55 -0
  351. package/dist/index.js.map +1 -0
  352. package/dist/ingest/index.d.ts +13 -0
  353. package/dist/ingest/index.d.ts.map +1 -0
  354. package/dist/ingest/index.js +146 -0
  355. package/dist/ingest/index.js.map +1 -0
  356. package/dist/ingest/parse.d.ts +20 -0
  357. package/dist/ingest/parse.d.ts.map +1 -0
  358. package/dist/ingest/parse.js +141 -0
  359. package/dist/ingest/parse.js.map +1 -0
  360. package/dist/ingest/resolve_prefix.d.ts +19 -0
  361. package/dist/ingest/resolve_prefix.d.ts.map +1 -0
  362. package/dist/ingest/resolve_prefix.js +63 -0
  363. package/dist/ingest/resolve_prefix.js.map +1 -0
  364. package/dist/ingest/types.d.ts +47 -0
  365. package/dist/ingest/types.d.ts.map +1 -0
  366. package/dist/ingest/types.js +2 -0
  367. package/dist/ingest/types.js.map +1 -0
  368. package/dist/inject/action_cue.d.ts +11 -0
  369. package/dist/inject/action_cue.d.ts.map +1 -0
  370. package/dist/inject/action_cue.js +49 -0
  371. package/dist/inject/action_cue.js.map +1 -0
  372. package/dist/inject/index.d.ts +11 -0
  373. package/dist/inject/index.d.ts.map +1 -0
  374. package/dist/inject/index.js +6 -0
  375. package/dist/inject/index.js.map +1 -0
  376. package/dist/inject/novelty.d.ts +19 -0
  377. package/dist/inject/novelty.d.ts.map +1 -0
  378. package/dist/inject/novelty.js +34 -0
  379. package/dist/inject/novelty.js.map +1 -0
  380. package/dist/inject/outcome.d.ts +20 -0
  381. package/dist/inject/outcome.d.ts.map +1 -0
  382. package/dist/inject/outcome.js +26 -0
  383. package/dist/inject/outcome.js.map +1 -0
  384. package/dist/inject/population.d.ts +6 -0
  385. package/dist/inject/population.d.ts.map +1 -0
  386. package/dist/inject/population.js +23 -0
  387. package/dist/inject/population.js.map +1 -0
  388. package/dist/inject/proactive_injector.d.ts +56 -0
  389. package/dist/inject/proactive_injector.d.ts.map +1 -0
  390. package/dist/inject/proactive_injector.js +153 -0
  391. package/dist/inject/proactive_injector.js.map +1 -0
  392. package/dist/inject/token_estimate.d.ts +3 -0
  393. package/dist/inject/token_estimate.d.ts.map +1 -0
  394. package/dist/inject/token_estimate.js +2 -0
  395. package/dist/inject/token_estimate.js.map +1 -0
  396. package/dist/inject/window.d.ts +6 -0
  397. package/dist/inject/window.d.ts.map +1 -0
  398. package/dist/inject/window.js +10 -0
  399. package/dist/inject/window.js.map +1 -0
  400. package/dist/modes/behaviour_modes.d.ts +21 -0
  401. package/dist/modes/behaviour_modes.d.ts.map +1 -0
  402. package/dist/modes/behaviour_modes.js +137 -0
  403. package/dist/modes/behaviour_modes.js.map +1 -0
  404. package/dist/policy/index.d.ts +2 -0
  405. package/dist/policy/index.d.ts.map +1 -0
  406. package/dist/policy/index.js +2 -0
  407. package/dist/policy/index.js.map +1 -0
  408. package/dist/policy/store_policy.d.ts +47 -0
  409. package/dist/policy/store_policy.d.ts.map +1 -0
  410. package/dist/policy/store_policy.js +125 -0
  411. package/dist/policy/store_policy.js.map +1 -0
  412. package/dist/profile/index.d.ts +5 -0
  413. package/dist/profile/index.d.ts.map +1 -0
  414. package/dist/profile/index.js +3 -0
  415. package/dist/profile/index.js.map +1 -0
  416. package/dist/profile/lever_profile.d.ts +27 -0
  417. package/dist/profile/lever_profile.d.ts.map +1 -0
  418. package/dist/profile/lever_profile.js +55 -0
  419. package/dist/profile/lever_profile.js.map +1 -0
  420. package/dist/profile/production.d.ts +12 -0
  421. package/dist/profile/production.d.ts.map +1 -0
  422. package/dist/profile/production.js +13 -0
  423. package/dist/profile/production.js.map +1 -0
  424. package/dist/provenance/build_fingerprint.d.ts +9 -0
  425. package/dist/provenance/build_fingerprint.d.ts.map +1 -0
  426. package/dist/provenance/build_fingerprint.js +47 -0
  427. package/dist/provenance/build_fingerprint.js.map +1 -0
  428. package/dist/provenance/derived_number.d.ts +33 -0
  429. package/dist/provenance/derived_number.d.ts.map +1 -0
  430. package/dist/provenance/derived_number.js +52 -0
  431. package/dist/provenance/derived_number.js.map +1 -0
  432. package/dist/provenance/index.d.ts +7 -0
  433. package/dist/provenance/index.d.ts.map +1 -0
  434. package/dist/provenance/index.js +4 -0
  435. package/dist/provenance/index.js.map +1 -0
  436. package/dist/provenance/live_state.d.ts +49 -0
  437. package/dist/provenance/live_state.d.ts.map +1 -0
  438. package/dist/provenance/live_state.js +141 -0
  439. package/dist/provenance/live_state.js.map +1 -0
  440. package/dist/rerank/cross_encoder.d.ts +14 -0
  441. package/dist/rerank/cross_encoder.d.ts.map +1 -0
  442. package/dist/rerank/cross_encoder.js +40 -0
  443. package/dist/rerank/cross_encoder.js.map +1 -0
  444. package/dist/rerank/identity.d.ts +6 -0
  445. package/dist/rerank/identity.d.ts.map +1 -0
  446. package/dist/rerank/identity.js +7 -0
  447. package/dist/rerank/identity.js.map +1 -0
  448. package/dist/rerank/index.d.ts +8 -0
  449. package/dist/rerank/index.d.ts.map +1 -0
  450. package/dist/rerank/index.js +5 -0
  451. package/dist/rerank/index.js.map +1 -0
  452. package/dist/rerank/reranking_retriever.d.ts +20 -0
  453. package/dist/rerank/reranking_retriever.d.ts.map +1 -0
  454. package/dist/rerank/reranking_retriever.js +38 -0
  455. package/dist/rerank/reranking_retriever.js.map +1 -0
  456. package/dist/rerank/reranking_select.d.ts +33 -0
  457. package/dist/rerank/reranking_select.d.ts.map +1 -0
  458. package/dist/rerank/reranking_select.js +116 -0
  459. package/dist/rerank/reranking_select.js.map +1 -0
  460. package/dist/rerank/types.d.ts +9 -0
  461. package/dist/rerank/types.d.ts.map +1 -0
  462. package/dist/rerank/types.js +2 -0
  463. package/dist/rerank/types.js.map +1 -0
  464. package/dist/resume/index.d.ts +3 -0
  465. package/dist/resume/index.d.ts.map +1 -0
  466. package/dist/resume/index.js +2 -0
  467. package/dist/resume/index.js.map +1 -0
  468. package/dist/resume/resume.d.ts +33 -0
  469. package/dist/resume/resume.d.ts.map +1 -0
  470. package/dist/resume/resume.js +86 -0
  471. package/dist/resume/resume.js.map +1 -0
  472. package/dist/retrieval/hnsw_store.d.ts +37 -0
  473. package/dist/retrieval/hnsw_store.d.ts.map +1 -0
  474. package/dist/retrieval/hnsw_store.js +284 -0
  475. package/dist/retrieval/hnsw_store.js.map +1 -0
  476. package/dist/retrieval/label_text.d.ts +2 -0
  477. package/dist/retrieval/label_text.d.ts.map +1 -0
  478. package/dist/retrieval/label_text.js +7 -0
  479. package/dist/retrieval/label_text.js.map +1 -0
  480. package/dist/retrieval/link_graph.d.ts +38 -0
  481. package/dist/retrieval/link_graph.d.ts.map +1 -0
  482. package/dist/retrieval/link_graph.js +118 -0
  483. package/dist/retrieval/link_graph.js.map +1 -0
  484. package/dist/retrieval/query_expansion.d.ts +18 -0
  485. package/dist/retrieval/query_expansion.d.ts.map +1 -0
  486. package/dist/retrieval/query_expansion.js +55 -0
  487. package/dist/retrieval/query_expansion.js.map +1 -0
  488. package/dist/retrieval/scope.d.ts +36 -0
  489. package/dist/retrieval/scope.d.ts.map +1 -0
  490. package/dist/retrieval/scope.js +120 -0
  491. package/dist/retrieval/scope.js.map +1 -0
  492. package/dist/retrieval/semantic.d.ts +136 -0
  493. package/dist/retrieval/semantic.d.ts.map +1 -0
  494. package/dist/retrieval/semantic.js +490 -0
  495. package/dist/retrieval/semantic.js.map +1 -0
  496. package/dist/retrieval/session_closed.d.ts +5 -0
  497. package/dist/retrieval/session_closed.d.ts.map +1 -0
  498. package/dist/retrieval/session_closed.js +8 -0
  499. package/dist/retrieval/session_closed.js.map +1 -0
  500. package/dist/retrieval/thread_lifecycle.d.ts +68 -0
  501. package/dist/retrieval/thread_lifecycle.d.ts.map +1 -0
  502. package/dist/retrieval/thread_lifecycle.js +201 -0
  503. package/dist/retrieval/thread_lifecycle.js.map +1 -0
  504. package/dist/retrieval/vector_store.d.ts +22 -0
  505. package/dist/retrieval/vector_store.d.ts.map +1 -0
  506. package/dist/retrieval/vector_store.js +41 -0
  507. package/dist/retrieval/vector_store.js.map +1 -0
  508. package/dist/retrieval/version_supersession.d.ts +13 -0
  509. package/dist/retrieval/version_supersession.d.ts.map +1 -0
  510. package/dist/retrieval/version_supersession.js +97 -0
  511. package/dist/retrieval/version_supersession.js.map +1 -0
  512. package/dist/saihm_client/federated_port.d.ts +30 -0
  513. package/dist/saihm_client/federated_port.d.ts.map +1 -0
  514. package/dist/saihm_client/federated_port.js +99 -0
  515. package/dist/saihm_client/federated_port.js.map +1 -0
  516. package/dist/saihm_client/in_memory_port.d.ts +35 -0
  517. package/dist/saihm_client/in_memory_port.d.ts.map +1 -0
  518. package/dist/saihm_client/in_memory_port.js +100 -0
  519. package/dist/saihm_client/in_memory_port.js.map +1 -0
  520. package/dist/saihm_client/index.d.ts +12 -0
  521. package/dist/saihm_client/index.d.ts.map +1 -0
  522. package/dist/saihm_client/index.js +8 -0
  523. package/dist/saihm_client/index.js.map +1 -0
  524. package/dist/saihm_client/mcp_client.d.ts +38 -0
  525. package/dist/saihm_client/mcp_client.d.ts.map +1 -0
  526. package/dist/saihm_client/mcp_client.js +266 -0
  527. package/dist/saihm_client/mcp_client.js.map +1 -0
  528. package/dist/saihm_client/server_features.d.ts +112 -0
  529. package/dist/saihm_client/server_features.d.ts.map +1 -0
  530. package/dist/saihm_client/server_features.js +415 -0
  531. package/dist/saihm_client/server_features.js.map +1 -0
  532. package/dist/saihm_client/share_guard.d.ts +9 -0
  533. package/dist/saihm_client/share_guard.d.ts.map +1 -0
  534. package/dist/saihm_client/share_guard.js +53 -0
  535. package/dist/saihm_client/share_guard.js.map +1 -0
  536. package/dist/saihm_client/timing.d.ts +100 -0
  537. package/dist/saihm_client/timing.d.ts.map +1 -0
  538. package/dist/saihm_client/timing.js +250 -0
  539. package/dist/saihm_client/timing.js.map +1 -0
  540. package/dist/saihm_client/types.d.ts +108 -0
  541. package/dist/saihm_client/types.d.ts.map +1 -0
  542. package/dist/saihm_client/types.js +19 -0
  543. package/dist/saihm_client/types.js.map +1 -0
  544. package/dist/service/handlers.d.ts +91 -0
  545. package/dist/service/handlers.d.ts.map +1 -0
  546. package/dist/service/handlers.js +173 -0
  547. package/dist/service/handlers.js.map +1 -0
  548. package/dist/service/http.d.ts +27 -0
  549. package/dist/service/http.d.ts.map +1 -0
  550. package/dist/service/http.js +261 -0
  551. package/dist/service/http.js.map +1 -0
  552. package/dist/service/index.d.ts +5 -0
  553. package/dist/service/index.d.ts.map +1 -0
  554. package/dist/service/index.js +5 -0
  555. package/dist/service/index.js.map +1 -0
  556. package/dist/service/resident.d.ts +50 -0
  557. package/dist/service/resident.d.ts.map +1 -0
  558. package/dist/service/resident.js +162 -0
  559. package/dist/service/resident.js.map +1 -0
  560. package/dist/service/service_level.d.ts +36 -0
  561. package/dist/service/service_level.d.ts.map +1 -0
  562. package/dist/service/service_level.js +65 -0
  563. package/dist/service/service_level.js.map +1 -0
  564. package/dist/session/change_feed.d.ts +82 -0
  565. package/dist/session/change_feed.d.ts.map +1 -0
  566. package/dist/session/change_feed.js +203 -0
  567. package/dist/session/change_feed.js.map +1 -0
  568. package/dist/session/index.d.ts +6 -0
  569. package/dist/session/index.d.ts.map +1 -0
  570. package/dist/session/index.js +4 -0
  571. package/dist/session/index.js.map +1 -0
  572. package/dist/session/memory_session.d.ts +426 -0
  573. package/dist/session/memory_session.d.ts.map +1 -0
  574. package/dist/session/memory_session.js +1183 -0
  575. package/dist/session/memory_session.js.map +1 -0
  576. package/dist/standing/content_fingerprint.d.ts +28 -0
  577. package/dist/standing/content_fingerprint.d.ts.map +1 -0
  578. package/dist/standing/content_fingerprint.js +95 -0
  579. package/dist/standing/content_fingerprint.js.map +1 -0
  580. package/dist/standing/standing_answers.d.ts +44 -0
  581. package/dist/standing/standing_answers.d.ts.map +1 -0
  582. package/dist/standing/standing_answers.js +72 -0
  583. package/dist/standing/standing_answers.js.map +1 -0
  584. package/dist/standing/standing_store.d.ts +44 -0
  585. package/dist/standing/standing_store.d.ts.map +1 -0
  586. package/dist/standing/standing_store.js +238 -0
  587. package/dist/standing/standing_store.js.map +1 -0
  588. package/dist/standing/surface.d.ts +20 -0
  589. package/dist/standing/surface.d.ts.map +1 -0
  590. package/dist/standing/surface.js +74 -0
  591. package/dist/standing/surface.js.map +1 -0
  592. package/dist/store/atomic_write.d.ts +7 -0
  593. package/dist/store/atomic_write.d.ts.map +1 -0
  594. package/dist/store/atomic_write.js +23 -0
  595. package/dist/store/atomic_write.js.map +1 -0
  596. package/dist/store/body_store.d.ts +42 -0
  597. package/dist/store/body_store.d.ts.map +1 -0
  598. package/dist/store/body_store.js +252 -0
  599. package/dist/store/body_store.js.map +1 -0
  600. package/dist/store/encrypted_store.d.ts +21 -0
  601. package/dist/store/encrypted_store.d.ts.map +1 -0
  602. package/dist/store/encrypted_store.js +266 -0
  603. package/dist/store/encrypted_store.js.map +1 -0
  604. package/dist/store/index.d.ts +21 -0
  605. package/dist/store/index.d.ts.map +1 -0
  606. package/dist/store/index.js +11 -0
  607. package/dist/store/index.js.map +1 -0
  608. package/dist/store/index_snapshot.d.ts +15 -0
  609. package/dist/store/index_snapshot.d.ts.map +1 -0
  610. package/dist/store/index_snapshot.js +126 -0
  611. package/dist/store/index_snapshot.js.map +1 -0
  612. package/dist/store/mcp_warm_start.d.ts +93 -0
  613. package/dist/store/mcp_warm_start.d.ts.map +1 -0
  614. package/dist/store/mcp_warm_start.js +406 -0
  615. package/dist/store/mcp_warm_start.js.map +1 -0
  616. package/dist/store/require_dir.d.ts +2 -0
  617. package/dist/store/require_dir.d.ts.map +1 -0
  618. package/dist/store/require_dir.js +9 -0
  619. package/dist/store/require_dir.js.map +1 -0
  620. package/dist/store/snapshot_format.d.ts +43 -0
  621. package/dist/store/snapshot_format.d.ts.map +1 -0
  622. package/dist/store/snapshot_format.js +119 -0
  623. package/dist/store/snapshot_format.js.map +1 -0
  624. package/dist/store/state_dir.d.ts +19 -0
  625. package/dist/store/state_dir.d.ts.map +1 -0
  626. package/dist/store/state_dir.js +42 -0
  627. package/dist/store/state_dir.js.map +1 -0
  628. package/dist/store/types.d.ts +37 -0
  629. package/dist/store/types.d.ts.map +1 -0
  630. package/dist/store/types.js +11 -0
  631. package/dist/store/types.js.map +1 -0
  632. package/dist/store/warm_index.d.ts +68 -0
  633. package/dist/store/warm_index.d.ts.map +1 -0
  634. package/dist/store/warm_index.js +279 -0
  635. package/dist/store/warm_index.js.map +1 -0
  636. package/dist/store/warm_start.d.ts +57 -0
  637. package/dist/store/warm_start.d.ts.map +1 -0
  638. package/dist/store/warm_start.js +68 -0
  639. package/dist/store/warm_start.js.map +1 -0
  640. package/dist/store/writer_lock.d.ts +34 -0
  641. package/dist/store/writer_lock.d.ts.map +1 -0
  642. package/dist/store/writer_lock.js +169 -0
  643. package/dist/store/writer_lock.js.map +1 -0
  644. package/dist/tiers/index.d.ts +2 -0
  645. package/dist/tiers/index.d.ts.map +1 -0
  646. package/dist/tiers/index.js +2 -0
  647. package/dist/tiers/index.js.map +1 -0
  648. package/dist/tiers/membership.d.ts +48 -0
  649. package/dist/tiers/membership.d.ts.map +1 -0
  650. package/dist/tiers/membership.js +85 -0
  651. package/dist/tiers/membership.js.map +1 -0
  652. package/dist/tuning/holdout.d.ts +54 -0
  653. package/dist/tuning/holdout.d.ts.map +1 -0
  654. package/dist/tuning/holdout.js +231 -0
  655. package/dist/tuning/holdout.js.map +1 -0
  656. package/dist/tuning/index.d.ts +7 -0
  657. package/dist/tuning/index.d.ts.map +1 -0
  658. package/dist/tuning/index.js +4 -0
  659. package/dist/tuning/index.js.map +1 -0
  660. package/dist/tuning/lever_stack.d.ts +27 -0
  661. package/dist/tuning/lever_stack.d.ts.map +1 -0
  662. package/dist/tuning/lever_stack.js +76 -0
  663. package/dist/tuning/lever_stack.js.map +1 -0
  664. package/dist/tuning/paired.d.ts +22 -0
  665. package/dist/tuning/paired.d.ts.map +1 -0
  666. package/dist/tuning/paired.js +74 -0
  667. package/dist/tuning/paired.js.map +1 -0
  668. package/dist/util/concurrency.d.ts +2 -0
  669. package/dist/util/concurrency.d.ts.map +1 -0
  670. package/dist/util/concurrency.js +19 -0
  671. package/dist/util/concurrency.js.map +1 -0
  672. package/package.json +161 -4
@@ -0,0 +1,864 @@
1
+ import { gateScope } from "../gate/scope.js";
2
+ import { refKey, sharerMatches } from "./inbound.js";
3
+ import { displayUntrusted } from "./untrusted_text.js";
4
+ export const EVENT_ENDS_MAY_HIDE_ERASURES = true;
5
+ function endedMayHideErasure(e) {
6
+ return e.endedBy !== "event" || EVENT_ENDS_MAY_HIDE_ERASURES;
7
+ }
8
+ function endedWhy(e, firstSeen) {
9
+ const lead = firstSeen ? "first seen already ended" : "ended";
10
+ if (e.endedBy !== "event")
11
+ return `${lead} by reconciliation — possibly erased`;
12
+ return endedMayHideErasure(e)
13
+ ? `${lead} by an event (revoked or expired) — possibly erased: an expiry can hide an erasure that was never delivered`
14
+ : `${lead} by an event (revoked or expired)`;
15
+ }
16
+ const STATUSES = new Set(["live", "stale", "ended", "erased"]);
17
+ const ISO_UTC = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?Z$/;
18
+ function timeOf(v) {
19
+ if (v === null || v === undefined)
20
+ return null;
21
+ if (typeof v !== "string" || !ISO_UTC.test(v))
22
+ return "unreadable";
23
+ const t = Date.parse(v);
24
+ if (!Number.isFinite(t))
25
+ return "unreadable";
26
+ return new Date(t).toISOString().slice(0, 19) === v.slice(0, 19) ? t : "unreadable";
27
+ }
28
+ const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
29
+ const lc = (s) => (s === null ? null : s.toLowerCase());
30
+ function obligation(e) {
31
+ if (e.status === "erased")
32
+ return 5;
33
+ if (e.copiesInvalidBefore !== null)
34
+ return 4;
35
+ if (e.status === "ended")
36
+ return 3;
37
+ if (e.status === "stale")
38
+ return 2;
39
+ if (e.status === "unknown")
40
+ return 1;
41
+ return 0;
42
+ }
43
+ export function readShareStates(recallResult) {
44
+ if (!isObject(recallResult))
45
+ return { kind: "malformed", why: "the recall result is not an object" };
46
+ if (!Object.prototype.hasOwnProperty.call(recallResult, "shareStates"))
47
+ return { kind: "absent" };
48
+ const raw = recallResult["shareStates"];
49
+ if (!isObject(raw))
50
+ return { kind: "malformed", why: "shareStates is not an object" };
51
+ if (!Object.prototype.hasOwnProperty.call(raw, "entries")) {
52
+ if (!isObject(raw["counts"]))
53
+ return { kind: "malformed", why: "shareStates carries neither entries nor counts" };
54
+ return { kind: "summary", summary: readSummary(raw) };
55
+ }
56
+ if (!Array.isArray(raw["entries"]))
57
+ return { kind: "malformed", why: "shareStates.entries is not an array" };
58
+ return { kind: "present", map: readMap(raw) };
59
+ }
60
+ function readSummary(raw) {
61
+ const defects = [];
62
+ const time = (field) => {
63
+ const v = timeOf(raw[field]);
64
+ if (v === "unreadable") {
65
+ defects.push(`${field} is unreadable — read as null`);
66
+ return null;
67
+ }
68
+ return v;
69
+ };
70
+ const since = time("since");
71
+ const statedComplete = raw["complete"];
72
+ if (typeof statedComplete !== "boolean")
73
+ defects.push("complete is not a boolean — read as false");
74
+ const asOf = time("asOf");
75
+ const startedAt = time("startedAt");
76
+ const stoppedRaw = raw["stopped"];
77
+ let stopped = null;
78
+ let stoppedText = null;
79
+ if (stoppedRaw !== null && stoppedRaw !== undefined) {
80
+ if (stoppedRaw === "unsupported" || stoppedRaw === "tier" || stoppedRaw === "erased") {
81
+ stopped = stoppedRaw;
82
+ }
83
+ else {
84
+ stopped = "unknown";
85
+ stoppedText = displayUntrusted(typeof stoppedRaw === "string" ? stoppedRaw : String(stoppedRaw), 32);
86
+ defects.push(`stopped "${stoppedText}" is not a v1 reason — kept as unknown`);
87
+ }
88
+ }
89
+ const countsRaw = isObject(raw["counts"]) ? raw["counts"] : {};
90
+ const count = (field) => {
91
+ const v = countsRaw[field];
92
+ if (typeof v === "number" && Number.isInteger(v) && v >= 0)
93
+ return v;
94
+ defects.push(`counts.${field} is not a whole number — read as null`);
95
+ return null;
96
+ };
97
+ const counts = { live: count("live"), stale: count("stale"), ended: count("ended"), erased: count("erased") };
98
+ return { since, complete: statedComplete === true, asOf, stopped, stoppedText, startedAt, counts, defects };
99
+ }
100
+ function readMap(raw) {
101
+ const defects = [];
102
+ let lossless = true;
103
+ const sinceT = timeOf(raw["since"]);
104
+ if (sinceT === "unreadable")
105
+ defects.push("since is unreadable — read as null, so a missing key concludes nothing");
106
+ const since = sinceT === "unreadable" ? null : sinceT;
107
+ const statedComplete = raw["complete"];
108
+ if (typeof statedComplete !== "boolean") {
109
+ defects.push("complete is not a boolean — read as false");
110
+ lossless = false;
111
+ }
112
+ const byKey = new Map();
113
+ raw["entries"].forEach((r, i) => {
114
+ if (!isObject(r)) {
115
+ defects.push(`entry ${i} is not an object — dropped, so the map is incomplete here`);
116
+ lossless = false;
117
+ return;
118
+ }
119
+ const sharer = r["sharer"];
120
+ const cellId = r["cellId"];
121
+ if (typeof sharer !== "string" || typeof cellId !== "string") {
122
+ defects.push(`entry ${i} lacks a string sharer or cellId — dropped, so the map is incomplete here`);
123
+ lossless = false;
124
+ return;
125
+ }
126
+ const statusText = typeof r["status"] === "string" ? r["status"] : String(r["status"]);
127
+ const status = STATUSES.has(statusText) ? statusText : "unknown";
128
+ if (status === "unknown") {
129
+ defects.push(`entry ${i}: status "${displayUntrusted(statusText, 32)}" is not a v1 status — kept as unknown, never as live`);
130
+ }
131
+ const text = (field) => {
132
+ const v = r[field];
133
+ if (v === null || v === undefined)
134
+ return null;
135
+ if (typeof v === "string")
136
+ return v;
137
+ defects.push(`entry ${i}: ${field} is not a string — set aside`);
138
+ return null;
139
+ };
140
+ const endedByRaw = r["endedBy"];
141
+ const endedBy = endedByRaw === null || endedByRaw === undefined
142
+ ? null
143
+ : endedByRaw === "event" || endedByRaw === "reconciliation"
144
+ ? endedByRaw
145
+ : "unknown";
146
+ const endedAt = timeOf(r["endedAt"]);
147
+ if (endedAt === "unreadable")
148
+ defects.push(`entry ${i}: endedAt is unreadable — set aside`);
149
+ const cib = timeOf(r["copiesInvalidBefore"]);
150
+ if (cib === "unreadable")
151
+ defects.push(`entry ${i}: copiesInvalidBefore is unreadable — every copy of this cell is treated as invalid`);
152
+ const entry = {
153
+ key: refKey({ sharer, cellId }),
154
+ sharer: sharer.trim().toLowerCase(),
155
+ cellId,
156
+ status,
157
+ statusText,
158
+ grant: text("grant"),
159
+ scope: text("scope"),
160
+ expiryEpoch: text("expiryEpoch"),
161
+ seq: text("seq"),
162
+ commitment: text("commitment"),
163
+ senderVerified: r["senderVerified"] === true,
164
+ endedAt: endedAt === "unreadable" ? null : endedAt,
165
+ endedBy,
166
+ copiesInvalidBefore: cib,
167
+ };
168
+ const held = byKey.get(entry.key);
169
+ if (held !== undefined) {
170
+ defects.push(`two entries share the key "${displayUntrusted(entry.key)}" — kept the one that obliges more`);
171
+ lossless = false;
172
+ if (obligation(entry) > obligation(held))
173
+ byKey.set(entry.key, entry);
174
+ return;
175
+ }
176
+ byKey.set(entry.key, entry);
177
+ });
178
+ const entries = [...byKey.values()].sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
179
+ const summary = isObject(raw["counts"]) ? readSummary(raw) : undefined;
180
+ return {
181
+ since,
182
+ complete: statedComplete === true && lossless,
183
+ entries,
184
+ defects: summary === undefined ? defects : [...defects, ...summary.defects.map((d) => `header: ${d}`)],
185
+ ...(summary !== undefined ? { summary } : {}),
186
+ };
187
+ }
188
+ export function readShareStatesFile(text) {
189
+ let doc;
190
+ try {
191
+ doc = JSON.parse(text);
192
+ }
193
+ catch {
194
+ return { kind: "malformed", why: "the share-states file is not JSON" };
195
+ }
196
+ if (!isObject(doc))
197
+ return { kind: "malformed", why: "the share-states file is not an object" };
198
+ if (doc["v"] !== 1)
199
+ return { kind: "malformed", why: `unsupported share-states file version ${displayUntrusted(String(doc["v"]), 16)}` };
200
+ if (!Array.isArray(doc["entries"]))
201
+ return { kind: "malformed", why: "the share-states file carries no entries array" };
202
+ return { kind: "present", map: readMap(doc) };
203
+ }
204
+ export function countsOf(map) {
205
+ let live = 0, stale = 0, ended = 0, erased = 0;
206
+ for (const e of map.entries) {
207
+ if (e.status === "live")
208
+ live += 1;
209
+ else if (e.status === "stale")
210
+ stale += 1;
211
+ else if (e.status === "ended")
212
+ ended += 1;
213
+ else if (e.status === "erased")
214
+ erased += 1;
215
+ }
216
+ return { live, stale, ended, erased };
217
+ }
218
+ const countsText = (c) => `live ${c.live ?? "?"}, stale ${c.stale ?? "?"}, ended ${c.ended ?? "?"}, erased ${c.erased ?? "?"}`;
219
+ const isoOrNull = (t) => (t === null ? "null" : new Date(t).toISOString());
220
+ export function fileCurrency(summary, file) {
221
+ if (file.kind !== "present") {
222
+ return { usable: false, why: file.kind === "malformed" ? `the share-states file is unreadable (${file.why})` : "no share-states file was read" };
223
+ }
224
+ const fs = file.map.summary;
225
+ if (fs === undefined)
226
+ return { usable: false, why: "the share-states file carries no header — it cannot be placed against the recall's summary" };
227
+ if (summary.startedAt === null)
228
+ return { usable: false, why: "the recall's feed has not started — it names no process the file could belong to" };
229
+ if (fs.startedAt !== summary.startedAt)
230
+ return { usable: false, why: "the share-states file is another process's map (a different startedAt)" };
231
+ if (summary.asOf === null) {
232
+ return { usable: true, why: fs.asOf === null ? "the same process, before its first answer on both" : "the same process, and the file already holds an answer the recall's summary did not" };
233
+ }
234
+ if (fs.asOf === null)
235
+ return { usable: false, why: "the share-states file has no asOf — it cannot be placed against the recall's summary" };
236
+ if (fs.asOf < summary.asOf)
237
+ return { usable: false, why: `the share-states file lags the recall's summary by ${summary.asOf - fs.asOf} ms — a past map` };
238
+ return {
239
+ usable: true,
240
+ why: fs.asOf === summary.asOf
241
+ ? "the share-states file is the recall's map (the same process, the same asOf)"
242
+ : `the share-states file is newer than the recall's summary by ${fs.asOf - summary.asOf} ms`,
243
+ };
244
+ }
245
+ export function summaryFindings(s, baseline) {
246
+ const lines = [];
247
+ let entriesNeeded = false;
248
+ if (s.stopped !== null) {
249
+ const reason = s.stopped === "unknown" ? `an unknown reason "${s.stoppedText ?? ""}"` : s.stopped;
250
+ lines.push(`the client's feed is stopped (${reason}) — the map is not being followed; versions and erasures after it stopped are not visible`);
251
+ }
252
+ else if (s.asOf === null) {
253
+ lines.push(`the feed is starting — no answer yet from the endpoint (started ${isoOrNull(s.startedAt)}); the map holds nothing to conclude from`);
254
+ }
255
+ if (!s.complete)
256
+ lines.push(`the map is not complete${s.since === null ? " and not reconciled" : ""} — a missing key concludes nothing`);
257
+ const c = s.counts;
258
+ const fields = ["live", "stale", "ended", "erased"];
259
+ const unreadable = fields.filter((k) => c[k] === null);
260
+ if (unreadable.length > 0) {
261
+ entriesNeeded = true;
262
+ lines.push(`counts unreadable for ${unreadable.join(", ")} — the entries must be read`);
263
+ }
264
+ if ((c.erased ?? 0) > 0) {
265
+ entriesNeeded = true;
266
+ lines.push(`${c.erased} erased entr${c.erased === 1 ? "y" : "ies"} — unnamed: fetch the entries to learn which cells' copies to delete`);
267
+ }
268
+ if ((c.ended ?? 0) > 0) {
269
+ entriesNeeded = true;
270
+ lines.push(`${c.ended} ended — which ended by reconciliation (possibly erased) is unknown without the entries`);
271
+ }
272
+ if ((c.stale ?? 0) > 0) {
273
+ entriesNeeded = true;
274
+ lines.push(`${c.stale} stale — a newer version this grant cannot open; which is unknown without the entries`);
275
+ }
276
+ if (baseline === null) {
277
+ lines.push(`no kept baseline — counts ${countsText(c)} as of ${isoOrNull(s.asOf)}; the first entries read become the baseline`);
278
+ }
279
+ else {
280
+ const b = countsOf(baseline);
281
+ const moved = fields.filter((k) => c[k] !== null && c[k] !== b[k]).map((k) => `${k} ${b[k]} → ${c[k]}`);
282
+ if (moved.length > 0) {
283
+ entriesNeeded = true;
284
+ lines.push(`the map changed since the kept baseline (${moved.join(", ")}) — fetch the entries`);
285
+ }
286
+ else {
287
+ lines.push(`counts equal the kept baseline's (${countsText(c)}) — a re-share or a newer version would not show in counts; not a clean bill`);
288
+ }
289
+ }
290
+ return { lines, entriesNeeded };
291
+ }
292
+ export function mapIsWhole(map) {
293
+ return map.since !== null && map.complete;
294
+ }
295
+ export function entryFor(map, sharer, cellId) {
296
+ const key = refKey({ sharer, cellId });
297
+ return map.entries.find((e) => e.key === key);
298
+ }
299
+ export const COPY_SKEW_MS = 5 * 60_000;
300
+ export function copyStanding(read, sharer, cellId, copy) {
301
+ if (read.kind === "absent") {
302
+ return { standing: "undetermined", why: "no share map — the client does not run the feed, so versions and erasures cannot be seen" };
303
+ }
304
+ if (read.kind === "malformed")
305
+ return { standing: "undetermined", why: `the share map is malformed (${read.why})` };
306
+ if (read.kind === "summary") {
307
+ return { standing: "undetermined", why: "the recall carried the map's summary only — no entries to place the copy against; read the entries" };
308
+ }
309
+ const map = read.map;
310
+ const e = entryFor(map, sharer, cellId);
311
+ if (e !== undefined) {
312
+ if (e.status === "erased")
313
+ return { standing: "erased", why: "the entry is erased — delete the copy" };
314
+ if (e.copiesInvalidBefore === "unreadable") {
315
+ return { standing: "erased", why: "copiesInvalidBefore is present but unreadable — every copy is treated as invalid" };
316
+ }
317
+ if (e.copiesInvalidBefore !== null && !(Number.isFinite(copy.madeAt) && copy.madeAt > e.copiesInvalidBefore + COPY_SKEW_MS)) {
318
+ return { standing: "erased", why: "the copy was made before copiesInvalidBefore (the 5-minute skew allowance included) — delete it" };
319
+ }
320
+ }
321
+ if (e === undefined) {
322
+ if (mapIsWhole(map)) {
323
+ return { standing: "possibly-erased", why: "the key is missing from a whole map — its share ended before the map began, or its tombstone aged out" };
324
+ }
325
+ return {
326
+ standing: "undetermined",
327
+ why: map.since === null
328
+ ? "the key is missing, and the map has not been reconciled (since is null) — no conclusion"
329
+ : "the key is missing from an incomplete map — no conclusion",
330
+ };
331
+ }
332
+ if (e.status === "ended") {
333
+ if (!endedMayHideErasure(e)) {
334
+ return { standing: "ended", why: "revoked or expired by an event — a read already taken stands; no newer version can be fetched" };
335
+ }
336
+ return e.endedBy === "event"
337
+ ? { standing: "possibly-erased", why: "ended by an event, which cannot tell an expiry from a revocation — and an expiry can hide an erasure that was never delivered" }
338
+ : { standing: "possibly-erased", why: "ended by reconciliation, which cannot tell an erasure from a revocation" };
339
+ }
340
+ if (e.status === "stale") {
341
+ return { standing: "stale", why: "a newer version exists that this grant cannot open — keep the copy, do not fetch, wait for the grant to be wrapped again" };
342
+ }
343
+ if (e.status === "unknown") {
344
+ return { standing: "undetermined", why: `status "${displayUntrusted(e.statusText, 32)}" is not a v1 status` };
345
+ }
346
+ if (copy.grant !== undefined && e.grant !== null && copy.grant.toLowerCase() !== e.grant.toLowerCase()) {
347
+ return { standing: "superseded", why: "the copy was read under another grant — shared again since; read it again" };
348
+ }
349
+ const commitmentBoth = copy.commitment !== undefined && e.commitment !== null;
350
+ const seqBoth = copy.seq !== undefined && e.seq !== null;
351
+ if (commitmentBoth && copy.commitment.toLowerCase() !== e.commitment.toLowerCase()) {
352
+ return { standing: "superseded", why: "the entry's commitment differs from the copy's — a newer version exists; read it again" };
353
+ }
354
+ if (!commitmentBoth && seqBoth && copy.seq !== e.seq) {
355
+ return { standing: "superseded", why: "the entry's write sequence differs from the copy's — read it again" };
356
+ }
357
+ if ((copy.commitment !== undefined || copy.seq !== undefined) && !commitmentBoth && !seqBoth) {
358
+ return { standing: "undetermined", why: "the copy's version was recorded, but the entry states none to compare it with (learned from an event, not yet reconciled) — whether the copy is current cannot be seen" };
359
+ }
360
+ if (copy.grant !== undefined && e.grant === null && !commitmentBoth) {
361
+ return { standing: "undetermined", why: "the copy's grant was recorded, but the entry states none — whether the cell was shared again cannot be seen, and no commitment settles it" };
362
+ }
363
+ return mapIsWhole(map)
364
+ ? { standing: "current", why: "live in a whole map, and nothing recorded about the copy disagrees with the entry" }
365
+ : { standing: "undetermined", why: "live, but the map is incomplete or not reconciled — the entry may be out of date" };
366
+ }
367
+ export function shareObligations(read) {
368
+ if (read.kind !== "present")
369
+ return [];
370
+ const out = [];
371
+ for (const e of read.map.entries) {
372
+ if (e.status === "erased") {
373
+ out.push({ kind: "erased", entry: e, why: "erased — delete cached copies of the cell" });
374
+ }
375
+ else if (e.copiesInvalidBefore !== null) {
376
+ out.push({
377
+ kind: "copies-invalid",
378
+ entry: e,
379
+ why: e.copiesInvalidBefore === "unreadable"
380
+ ? "copiesInvalidBefore is unreadable — every copy of the cell is invalid"
381
+ : `copies made before ${new Date(e.copiesInvalidBefore).toISOString()} (plus 5 minutes) are invalid — delete them`,
382
+ });
383
+ }
384
+ else if (e.status === "ended" && endedMayHideErasure(e)) {
385
+ out.push({ kind: "possibly-erased", entry: e, why: `${endedWhy(e, false)}; review cached copies` });
386
+ }
387
+ else if (e.status === "stale") {
388
+ out.push({ kind: "stale", entry: e, why: "stale — do not fetch; the grant cannot open the newest version" });
389
+ }
390
+ }
391
+ return out;
392
+ }
393
+ export function obligationKey(o) {
394
+ const e = o.entry;
395
+ const cib = e.copiesInvalidBefore === null || e.copiesInvalidBefore === "unreadable"
396
+ ? e.copiesInvalidBefore
397
+ : new Date(e.copiesInvalidBefore).toISOString();
398
+ return JSON.stringify(["obligation", o.kind, e.key, lc(e.grant), e.commitment !== null ? lc(e.commitment) : e.seq, cib]);
399
+ }
400
+ export function pendingObligations(read, seen) {
401
+ return shareObligations(read).filter((o) => !seen.has(obligationKey(o)));
402
+ }
403
+ const sameStatedGrant = (p, c) => p.grant !== null && c.grant !== null && lc(p.grant) === lc(c.grant);
404
+ function versionMove(p, c) {
405
+ const seqBoth = p.seq !== null && c.seq !== null;
406
+ const commitmentBoth = p.commitment !== null && c.commitment !== null;
407
+ if ((seqBoth && p.seq !== c.seq) || (commitmentBoth && lc(p.commitment) !== lc(c.commitment)))
408
+ return "moved";
409
+ if (commitmentBoth)
410
+ return "unmoved";
411
+ if (seqBoth)
412
+ return sameStatedGrant(p, c) ? "unmoved" : "incomparable";
413
+ const stated = (e) => e.seq !== null || e.commitment !== null;
414
+ return stated(p) || stated(c) ? "incomparable" : "unmoved";
415
+ }
416
+ const singleWriteUnderOneGrant = (p, c) => sameStatedGrant(p, c) && c.seq === "1";
417
+ const sameCib = (a, b) => a === b;
418
+ function transitionsOfPair(p, c) {
419
+ const out = [];
420
+ const add = (kind, why) => {
421
+ out.push({ kind, key: c.key, sharer: c.sharer, cellId: c.cellId, before: p, after: c, why });
422
+ };
423
+ const readable = (s) => s === "live" || s === "stale";
424
+ if (c.status === "erased" && p.status !== "erased") {
425
+ add("erased", "erased — delete cached copies of the cell");
426
+ }
427
+ else if (c.status === "ended" && readable(p.status)) {
428
+ add("ended", endedWhy(c, false));
429
+ }
430
+ else if (readable(c.status) && (p.status === "ended" || p.status === "erased")) {
431
+ add("reshared", "shared again after it ended — a new grant; read it as new");
432
+ }
433
+ else if (readable(c.status) && readable(p.status) && p.grant !== null && c.grant !== null && lc(p.grant) !== lc(c.grant)) {
434
+ add("reshared", "the grant changed — terms changed or it was shared again; read it as new");
435
+ }
436
+ else if (c.status === "stale" && p.status === "live") {
437
+ add("stale", "a newer version exists that this grant cannot open — do not fetch");
438
+ }
439
+ else if (c.status === "live" && p.status === "stale") {
440
+ add("updated", "the grant was wrapped again for the newer version — read it again");
441
+ }
442
+ else if (c.status === "live" && p.status === "live" && versionMove(p, c) === "moved") {
443
+ add("updated", "a newer version is readable — read it again");
444
+ }
445
+ else if (c.status === "live" && p.status === "live" && versionMove(p, c) === "incomparable" && !singleWriteUnderOneGrant(p, c)) {
446
+ add("updated", c.seq === null && c.commitment === null
447
+ ? "the map no longer states this share's version — an event reset it (shared again, or written again); read it again"
448
+ : "the earlier map cannot say whether this version is newer — it states no version to compare, or no grant to count the write sequence under — and this is not a single write under one grant; read it again");
449
+ }
450
+ else if ((c.status === "unknown") !== (p.status === "unknown")) {
451
+ add("undetermined", `status moved from "${displayUntrusted(p.statusText, 32)}" to "${displayUntrusted(c.statusText, 32)}"`);
452
+ }
453
+ if (c.copiesInvalidBefore !== null && c.status !== "erased" && !sameCib(c.copiesInvalidBefore, p.copiesInvalidBefore)) {
454
+ add("copies-invalidated", "copiesInvalidBefore was set or moved — copies made before it are invalid");
455
+ }
456
+ return out;
457
+ }
458
+ function transitionsOfArrival(c) {
459
+ const out = [];
460
+ const add = (kind, why) => {
461
+ out.push({ kind, key: c.key, sharer: c.sharer, cellId: c.cellId, before: null, after: c, why });
462
+ };
463
+ if (c.status === "live")
464
+ add("new", "a share this map did not hold before");
465
+ else if (c.status === "stale")
466
+ add("new", "a share this map did not hold before — already stale: do not fetch");
467
+ else if (c.status === "ended")
468
+ add("ended", endedWhy(c, true));
469
+ else if (c.status === "erased")
470
+ add("erased", "first seen already erased — delete any cached copies");
471
+ else
472
+ add("undetermined", `first seen with status "${displayUntrusted(c.statusText, 32)}"`);
473
+ if (c.copiesInvalidBefore !== null && c.status !== "erased") {
474
+ add("copies-invalidated", "copies made before copiesInvalidBefore are invalid");
475
+ }
476
+ return out;
477
+ }
478
+ export function shareTransitions(previous, current) {
479
+ if (current.kind !== "present") {
480
+ const scope = gateScope({ unit: "share key", examined: 0, discriminating: 0, discriminator: "could be compared with an earlier map" });
481
+ if (current.kind === "summary") {
482
+ const s = current.summary;
483
+ return {
484
+ baseline: "unusable",
485
+ transitions: [],
486
+ scope,
487
+ verdict: `SUMMARY ONLY — the recall carried the map's summary without its entries (${countsText(s.counts)} as of ${isoOrNull(s.asOf)}): transitions and versions cannot be seen, and what the counts oblige is unnamed until the entries are read`,
488
+ };
489
+ }
490
+ const why = current.kind === "absent" ? "the client does not run the feed" : `the map is malformed (${current.why})`;
491
+ return {
492
+ baseline: "unusable",
493
+ transitions: [],
494
+ scope,
495
+ verdict: `NO SHARE MAP — ${why}: transitions, stale versions and erasures cannot be seen, and the listing triage is all there is`,
496
+ };
497
+ }
498
+ const cur = current.map;
499
+ if (previous === null || previous.since === null) {
500
+ const unreconciled = previous === null ? "" : " (the earlier map was never reconciled, so it is no baseline)";
501
+ return {
502
+ baseline: "first",
503
+ transitions: [],
504
+ scope: gateScope({ unit: "share key", examined: cur.entries.length, discriminating: 0, discriminator: "could be compared with an earlier map" }),
505
+ verdict: cur.since === null
506
+ ? `NO BASELINE YET${unreconciled} — the map is not reconciled, so it is not kept; transitions are reported from the first reconciled map`
507
+ : `FIRST SHARE MAP${unreconciled} — ${cur.entries.length} entr${cur.entries.length === 1 ? "y" : "ies"} kept as the baseline; transitions are reported from the next map`,
508
+ };
509
+ }
510
+ const baseline = cur.since === null ? "unreconciled" : previous.since === cur.since ? "continuous" : "restarted";
511
+ const whole = mapIsWhole(cur);
512
+ const before = new Map(previous.entries.map((e) => [e.key, e]));
513
+ const after = new Map(cur.entries.map((e) => [e.key, e]));
514
+ const keys = [...new Set([...before.keys(), ...after.keys()])].sort();
515
+ const transitions = [];
516
+ let discriminating = 0;
517
+ for (const k of keys) {
518
+ const p = before.get(k);
519
+ const c = after.get(k);
520
+ if (p !== undefined && c !== undefined) {
521
+ discriminating += 1;
522
+ transitions.push(...transitionsOfPair(p, c));
523
+ }
524
+ else if (c !== undefined) {
525
+ discriminating += 1;
526
+ transitions.push(...transitionsOfArrival(c));
527
+ }
528
+ else if (p !== undefined) {
529
+ if (p.status === "ended" || p.status === "erased") {
530
+ discriminating += 1;
531
+ continue;
532
+ }
533
+ if (whole) {
534
+ discriminating += 1;
535
+ transitions.push({ kind: "vanished", key: k, sharer: p.sharer, cellId: p.cellId, before: p, after: null,
536
+ why: "missing from a whole map, and no end was reported — possibly erased" });
537
+ }
538
+ else {
539
+ transitions.push({ kind: "undetermined", key: k, sharer: p.sharer, cellId: p.cellId, before: p, after: null,
540
+ why: cur.since === null ? "missing from an unreconciled map — no conclusion" : "missing from an incomplete map — no conclusion" });
541
+ }
542
+ }
543
+ }
544
+ const scope = gateScope({
545
+ unit: "share key",
546
+ examined: keys.length,
547
+ discriminating,
548
+ discriminator: "could be compared with an earlier map",
549
+ });
550
+ const counts = new Map();
551
+ for (const t of transitions)
552
+ counts.set(t.kind, (counts.get(t.kind) ?? 0) + 1);
553
+ const listed = [...counts].map(([k, n]) => `${n} ${k}`).join(", ");
554
+ const note = baseline === "restarted"
555
+ ? `; the map restarted at ${cur.since === null ? "?" : new Date(cur.since).toISOString()} — changes before it show only as missing keys`
556
+ : baseline === "unreconciled"
557
+ ? "; the map is not reconciled — missing keys conclude nothing"
558
+ : "";
559
+ const verdict = !scope.conclusive
560
+ ? `VERDICT WITHHELD — ${scope.note}`
561
+ : `${transitions.length === 0 ? "no transitions" : listed} across ${keys.length} key(s) (${baseline}${whole ? "" : ", not whole"})${note}`;
562
+ return { baseline, transitions, scope, verdict };
563
+ }
564
+ export function nextBaseline(previous, read) {
565
+ if (read.kind !== "present" || read.map.since === null)
566
+ return previous;
567
+ const cur = read.map;
568
+ if (cur.complete || previous === null)
569
+ return cur;
570
+ const held = new Set(cur.entries.map((e) => e.key));
571
+ const kept = previous.entries.filter((e) => !held.has(e.key));
572
+ if (kept.length === 0)
573
+ return cur;
574
+ return {
575
+ since: cur.since,
576
+ complete: false,
577
+ ...(cur.summary !== undefined ? { summary: cur.summary } : {}),
578
+ entries: [...cur.entries, ...kept].sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0)),
579
+ defects: [
580
+ ...cur.defects,
581
+ `${kept.length} entr${kept.length === 1 ? "y" : "ies"} kept from the earlier baseline — absent from a map that is not complete`,
582
+ ],
583
+ };
584
+ }
585
+ export function carryObligations(previous, read, report, seen, now) {
586
+ const byId = new Map(previous.map((o) => [o.id, o]));
587
+ let handled = 0;
588
+ for (const o of previous) {
589
+ if (seen.has(o.id) && byId.delete(o.id))
590
+ handled += 1;
591
+ }
592
+ const heldNow = new Set();
593
+ const fresh = [];
594
+ const see = (o, source) => {
595
+ if (o.kind === "stale")
596
+ return;
597
+ const id = obligationKey(o);
598
+ if (source === "entry")
599
+ heldNow.add(id);
600
+ if (seen.has(id))
601
+ return;
602
+ const was = byId.get(id);
603
+ if (was === undefined)
604
+ fresh.push(id);
605
+ const e = o.entry;
606
+ byId.set(id, {
607
+ id, kind: o.kind, key: e.key, sharer: e.sharer, cellId: e.cellId, grant: e.grant, senderVerified: e.senderVerified,
608
+ why: o.why,
609
+ source: was?.source === "entry" ? "entry" : source,
610
+ firstSeen: was?.firstSeen ?? now,
611
+ lastHeld: source === "entry" ? now : was?.lastHeld ?? null,
612
+ });
613
+ };
614
+ for (const o of shareObligations(read))
615
+ see(o, "entry");
616
+ for (const t of report?.transitions ?? []) {
617
+ if (t.kind === "vanished" && t.before !== null)
618
+ see({ kind: "possibly-erased", entry: t.before, why: t.why }, "vanished");
619
+ }
620
+ const withdrawn = [];
621
+ if (read.kind === "present") {
622
+ for (const o of [...byId.values()]) {
623
+ if (o.kind !== "possibly-erased" || heldNow.has(o.id))
624
+ continue;
625
+ const e = entryFor(read.map, o.sharer, o.cellId);
626
+ const readable = e !== undefined && (e.status === "live" || e.status === "stale") && e.copiesInvalidBefore === null;
627
+ if (readable && o.grant !== null && e.grant !== null && lc(o.grant) === lc(e.grant)) {
628
+ byId.delete(o.id);
629
+ withdrawn.push({ obligation: o, why: "the same grant is readable again with no copies invalidated — an erasure ends the grant, so the absence was the map's" });
630
+ }
631
+ }
632
+ }
633
+ const open = [...byId.values()].sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
634
+ return { open, carried: open.filter((o) => !heldNow.has(o.id)), withdrawn, added: fresh.length, fresh: fresh.sort(), handled };
635
+ }
636
+ const CARRIED_KINDS = new Set(["erased", "copies-invalid", "possibly-erased"]);
637
+ export function readObligationLedger(raw) {
638
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw))
639
+ return { open: [], defects: ["the obligation ledger is not an object"] };
640
+ const doc = raw;
641
+ if (doc["v"] !== 1)
642
+ return { open: [], defects: [`the obligation ledger's version is ${displayUntrusted(JSON.stringify(doc["v"]) ?? "absent", 32)}, not 1`] };
643
+ const rows = doc["open"];
644
+ if (!Array.isArray(rows))
645
+ return { open: [], defects: ["the obligation ledger's open is not an array"] };
646
+ const open = [];
647
+ const defects = [];
648
+ const ids = new Set();
649
+ rows.forEach((row, i) => {
650
+ const bad = (why) => { defects.push(`ledger row ${i}: ${why} — an obligation may be lost`); };
651
+ if (typeof row !== "object" || row === null || Array.isArray(row))
652
+ return bad("not an object");
653
+ const r = row;
654
+ const { id, kind, key, sharer, cellId, grant, senderVerified, why, source, firstSeen, lastHeld } = r;
655
+ if (typeof id !== "string" || typeof key !== "string" || typeof sharer !== "string" || typeof cellId !== "string" || typeof why !== "string") {
656
+ return bad("id, key, sharer, cellId and why must be strings");
657
+ }
658
+ if (typeof kind !== "string" || !CARRIED_KINDS.has(kind))
659
+ return bad(`kind ${displayUntrusted(JSON.stringify(kind) ?? "absent", 32)} is not a carried kind`);
660
+ if (grant !== null && typeof grant !== "string")
661
+ return bad("grant must be a string or null");
662
+ if (typeof senderVerified !== "boolean")
663
+ return bad("senderVerified must be a boolean");
664
+ if (source !== "entry" && source !== "vanished")
665
+ return bad("source must be entry or vanished");
666
+ if (typeof firstSeen !== "number" || !Number.isFinite(firstSeen))
667
+ return bad("firstSeen must be a finite number");
668
+ if (lastHeld !== null && (typeof lastHeld !== "number" || !Number.isFinite(lastHeld)))
669
+ return bad("lastHeld must be a finite number or null");
670
+ if (key !== refKey({ sharer, cellId }))
671
+ return bad("key is not the key of its sharer and cellId");
672
+ let named;
673
+ try {
674
+ named = JSON.parse(id);
675
+ }
676
+ catch {
677
+ named = undefined;
678
+ }
679
+ if (!Array.isArray(named) || named[0] !== "obligation" || named[1] !== kind || named[2] !== key)
680
+ return bad("id does not name this row's kind and key");
681
+ if (ids.has(id))
682
+ return bad("a second row with the same id");
683
+ ids.add(id);
684
+ open.push({ id, kind: kind, key, sharer, cellId, grant, senderVerified, why, source, firstSeen, lastHeld });
685
+ });
686
+ return { open, defects };
687
+ }
688
+ export function versionKey(e) {
689
+ const version = e.commitment !== null ? lc(e.commitment) : e.seq !== null ? `seq:${e.seq}` : null;
690
+ return JSON.stringify([e.key, lc(e.grant), version]);
691
+ }
692
+ function someVersionMarked(e, seen) {
693
+ const grant = lc(e.grant);
694
+ for (const member of seen) {
695
+ let parts;
696
+ try {
697
+ parts = JSON.parse(member);
698
+ }
699
+ catch {
700
+ continue;
701
+ }
702
+ if (Array.isArray(parts) && parts.length === 3 && parts[0] === e.key && parts[1] === grant && typeof parts[2] === "string")
703
+ return true;
704
+ }
705
+ return false;
706
+ }
707
+ export function readMarkOf(e, seen) {
708
+ if (seen.has(versionKey(e))) {
709
+ return { read: true, why: e.commitment === null && e.seq === null ? "read while the map stated no version for it" : "this version was read" };
710
+ }
711
+ if (e.commitment === null && e.seq === null && e.copiesInvalidBefore === null && someVersionMarked(e, seen)) {
712
+ return { read: false, awaitsVersion: true, why: "a version of it was read, and the map states no version to compare with yet — nothing says a newer one exists; compare again after the feed's next reconciliation" };
713
+ }
714
+ if (seen.has(e.key)) {
715
+ if (e.status === "live" && e.seq === "1" && e.copiesInvalidBefore === null) {
716
+ return { read: true, why: "read before versions were tracked, and the cell has a single write" };
717
+ }
718
+ return { read: false, why: "read before versions were tracked, and the cell was written again or its copies invalidated — read it again" };
719
+ }
720
+ return { read: false, why: "not read" };
721
+ }
722
+ export function unreadVersions(read, seen) {
723
+ if (read.kind !== "present")
724
+ return [];
725
+ const out = [];
726
+ for (const e of read.map.entries) {
727
+ if (e.status !== "live")
728
+ continue;
729
+ const m = readMarkOf(e, seen);
730
+ if (!m.read)
731
+ out.push({ entry: e, why: m.why, ...(m.awaitsVersion === true ? { awaitsVersion: true } : {}) });
732
+ }
733
+ return out;
734
+ }
735
+ export const MIN_CITED_ID_LENGTH = 8;
736
+ const ALNUM = /^[A-Za-z0-9]$/;
737
+ export function citingNotes(cellId, notes) {
738
+ if (cellId.length < MIN_CITED_ID_LENGTH) {
739
+ return { searched: false, names: [], why: `the id is shorter than ${MIN_CITED_ID_LENGTH} characters and would match ordinary text — not searched` };
740
+ }
741
+ const names = [];
742
+ for (const n of notes) {
743
+ for (let from = 0;;) {
744
+ const at = n.text.indexOf(cellId, from);
745
+ if (at < 0)
746
+ break;
747
+ const before = at === 0 ? "" : n.text[at - 1];
748
+ const after = n.text[at + cellId.length] ?? "";
749
+ if (!ALNUM.test(before) && !ALNUM.test(after)) {
750
+ names.push(n.name);
751
+ break;
752
+ }
753
+ from = at + 1;
754
+ }
755
+ }
756
+ return { searched: true, names, why: `${names.length} of ${notes.length} note(s) cite the full id; abbreviated citations are not searched` };
757
+ }
758
+ const KIND_ORDER = [
759
+ "erased", "copies-invalidated", "vanished", "ended", "reshared", "updated", "stale", "new", "undetermined",
760
+ ];
761
+ function senderPhrase(e, known) {
762
+ const who = displayUntrusted(e.sharer.slice(0, 8), 32);
763
+ const base = e.senderVerified ? `from ${who}` : `listed as from ${who} (unverified until read)`;
764
+ return known !== undefined && !sharerMatches(e.sharer, known, "known") ? `${base}, a sharer not vouched for` : base;
765
+ }
766
+ export function renderShareNotices(report, obligations, policy = {}) {
767
+ const segregated = policy.segregated ?? [];
768
+ const known = policy.known;
769
+ const lines = [`share map: ${report.verdict}`];
770
+ const isSegregated = (sharer) => segregated.length > 0 && sharerMatches(sharer, segregated, "segregated");
771
+ const segCount = new Map();
772
+ const count = (sharer) => {
773
+ const p = displayUntrusted(sharer.slice(0, 8), 32);
774
+ segCount.set(p, (segCount.get(p) ?? 0) + 1);
775
+ };
776
+ const shown = [];
777
+ for (const t of report.transitions) {
778
+ if (isSegregated(t.sharer))
779
+ count(t.sharer);
780
+ else
781
+ shown.push(t);
782
+ }
783
+ const pending = obligations.filter((o) => {
784
+ if (isSegregated(o.entry.sharer)) {
785
+ count(o.entry.sharer);
786
+ return false;
787
+ }
788
+ return true;
789
+ });
790
+ for (const [p, n] of segCount) {
791
+ lines.push(`SEGREGATED — ${n} item(s) listed as from ${p}: re-file unread; not itemised`);
792
+ }
793
+ const cite = (key) => {
794
+ const c = policy.citations?.get(key);
795
+ if (c === undefined)
796
+ return "";
797
+ if (!c.searched)
798
+ return `; notes not searched: ${c.why}`;
799
+ const names = c.names.slice(0, 8).map((n) => displayUntrusted(n, 64));
800
+ const more = c.names.length > names.length ? `, +${c.names.length - names.length} more` : "";
801
+ return c.names.length === 0
802
+ ? `; no note cites the full id (abbreviated citations are not searched)`
803
+ : `; ${c.names.length} note(s) cite it: ${names.join(", ")}${more} — flagged, never deleted automatically`;
804
+ };
805
+ shown.sort((a, b) => KIND_ORDER.indexOf(a.kind) - KIND_ORDER.indexOf(b.kind) || (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
806
+ const expressed = new Set();
807
+ for (const t of shown) {
808
+ const e = t.after ?? t.before;
809
+ const obliges = t.kind === "erased" || t.kind === "vanished" || (t.kind === "ended" && endedMayHideErasure(e));
810
+ lines.push(`${t.kind}: "${displayUntrusted(t.cellId)}" ${senderPhrase(e, known)} — ${t.why}${obliges ? cite(t.key) : ""}`);
811
+ const states = t.kind === "erased" ? "erased"
812
+ : t.kind === "copies-invalidated" ? "copies-invalid"
813
+ : t.kind === "ended" && endedMayHideErasure(e) ? "possibly-erased"
814
+ : t.kind === "stale" || (t.kind === "new" && e.status === "stale") ? "stale"
815
+ : undefined;
816
+ if (states !== undefined)
817
+ expressed.add(`${t.key}\u0000${states}`);
818
+ }
819
+ for (const o of pending) {
820
+ if (expressed.has(`${o.entry.key}\u0000${o.kind}`))
821
+ continue;
822
+ const obliges = o.kind === "erased" || o.kind === "possibly-erased" || o.kind === "copies-invalid";
823
+ lines.push(`still ${o.kind}: "${displayUntrusted(o.entry.cellId)}" ${senderPhrase(o.entry, known)} — ${o.why}${obliges ? cite(o.entry.key) : ""}`);
824
+ }
825
+ return lines;
826
+ }
827
+ export function renderCarriedObligations(carry, policy = {}) {
828
+ const segregated = policy.segregated ?? [];
829
+ const known = policy.known;
830
+ const isSegregated = (sharer) => segregated.length > 0 && sharerMatches(sharer, segregated, "segregated");
831
+ const lines = [];
832
+ const segCount = new Map();
833
+ const cite = (key) => {
834
+ const c = policy.citations?.get(key);
835
+ if (c === undefined)
836
+ return "";
837
+ if (!c.searched)
838
+ return `; notes not searched: ${c.why}`;
839
+ return c.names.length === 0
840
+ ? "; no note cites the full id (abbreviated citations are not searched)"
841
+ : `; ${c.names.length} note(s) cite it: ${c.names.slice(0, 8).map((n) => displayUntrusted(n, 64)).join(", ")}${c.names.length > 8 ? `, +${c.names.length - 8} more` : ""} — flagged, never deleted automatically`;
842
+ };
843
+ const fresh = new Set(carry.fresh);
844
+ for (const o of carry.carried) {
845
+ if (fresh.has(o.id))
846
+ continue;
847
+ if (isSegregated(o.sharer)) {
848
+ const p = displayUntrusted(o.sharer.slice(0, 8), 32);
849
+ segCount.set(p, (segCount.get(p) ?? 0) + 1);
850
+ continue;
851
+ }
852
+ const held = o.lastHeld === null ? "no map ever held it" : `last held by a map ${new Date(o.lastHeld).toISOString()}`;
853
+ lines.push(`still owed, ${o.kind} (first seen ${new Date(o.firstSeen).toISOString()}; ${held}; not in the current map): "${displayUntrusted(o.cellId)}" ${senderPhrase(o, known)} — ${o.why}${cite(o.key)}`);
854
+ }
855
+ for (const [p, n] of segCount)
856
+ lines.push(`SEGREGATED — ${n} owed item(s) listed as from ${p}: re-file unread; not itemised`);
857
+ for (const w of carry.withdrawn) {
858
+ if (isSegregated(w.obligation.sharer))
859
+ continue;
860
+ lines.push(`withdrawn, ${w.obligation.kind}: "${displayUntrusted(w.obligation.cellId)}" — ${w.why}`);
861
+ }
862
+ return lines;
863
+ }
864
+ //# sourceMappingURL=share_states.js.map