@yaks/session 0.0.0-stage → 0.2.36

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 (393) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +1392 -2
  3. package/_dist/admission.d.ts +15 -0
  4. package/_dist/admission.d.ts.map +1 -0
  5. package/_dist/announce.d.ts +17 -0
  6. package/_dist/announce.d.ts.map +1 -0
  7. package/_dist/answer.d.ts +200 -0
  8. package/_dist/answer.d.ts.map +1 -0
  9. package/_dist/append.d.ts +10 -0
  10. package/_dist/append.d.ts.map +1 -0
  11. package/_dist/archive.d.ts +6 -0
  12. package/_dist/archive.d.ts.map +1 -0
  13. package/_dist/asks.d.ts +11 -0
  14. package/_dist/asks.d.ts.map +1 -0
  15. package/_dist/audit.d.ts +15 -0
  16. package/_dist/audit.d.ts.map +1 -0
  17. package/_dist/bounce.d.ts +19 -0
  18. package/_dist/bounce.d.ts.map +1 -0
  19. package/_dist/bus.d.ts +8 -0
  20. package/_dist/bus.d.ts.map +1 -0
  21. package/_dist/cache.d.ts +45 -0
  22. package/_dist/cache.d.ts.map +1 -0
  23. package/_dist/child-notice.d.ts +6 -0
  24. package/_dist/child-notice.d.ts.map +1 -0
  25. package/_dist/children.d.ts +59 -0
  26. package/_dist/children.d.ts.map +1 -0
  27. package/_dist/cli.d.ts +8 -0
  28. package/_dist/cli.d.ts.map +1 -0
  29. package/_dist/comp.d.ts +9 -0
  30. package/_dist/comp.d.ts.map +1 -0
  31. package/_dist/compact.d.ts +19 -0
  32. package/_dist/compact.d.ts.map +1 -0
  33. package/_dist/conversation.d.ts +158 -0
  34. package/_dist/conversation.d.ts.map +1 -0
  35. package/_dist/cost.d.ts +13 -0
  36. package/_dist/cost.d.ts.map +1 -0
  37. package/_dist/deferred.d.ts +79 -0
  38. package/_dist/deferred.d.ts.map +1 -0
  39. package/_dist/ended.d.ts +27 -0
  40. package/_dist/ended.d.ts.map +1 -0
  41. package/_dist/files.d.ts +73 -0
  42. package/_dist/files.d.ts.map +1 -0
  43. package/_dist/fork.d.ts +23 -0
  44. package/_dist/fork.d.ts.map +1 -0
  45. package/_dist/graft.d.ts +33 -0
  46. package/_dist/graft.d.ts.map +1 -0
  47. package/_dist/graph.d.ts +14 -0
  48. package/_dist/graph.d.ts.map +1 -0
  49. package/_dist/handoff.d.ts +29 -0
  50. package/_dist/handoff.d.ts.map +1 -0
  51. package/_dist/imported.d.ts +63 -0
  52. package/_dist/imported.d.ts.map +1 -0
  53. package/_dist/intake.d.ts +43 -0
  54. package/_dist/intake.d.ts.map +1 -0
  55. package/_dist/joined.d.ts +35 -0
  56. package/_dist/joined.d.ts.map +1 -0
  57. package/_dist/lease.d.ts +21 -0
  58. package/_dist/lease.d.ts.map +1 -0
  59. package/_dist/lines.d.ts +13 -0
  60. package/_dist/lines.d.ts.map +1 -0
  61. package/_dist/mod.d.ts +107 -0
  62. package/_dist/mod.d.ts.map +1 -0
  63. package/_dist/naming.d.ts +10 -0
  64. package/_dist/naming.d.ts.map +1 -0
  65. package/_dist/native.d.ts +13 -0
  66. package/_dist/native.d.ts.map +1 -0
  67. package/_dist/parts.d.ts +145 -0
  68. package/_dist/parts.d.ts.map +1 -0
  69. package/_dist/plugin.d.ts +33 -0
  70. package/_dist/plugin.d.ts.map +1 -0
  71. package/_dist/project.d.ts +67 -0
  72. package/_dist/project.d.ts.map +1 -0
  73. package/_dist/prose.d.ts +7 -0
  74. package/_dist/prose.d.ts.map +1 -0
  75. package/_dist/providers.d.ts +36 -0
  76. package/_dist/providers.d.ts.map +1 -0
  77. package/_dist/reach.d.ts +39 -0
  78. package/_dist/reach.d.ts.map +1 -0
  79. package/_dist/react.d.ts +236 -0
  80. package/_dist/react.d.ts.map +1 -0
  81. package/_dist/readers.d.ts +221 -0
  82. package/_dist/readers.d.ts.map +1 -0
  83. package/_dist/reap.d.ts +21 -0
  84. package/_dist/reap.d.ts.map +1 -0
  85. package/_dist/recall.d.ts +32 -0
  86. package/_dist/recall.d.ts.map +1 -0
  87. package/_dist/routes.d.ts +15 -0
  88. package/_dist/routes.d.ts.map +1 -0
  89. package/_dist/run.d.ts +81 -0
  90. package/_dist/run.d.ts.map +1 -0
  91. package/_dist/service.d.ts +131 -0
  92. package/_dist/service.d.ts.map +1 -0
  93. package/_dist/source.d.ts +9 -0
  94. package/_dist/source.d.ts.map +1 -0
  95. package/_dist/start.d.ts +29 -0
  96. package/_dist/start.d.ts.map +1 -0
  97. package/_dist/state.d.ts +75 -0
  98. package/_dist/state.d.ts.map +1 -0
  99. package/_dist/status.d.ts +38 -0
  100. package/_dist/status.d.ts.map +1 -0
  101. package/_dist/tail.d.ts +121 -0
  102. package/_dist/tail.d.ts.map +1 -0
  103. package/_dist/timing.d.ts +9 -0
  104. package/_dist/timing.d.ts.map +1 -0
  105. package/_dist/told.d.ts +17 -0
  106. package/_dist/told.d.ts.map +1 -0
  107. package/_dist/tools.d.ts +41 -0
  108. package/_dist/tools.d.ts.map +1 -0
  109. package/_dist/transcript.d.ts +5 -0
  110. package/_dist/transcript.d.ts.map +1 -0
  111. package/_dist/turn.d.ts +49 -0
  112. package/_dist/turn.d.ts.map +1 -0
  113. package/_dist/unknown.d.ts +6 -0
  114. package/_dist/unknown.d.ts.map +1 -0
  115. package/_dist/views.d.ts +9 -0
  116. package/_dist/views.d.ts.map +1 -0
  117. package/_dist/vocab.d.ts +9 -0
  118. package/_dist/vocab.d.ts.map +1 -0
  119. package/_dist/wait.d.ts +15 -0
  120. package/_dist/wait.d.ts.map +1 -0
  121. package/_dist/wake.d.ts +116 -0
  122. package/_dist/wake.d.ts.map +1 -0
  123. package/_dist/watch.d.ts +52 -0
  124. package/_dist/watch.d.ts.map +1 -0
  125. package/_dist/who.d.ts +84 -0
  126. package/_dist/who.d.ts.map +1 -0
  127. package/_dist/window.d.ts +43 -0
  128. package/_dist/window.d.ts.map +1 -0
  129. package/admission.js +137 -0
  130. package/admission.js.map +1 -0
  131. package/admission.ts +164 -0
  132. package/announce.js +123 -0
  133. package/announce.js.map +1 -0
  134. package/announce.ts +126 -0
  135. package/answer.js +372 -0
  136. package/answer.js.map +1 -0
  137. package/answer.ts +426 -0
  138. package/append.js +125 -0
  139. package/append.js.map +1 -0
  140. package/append.ts +205 -0
  141. package/archive.js +62 -0
  142. package/archive.js.map +1 -0
  143. package/archive.ts +62 -0
  144. package/asks.js +80 -0
  145. package/asks.js.map +1 -0
  146. package/asks.ts +106 -0
  147. package/attempt.js +46 -0
  148. package/attempt.js.map +1 -0
  149. package/attempt.ts +60 -0
  150. package/audit.js +57 -0
  151. package/audit.js.map +1 -0
  152. package/audit.ts +65 -0
  153. package/bounce.js +29 -0
  154. package/bounce.js.map +1 -0
  155. package/bounce.ts +34 -0
  156. package/bus.js +568 -0
  157. package/bus.js.map +1 -0
  158. package/bus.ts +683 -0
  159. package/cache.js +169 -0
  160. package/cache.js.map +1 -0
  161. package/cache.ts +230 -0
  162. package/child-notice.js +128 -0
  163. package/child-notice.js.map +1 -0
  164. package/child-notice.ts +136 -0
  165. package/children.js +937 -0
  166. package/children.js.map +1 -0
  167. package/children.ts +925 -0
  168. package/claude-control.js +8 -0
  169. package/claude-control.js.map +1 -0
  170. package/claude-control.ts +12 -0
  171. package/cli.js +23 -0
  172. package/cli.js.map +1 -0
  173. package/cli.ts +28 -0
  174. package/comp.js +76 -0
  175. package/comp.js.map +1 -0
  176. package/comp.ts +78 -0
  177. package/compact.js +157 -0
  178. package/compact.js.map +1 -0
  179. package/compact.ts +209 -0
  180. package/compact_ask.js +280 -0
  181. package/compact_ask.js.map +1 -0
  182. package/compact_ask.ts +199 -0
  183. package/continue.js +131 -0
  184. package/continue.js.map +1 -0
  185. package/continue.ts +143 -0
  186. package/conversation.js +337 -0
  187. package/conversation.js.map +1 -0
  188. package/conversation.ts +593 -0
  189. package/cost.js +111 -0
  190. package/cost.js.map +1 -0
  191. package/cost.ts +93 -0
  192. package/deferred.js +207 -0
  193. package/deferred.js.map +1 -0
  194. package/deferred.ts +219 -0
  195. package/deno.json +1 -0
  196. package/dependencies.js +114 -0
  197. package/dependencies.js.map +1 -0
  198. package/dependencies.ts +110 -0
  199. package/draining.js +20 -0
  200. package/draining.js.map +1 -0
  201. package/draining.ts +26 -0
  202. package/ended.js +210 -0
  203. package/ended.js.map +1 -0
  204. package/ended.ts +225 -0
  205. package/files.js +285 -0
  206. package/files.js.map +1 -0
  207. package/files.ts +318 -0
  208. package/fork.js +96 -0
  209. package/fork.js.map +1 -0
  210. package/fork.ts +124 -0
  211. package/graft.js +97 -0
  212. package/graft.js.map +1 -0
  213. package/graft.ts +88 -0
  214. package/graph.js +49 -0
  215. package/graph.js.map +1 -0
  216. package/graph.ts +61 -0
  217. package/handoff.js +111 -0
  218. package/handoff.js.map +1 -0
  219. package/handoff.ts +147 -0
  220. package/help.js +432 -0
  221. package/help.js.map +1 -0
  222. package/help.ts +431 -0
  223. package/hooks.js +253 -0
  224. package/hooks.js.map +1 -0
  225. package/hooks.ts +333 -0
  226. package/imported.js +259 -0
  227. package/imported.js.map +1 -0
  228. package/imported.ts +201 -0
  229. package/inspect.js +353 -0
  230. package/inspect.js.map +1 -0
  231. package/inspect.ts +378 -0
  232. package/intake.js +115 -0
  233. package/intake.js.map +1 -0
  234. package/intake.ts +124 -0
  235. package/joined.js +67 -0
  236. package/joined.js.map +1 -0
  237. package/joined.ts +69 -0
  238. package/lease.js +146 -0
  239. package/lease.js.map +1 -0
  240. package/lease.ts +151 -0
  241. package/lifecycle.js +49 -0
  242. package/lifecycle.js.map +1 -0
  243. package/lifecycle.ts +46 -0
  244. package/lines.js +171 -0
  245. package/lines.js.map +1 -0
  246. package/lines.ts +177 -0
  247. package/listen.js +604 -0
  248. package/listen.js.map +1 -0
  249. package/listen.ts +976 -0
  250. package/log.js +78 -0
  251. package/log.js.map +1 -0
  252. package/log.ts +88 -0
  253. package/mod.js +107 -0
  254. package/mod.js.map +1 -0
  255. package/mod.ts +113 -0
  256. package/name.js +51 -0
  257. package/name.js.map +1 -0
  258. package/name.ts +84 -0
  259. package/naming.js +96 -0
  260. package/naming.js.map +1 -0
  261. package/naming.ts +102 -0
  262. package/native.js +17 -0
  263. package/native.js.map +1 -0
  264. package/native.ts +17 -0
  265. package/package.json +133 -4
  266. package/parts.js +334 -0
  267. package/parts.js.map +1 -0
  268. package/parts.ts +383 -0
  269. package/plugin.js +77 -0
  270. package/plugin.js.map +1 -0
  271. package/plugin.ts +98 -0
  272. package/project.js +354 -0
  273. package/project.js.map +1 -0
  274. package/project.ts +407 -0
  275. package/prompt.js +57 -0
  276. package/prompt.js.map +1 -0
  277. package/prompt.ts +92 -0
  278. package/prose.js +43 -0
  279. package/prose.js.map +1 -0
  280. package/prose.ts +63 -0
  281. package/providers.js +279 -0
  282. package/providers.js.map +1 -0
  283. package/providers.ts +306 -0
  284. package/pruning.js +80 -0
  285. package/pruning.js.map +1 -0
  286. package/pruning.ts +147 -0
  287. package/reach.js +923 -0
  288. package/reach.js.map +1 -0
  289. package/reach.ts +1107 -0
  290. package/react.js +2259 -0
  291. package/react.js.map +1 -0
  292. package/react.ts +2864 -0
  293. package/readers.js +956 -0
  294. package/readers.js.map +1 -0
  295. package/readers.ts +1017 -0
  296. package/reap.js +60 -0
  297. package/reap.js.map +1 -0
  298. package/reap.ts +65 -0
  299. package/recall.js +67 -0
  300. package/recall.js.map +1 -0
  301. package/recall.ts +114 -0
  302. package/reopen.js +45 -0
  303. package/reopen.js.map +1 -0
  304. package/reopen.ts +44 -0
  305. package/result-entry.js +32 -0
  306. package/result-entry.js.map +1 -0
  307. package/result-entry.ts +34 -0
  308. package/resume.js +266 -0
  309. package/resume.js.map +1 -0
  310. package/resume.ts +283 -0
  311. package/routes.js +129 -0
  312. package/routes.js.map +1 -0
  313. package/routes.ts +147 -0
  314. package/routine.js +179 -0
  315. package/routine.js.map +1 -0
  316. package/routine.ts +191 -0
  317. package/run.js +932 -0
  318. package/run.js.map +1 -0
  319. package/run.ts +999 -0
  320. package/service.js +806 -0
  321. package/service.js.map +1 -0
  322. package/service.ts +911 -0
  323. package/source.js +26 -0
  324. package/source.js.map +1 -0
  325. package/source.ts +40 -0
  326. package/start.js +197 -0
  327. package/start.js.map +1 -0
  328. package/start.ts +214 -0
  329. package/state.js +247 -0
  330. package/state.js.map +1 -0
  331. package/state.ts +404 -0
  332. package/status.js +1222 -0
  333. package/status.js.map +1 -0
  334. package/status.ts +1555 -0
  335. package/status_bench.ts +50 -0
  336. package/statusline.js +187 -0
  337. package/statusline.js.map +1 -0
  338. package/statusline.ts +232 -0
  339. package/tail.js +748 -0
  340. package/tail.js.map +1 -0
  341. package/tail.ts +815 -0
  342. package/talk.js +58 -0
  343. package/talk.js.map +1 -0
  344. package/talk.ts +51 -0
  345. package/task-context.js +41 -0
  346. package/task-context.js.map +1 -0
  347. package/task-context.ts +53 -0
  348. package/texted.js +65 -0
  349. package/texted.js.map +1 -0
  350. package/texted.ts +65 -0
  351. package/timing.js +37 -0
  352. package/timing.js.map +1 -0
  353. package/timing.ts +52 -0
  354. package/told.js +56 -0
  355. package/told.js.map +1 -0
  356. package/told.ts +54 -0
  357. package/tools.js +595 -0
  358. package/tools.js.map +1 -0
  359. package/tools.ts +633 -0
  360. package/transcript.js +34 -0
  361. package/transcript.js.map +1 -0
  362. package/transcript.ts +41 -0
  363. package/turn.js +47 -0
  364. package/turn.js.map +1 -0
  365. package/turn.ts +68 -0
  366. package/unknown.js +8 -0
  367. package/unknown.js.map +1 -0
  368. package/unknown.ts +9 -0
  369. package/views.js +15 -0
  370. package/views.js.map +1 -0
  371. package/views.ts +21 -0
  372. package/vocab.js +24 -0
  373. package/vocab.js.map +1 -0
  374. package/vocab.json +1573 -0
  375. package/vocab.ts +30 -0
  376. package/wait.js +30 -0
  377. package/wait.js.map +1 -0
  378. package/wait.ts +45 -0
  379. package/wake.js +552 -0
  380. package/wake.js.map +1 -0
  381. package/wake.ts +597 -0
  382. package/watch.js +520 -0
  383. package/watch.js.map +1 -0
  384. package/watch.ts +596 -0
  385. package/who.js +309 -0
  386. package/who.js.map +1 -0
  387. package/who.ts +347 -0
  388. package/window.js +179 -0
  389. package/window.js.map +1 -0
  390. package/window.ts +268 -0
  391. package/woken.js +129 -0
  392. package/woken.js.map +1 -0
  393. package/woken.ts +127 -0
package/reap.js ADDED
@@ -0,0 +1,60 @@
1
+ // Boot reconciliation: the locks whose holder is gone.
2
+ //
3
+ // A session that lets go of what it holds releases its claims; a session whose
4
+ // entity is deleted takes its locks with it (`death: 'release'` in the
5
+ // vocabulary). What neither covers is a lock naming a session the graph has no
6
+ // entity for at all — a holder that was never committed, or was removed on
7
+ // another store — so the graph reports that somebody is working on a document
8
+ // that nobody is working on. Nothing expires on its own (a lease with a timeout
9
+ // would have to be renewed, and a worker that is merely thinking hard would
10
+ // lose its lock mid-edit), so the correction happens at the one moment a fresh,
11
+ // reliable answer is available: start-up.
12
+ //
13
+ // A session that is merely over is ended by ./ended.ts, and its claims go with
14
+ // that: one an outside harness ran once its process is gone, one with no
15
+ // transcript file once it has been quiet and is not parked on what it holds.
16
+ //
17
+ // What is read here is exactly the locks and the sessions holding them, never
18
+ // the whole graph: locks are few by nature, since only work in progress holds
19
+ // one. It is idempotent by construction — a freed lock is gone, so the next
20
+ // start-up finds nothing to do.
21
+ import { line } from "@yaks/query";
22
+ import { after } from "@yaks/fp";
23
+ import { detached } from "@yaks/graph/storage";
24
+ import { CLAIM } from "./comp.js";
25
+ /**
26
+ * The releases a graph needs: one `claim: null` bundle per lock whose holder
27
+ * is not a session in this graph. Reads only — hand the result to `apply()` if
28
+ * you want the release journaled and its effects fired.
29
+ */ export let staleLeases = (tx)=>after(tx.read(line`.${CLAIM}.session`), (locked)=>{
30
+ if (!locked.length) return [];
31
+ // Ask whether the holder is a session through the claim's reference. The
32
+ // answer carries claims, not the holders' transcript-derived properties.
33
+ return after(tx.read(line`.${CLAIM}.session.session`), (held)=>{
34
+ let live = new Set(held.map((b)=>b.entity.eid));
35
+ return locked.filter((b)=>!live.has(b.entity.eid)).map((b)=>({
36
+ entity: {
37
+ eid: b.entity.eid
38
+ },
39
+ [CLAIM]: null
40
+ }));
41
+ });
42
+ });
43
+ /**
44
+ * Free every lock whose holder is gone, and answer with what was freed. Call
45
+ * it once at start-up, before serving:
46
+ *
47
+ * ```ts
48
+ * import { reapLeases } from '@yaks/session'
49
+ * // let freed = reapLeases(storage)
50
+ * ```
51
+ *
52
+ * The releases are written straight through storage, each its own unit of
53
+ * work, so a reap of fifty stale locks is not one transaction that must all
54
+ * land. A caller who wants them journaled instead can apply
55
+ * {@link staleLeases} through a graph.
56
+ */ export let reapLeases = (storage)=>{
57
+ let tx = detached(storage);
58
+ return after(staleLeases(tx), (freed)=>freed.length ? after(tx.patch(freed), ()=>freed) : freed);
59
+ };
60
+ //# sourceMappingURL=reap.js.map
package/reap.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reap.js","sources":["./reap.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,EAAE;AACF,+EAA+E;AAC/E,uEAAuE;AACvE,+EAA+E;AAC/E,2EAA2E;AAC3E,8EAA8E;AAC9E,gFAAgF;AAChF,4EAA4E;AAC5E,gFAAgF;AAChF,0CAA0C;AAC1C,EAAE;AACF,+EAA+E;AAC/E,yEAAyE;AACzE,6EAA6E;AAC7E,EAAE;AACF,8EAA8E;AAC9E,8EAA8E;AAC9E,4EAA4E;AAC5E,gCAAgC;AAEhC,SAAS,IAAI,2BAAgC;AAE7C,SAAS,KAAK,wBAA6B;AAC3C,SAAS,QAAQ,mCAAwC;AACzD,SAAS,KAAK,oBAAmB;AAEjC;;;;CAIC,GACD,OAAO,IAAI,cAAc,CAAC,KACxB,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,QAAQ,CAAC,GAAG,CAAC;IACvC,IAAI,CAAC,OAAO,MAAM,EAAE,OAAO,EAAE;IAC7B,yEAAyE;IACzE,yEAAyE;IACzE,OAAO,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,gBAAgB,CAAC,GAAG,CAAC;MACtD,IAAI,OAAO,IAAI,IAAS,KAAK,GAAG,CAAC,CAAC,IAAM,EAAE,MAAM,CAAC,GAAG;MACpD,OAAO,OAAO,MAAM,CAAC,CAAC,IAAM,CAAC,KAAK,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,GAC/C,GAAG,CAAC,CAAC,IAAc,CAAC;UAAE,QAAQ;YAAE,KAAK,EAAE,MAAM,CAAC,GAAG;UAAC;UAAG,CAAC,MAAM,EAAE;QAAK,CAAC;IACzE;EACF,GAAE;AAEJ;;;;;;;;;;;;;CAaC,GACD,OAAO,IAAI,aAAa,CAAC;EACvB,IAAI,KAAK,SAAS;EAClB,OAAO,MACL,YAAY,KACZ,CAAC,QAAU,MAAM,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,QAAQ,IAAM,SAAS;AAEpE,EAAC"}
package/reap.ts ADDED
@@ -0,0 +1,65 @@
1
+ // Boot reconciliation: the locks whose holder is gone.
2
+ //
3
+ // A session that lets go of what it holds releases its claims; a session whose
4
+ // entity is deleted takes its locks with it (`death: 'release'` in the
5
+ // vocabulary). What neither covers is a lock naming a session the graph has no
6
+ // entity for at all — a holder that was never committed, or was removed on
7
+ // another store — so the graph reports that somebody is working on a document
8
+ // that nobody is working on. Nothing expires on its own (a lease with a timeout
9
+ // would have to be renewed, and a worker that is merely thinking hard would
10
+ // lose its lock mid-edit), so the correction happens at the one moment a fresh,
11
+ // reliable answer is available: start-up.
12
+ //
13
+ // A session that is merely over is ended by ./ended.ts, and its claims go with
14
+ // that: one an outside harness ran once its process is gone, one with no
15
+ // transcript file once it has been quiet and is not parked on what it holds.
16
+ //
17
+ // What is read here is exactly the locks and the sessions holding them, never
18
+ // the whole graph: locks are few by nature, since only work in progress holds
19
+ // one. It is idempotent by construction — a freed lock is gone, so the next
20
+ // start-up finds nothing to do.
21
+
22
+ import { line } from '@yaks/query'
23
+ import type { Bundle, Eid, ReadTx, Storage } from 'jsr:@yaks/graph@0.2.36'
24
+ import { after } from '@yaks/fp'
25
+ import { detached } from '@yaks/graph/storage'
26
+ import { CLAIM } from './comp.js'
27
+
28
+ /**
29
+ * The releases a graph needs: one `claim: null` bundle per lock whose holder
30
+ * is not a session in this graph. Reads only — hand the result to `apply()` if
31
+ * you want the release journaled and its effects fired.
32
+ */
33
+ export let staleLeases = (tx: ReadTx): Bundle[] | Promise<Bundle[]> =>
34
+ after(tx.read(line`.${CLAIM}.session`), (locked) => {
35
+ if (!locked.length) return []
36
+ // Ask whether the holder is a session through the claim's reference. The
37
+ // answer carries claims, not the holders' transcript-derived properties.
38
+ return after(tx.read(line`.${CLAIM}.session.session`), (held) => {
39
+ let live = new Set<Eid>(held.map((b) => b.entity.eid))
40
+ return locked.filter((b) => !live.has(b.entity.eid))
41
+ .map((b): Bundle => ({ entity: { eid: b.entity.eid }, [CLAIM]: null }))
42
+ })
43
+ })
44
+
45
+ /**
46
+ * Free every lock whose holder is gone, and answer with what was freed. Call
47
+ * it once at start-up, before serving:
48
+ *
49
+ * ```ts
50
+ * import { reapLeases } from '@yaks/session'
51
+ * // let freed = reapLeases(storage)
52
+ * ```
53
+ *
54
+ * The releases are written straight through storage, each its own unit of
55
+ * work, so a reap of fifty stale locks is not one transaction that must all
56
+ * land. A caller who wants them journaled instead can apply
57
+ * {@link staleLeases} through a graph.
58
+ */
59
+ export let reapLeases = (storage: Storage): Bundle[] | Promise<Bundle[]> => {
60
+ let tx = detached(storage)
61
+ return after(
62
+ staleLeases(tx),
63
+ (freed) => freed.length ? after(tx.patch(freed), () => freed) : freed,
64
+ )
65
+ }
package/recall.js ADDED
@@ -0,0 +1,67 @@
1
+ // What the configured person said, kept and decided before on the subject of
2
+ // their words (@yaks/memory/earlier), for every door that hands those words
3
+ // to the agent answering them: the prompt hook (./routes.ts), and a comment
4
+ // or letter of theirs the bus owes a session (./bus.ts), or a session is
5
+ // started on (./start.ts). What an agent writes is answered the same way by
6
+ // @yaks/memory/graph, keyed on what it wrote. The recall gets RECALL ms and
7
+ // includes the reads that finish within that time. Failures are reported.
8
+ import { line } from "@yaks/query";
9
+ import { earlier } from "@yaks/memory/earlier";
10
+ import { words } from "./listen.js";
11
+ /** How long words wait for what was said before, before going without it. */ export let RECALL = 700;
12
+ let comp = (b, name)=>b[name] ?? {};
13
+ // What `session`'s model no longer has in front of it: what was said in
14
+ // another session, or in this one before its newest checkpoint.
15
+ let unseen = async (g, session)=>{
16
+ let [cut] = g.vocab.comp('checkpoint') ? await g.read(line`.entry.session=${session}&.checkpoint&.order=-entry.seq&.limit=1&.fields=created.at`) : [];
17
+ let at = cut && comp(cut, 'created').at;
18
+ return at ? line`(.entry.session!=${session})|(.created.at<${String(at)})` : line`(.entry.session!=${session})`;
19
+ };
20
+ /** A host's recall, each given `wait` ms; a null `wait` waits as long as it
21
+ * takes. */ export let recall = (host, wait = RECALL)=>{
22
+ let person = async ()=>{
23
+ let said = host.config?.person;
24
+ return said ? (await host.graph.address([
25
+ said
26
+ ])).get(said) ?? said : undefined;
27
+ };
28
+ let said = async (text, before, o = {})=>{
29
+ try {
30
+ return await earlier(host.graph, {
31
+ person: o.by ?? await person(),
32
+ words: text,
33
+ before,
34
+ meaning: host.meaning,
35
+ ...host.floors,
36
+ wait,
37
+ ...o.session ? {
38
+ among: await unseen(host.graph, o.session)
39
+ } : {}
40
+ });
41
+ } catch (error) {
42
+ if (!host.report) throw error;
43
+ await host.report(error);
44
+ return '';
45
+ }
46
+ };
47
+ let beside = async (owed)=>{
48
+ let theirs = (o)=>comp(o.item, 'created').by;
49
+ if (!host.config?.person || !owed.some(theirs)) return owed;
50
+ let by = await person();
51
+ return Promise.all(owed.map(async (o)=>{
52
+ if (theirs(o) != by) return o;
53
+ let found = await said(words(o.item), String(comp(o.item, 'created').at), {
54
+ by
55
+ });
56
+ return found ? {
57
+ ...o,
58
+ line: `${o.line}\n\n${found}`
59
+ } : o;
60
+ }));
61
+ };
62
+ return {
63
+ said,
64
+ beside
65
+ };
66
+ };
67
+ //# sourceMappingURL=recall.js.map
package/recall.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recall.js","sources":["./recall.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,4EAA4E;AAC5E,4EAA4E;AAC5E,yEAAyE;AACzE,4EAA4E;AAC5E,4EAA4E;AAC5E,0EAA0E;AAE1E,SAAS,IAAI,2BAAgC;AAC7C,SAAS,OAAO,oCAAyC;AAIzD,SAAS,KAAK,sBAAqB;AAEnC,2EAA2E,GAC3E,OAAO,IAAI,SAAS,IAAG;AAavB,IAAI,OAAO,CAAC,GAAW,OAAwB,CAAC,CAAC,KAAK,IAAI,CAAC;AA0B3D,wEAAwE;AACxE,gEAAgE;AAChE,IAAI,SAAS,OAAO,GAAU;EAC5B,IAAI,CAAC,IAAI,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,gBACrB,MAAM,EAAE,IAAI,CACZ,IAAI,CAAC,eAAe,EAAE,QAAQ,0DAA0D,CAAC,IAEzF,EAAE;EACN,IAAI,KAAK,OAAO,KAAK,KAAK,WAAW,EAAE;EACvC,OAAO,KACH,IAAI,CAAC,iBAAiB,EAAE,QAAQ,eAAe,EAAE,OAAO,IAAI,CAAC,CAAC,GAC9D,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;AACxC;AAEA;UACU,GACV,OAAO,IAAI,SAAS,CAClB,MACA,OAAsB,MAAM;EAE5B,IAAI,SAAS;IACX,IAAI,OAAO,KAAK,MAAM,EAAE;IACxB,OAAO,OACH,CAAC,MAAM,KAAK,KAAK,CAAC,OAAO,CAAC;MAAC;KAAK,CAAC,EAAE,GAAG,CAAC,SAAS,OAChD;EACN;EACA,IAAI,OAAO,OAAO,MAAc,QAAgB,IAAY,CAAC,CAAC;IAC5D,IAAI;MACF,OAAO,MAAM,QAAQ,KAAK,KAAK,EAAE;QAC/B,QAAQ,EAAE,EAAE,IAAI,MAAM;QACtB,OAAO;QACP;QACA,SAAS,KAAK,OAAO;QACrB,GAAG,KAAK,MAAM;QACd;QACA,GAAG,EAAE,OAAO,GAAG;UAAE,OAAO,MAAM,OAAO,KAAK,KAAK,EAAE,EAAE,OAAO;QAAE,IAAI,CAAC,CAAC;MACpE;IACF,EAAE,OAAO,OAAO;MACd,IAAI,CAAC,KAAK,MAAM,EAAE,MAAM;MACxB,MAAM,KAAK,MAAM,CAAC;MAClB,OAAO;IACT;EACF;EACA,IAAI,SAAiB,OAAO;IAC1B,IAAI,SAAS,CAAC,IAAwB,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE;IAChE,IAAI,CAAC,KAAK,MAAM,EAAE,UAAU,CAAC,KAAK,IAAI,CAAC,SAAS,OAAO;IACvD,IAAI,KAAK,MAAM;IACf,OAAO,QAAQ,GAAG,CAAC,KAAK,GAAG,CAAC,OAAO;MACjC,IAAI,OAAO,MAAM,IAAI,OAAO;MAC5B,IAAI,QAAQ,MAAM,KAChB,MAAM,EAAE,IAAI,GACZ,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,GACjC;QAAE;MAAG;MAEP,OAAO,QAAQ;QAAE,GAAG,CAAC;QAAE,MAAM,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO;MAAC,IAAI;IAC3D;EACF;EACA,OAAO;IAAE;IAAM;EAAO;AACxB,EAAC"}
package/recall.ts ADDED
@@ -0,0 +1,114 @@
1
+ // What the configured person said, kept and decided before on the subject of
2
+ // their words (@yaks/memory/earlier), for every door that hands those words
3
+ // to the agent answering them: the prompt hook (./routes.ts), and a comment
4
+ // or letter of theirs the bus owes a session (./bus.ts), or a session is
5
+ // started on (./start.ts). What an agent writes is answered the same way by
6
+ // @yaks/memory/graph, keyed on what it wrote. The recall gets RECALL ms and
7
+ // includes the reads that finish within that time. Failures are reported.
8
+
9
+ import { line } from '@yaks/query'
10
+ import { earlier } from '@yaks/memory/earlier'
11
+ import type { Bundle, Comp, Eid, Graph } from 'jsr:@yaks/graph@0.2.36'
12
+ import type { Host, Meaning } from 'jsr:@yaks/host@0.2.36'
13
+ import type { Floors } from '@yaks/memory/earlier'
14
+ import { words } from './listen.js'
15
+
16
+ /** How long words wait for what was said before, before going without it. */
17
+ export let RECALL = 700
18
+
19
+ /** What a host recalls with: its person, and its ranking by meaning. */
20
+ export type Recalling = {
21
+ graph: Graph
22
+ config?: { person?: string }
23
+ meaning?: Meaning
24
+ /** how near its meaning's model puts what is recalled, where it is not the
25
+ * model @yaks/memory's floors were measured on */
26
+ floors?: Floors
27
+ report?: Host['report']
28
+ }
29
+
30
+ let comp = (b: Bundle, name: string): Comp => (b[name] ?? {}) as Comp
31
+
32
+ /** What sets beside a person's words what they said before. */
33
+ export type Beside = <T extends { item: Bundle; line: string }>(
34
+ owed: T[],
35
+ ) => Promise<T[]>
36
+
37
+ /** Whose words a recall answers, and for which session's model. */
38
+ export type Saying = {
39
+ /** who said them, where not the host's person */
40
+ by?: string
41
+ /** the session whose model is given what is recalled: what it still has in
42
+ * front of it (its own lines since its newest checkpoint) is left out */
43
+ session?: Eid
44
+ }
45
+
46
+ /** A host's recall. */
47
+ export type Recall = {
48
+ /** what the host's person (or `by`) said before `before` on the subject of
49
+ * `words`, beyond what `session` already holds */
50
+ said: (words: string, before: string, o?: Saying) => Promise<string>
51
+ /** these items, with it under the line of each one the person wrote where
52
+ * there is any */
53
+ beside: Beside
54
+ }
55
+
56
+ // What `session`'s model no longer has in front of it: what was said in
57
+ // another session, or in this one before its newest checkpoint.
58
+ let unseen = async (g: Graph, session: Eid) => {
59
+ let [cut] = g.vocab.comp('checkpoint')
60
+ ? await g.read(
61
+ line`.entry.session=${session}&.checkpoint&.order=-entry.seq&.limit=1&.fields=created.at`,
62
+ )
63
+ : []
64
+ let at = cut && comp(cut, 'created').at
65
+ return at
66
+ ? line`(.entry.session!=${session})|(.created.at<${String(at)})`
67
+ : line`(.entry.session!=${session})`
68
+ }
69
+
70
+ /** A host's recall, each given `wait` ms; a null `wait` waits as long as it
71
+ * takes. */
72
+ export let recall = (
73
+ host: Recalling,
74
+ wait: number | null = RECALL,
75
+ ): Recall => {
76
+ let person = async () => {
77
+ let said = host.config?.person
78
+ return said
79
+ ? (await host.graph.address([said])).get(said) ?? said
80
+ : undefined
81
+ }
82
+ let said = async (text: string, before: string, o: Saying = {}) => {
83
+ try {
84
+ return await earlier(host.graph, {
85
+ person: o.by ?? await person(),
86
+ words: text,
87
+ before,
88
+ meaning: host.meaning,
89
+ ...host.floors,
90
+ wait,
91
+ ...o.session ? { among: await unseen(host.graph, o.session) } : {},
92
+ })
93
+ } catch (error) {
94
+ if (!host.report) throw error
95
+ await host.report(error)
96
+ return ''
97
+ }
98
+ }
99
+ let beside: Beside = async (owed) => {
100
+ let theirs = (o: { item: Bundle }) => comp(o.item, 'created').by
101
+ if (!host.config?.person || !owed.some(theirs)) return owed
102
+ let by = await person()
103
+ return Promise.all(owed.map(async (o) => {
104
+ if (theirs(o) != by) return o
105
+ let found = await said(
106
+ words(o.item),
107
+ String(comp(o.item, 'created').at),
108
+ { by },
109
+ )
110
+ return found ? { ...o, line: `${o.line}\n\n${found}` } : o
111
+ }))
112
+ }
113
+ return { said, beside }
114
+ }
package/reopen.js ADDED
@@ -0,0 +1,45 @@
1
+ // `session.ended` says a session is at rest for good, until something new is
2
+ // said to it. Whatever door the words come through, input on the transcript or
3
+ // a knock or letter addressed to it, the mark goes in the same batch, so what
4
+ // was said is read and answered. A line imported from an outside harness's log
5
+ // is that harness's record, not something said to it (`session_context` clears
6
+ // the mark when the harness resumes).
7
+ import { after } from "@yaks/fp";
8
+ import { hook } from "@yaks/graph/plugin";
9
+ import { and, eq, fields, list, present } from "@yaks/query";
10
+ import { SESSION } from "./comp.js";
11
+ import { kindOf } from "./state.js";
12
+ let named = (b, comp, prop)=>{
13
+ let id = b[comp]?.[prop];
14
+ return typeof id == 'string' ? [
15
+ id
16
+ ] : [];
17
+ };
18
+ // The session this bundle says something to, if it does.
19
+ let addressed = (b)=>[
20
+ ...!b.lines && kindOf(b) == 'input' ? named(b, 'entry', 'session') : [],
21
+ ...named(b, 'knock', 'target'),
22
+ ...named(b, 'deliver', 'to')
23
+ ];
24
+ export let reopening = hook([
25
+ 'entry',
26
+ 'knock',
27
+ 'deliver'
28
+ ], (bundles, tx)=>{
29
+ let ids = [
30
+ ...new Set(bundles.flatMap(addressed))
31
+ ];
32
+ if (!ids.length) return bundles;
33
+ return after(tx.read(and(eq('entity.eid', list(...ids)), present(`${SESSION}.ended`), fields('entity.eid'))), (marked)=>[
34
+ ...bundles,
35
+ ...marked.map((m)=>({
36
+ entity: {
37
+ eid: m.entity.eid
38
+ },
39
+ [SESSION]: {
40
+ ended: null
41
+ }
42
+ }))
43
+ ]);
44
+ });
45
+ //# sourceMappingURL=reopen.js.map
package/reopen.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reopen.js","sources":["./reopen.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,+EAA+E;AAC/E,8EAA8E;AAC9E,+EAA+E;AAC/E,+EAA+E;AAC/E,sCAAsC;AAEtC,SAAS,KAAK,wBAA6B;AAE3C,SAAS,IAAI,kCAAuC;AACpD,SAAS,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,2BAAgC;AACvE,SAAS,OAAO,oBAAmB;AACnC,SAAS,MAAM,qBAAoB;AAEnC,IAAI,QAAQ,CAAC,GAAW,MAAc;EACpC,IAAI,KAAM,CAAC,CAAC,KAAK,EAAuB,CAAC,KAAK;EAC9C,OAAO,OAAO,MAAM,WAAW;IAAC;GAAG,GAAG,EAAE;AAC1C;AAEA,yDAAyD;AACzD,IAAI,YAAY,CAAC,IAAwB;OACpC,CAAC,EAAE,KAAK,IAAI,OAAO,MAAM,UAAU,MAAM,GAAG,SAAS,aAAa,EAAE;OACpE,MAAM,GAAG,SAAS;OAClB,MAAM,GAAG,WAAW;GACxB;AAED,OAAO,IAAI,YAAY,KAAK;EAAC;EAAS;EAAS;CAAU,EAAE,CAAC,SAAS;EACnE,IAAI,MAAM;OAAI,IAAI,IAAI,QAAQ,OAAO,CAAC;GAAY;EAClD,IAAI,CAAC,IAAI,MAAM,EAAE,OAAO;EACxB,OAAO,MACL,GAAG,IAAI,CAAC,IACN,GAAG,cAAc,QAAQ,OACzB,QAAQ,GAAG,QAAQ,MAAM,CAAC,GAC1B,OAAO,iBAET,CAAC,SAAW;SACP;SACA,OAAO,GAAG,CAAC,CAAC,IAAc,CAAC;UAC5B,QAAQ;YAAE,KAAK,EAAE,MAAM,CAAC,GAAG;UAAC;UAC5B,CAAC,QAAQ,EAAE;YAAE,OAAO;UAAK;QAC3B,CAAC;KACF;AAEL,GAAE"}
package/reopen.ts ADDED
@@ -0,0 +1,44 @@
1
+ // `session.ended` says a session is at rest for good, until something new is
2
+ // said to it. Whatever door the words come through, input on the transcript or
3
+ // a knock or letter addressed to it, the mark goes in the same batch, so what
4
+ // was said is read and answered. A line imported from an outside harness's log
5
+ // is that harness's record, not something said to it (`session_context` clears
6
+ // the mark when the harness resumes).
7
+
8
+ import { after } from '@yaks/fp'
9
+ import type { Bundle, Comp } from 'jsr:@yaks/graph@0.2.36/bundle'
10
+ import { hook } from '@yaks/graph/plugin'
11
+ import { and, eq, fields, list, present } from '@yaks/query'
12
+ import { SESSION } from './comp.js'
13
+ import { kindOf } from './state.js'
14
+
15
+ let named = (b: Bundle, comp: string, prop: string): string[] => {
16
+ let id = (b[comp] as Comp | undefined)?.[prop]
17
+ return typeof id == 'string' ? [id] : []
18
+ }
19
+
20
+ // The session this bundle says something to, if it does.
21
+ let addressed = (b: Bundle): string[] => [
22
+ ...!b.lines && kindOf(b) == 'input' ? named(b, 'entry', 'session') : [],
23
+ ...named(b, 'knock', 'target'),
24
+ ...named(b, 'deliver', 'to'),
25
+ ]
26
+
27
+ export let reopening = hook(['entry', 'knock', 'deliver'], (bundles, tx) => {
28
+ let ids = [...new Set(bundles.flatMap(addressed))]
29
+ if (!ids.length) return bundles
30
+ return after(
31
+ tx.read(and(
32
+ eq('entity.eid', list(...ids)),
33
+ present(`${SESSION}.ended`),
34
+ fields('entity.eid'),
35
+ )),
36
+ (marked) => [
37
+ ...bundles,
38
+ ...marked.map((m): Bundle => ({
39
+ entity: { eid: m.entity.eid },
40
+ [SESSION]: { ended: null },
41
+ })),
42
+ ],
43
+ )
44
+ })
@@ -0,0 +1,32 @@
1
+ /** Session association is a rule, not a responsibility of the tool executor. */ import { after } from "@yaks/fp";
2
+ /** Add transcript membership only when absent. Sequencing is a separate rule.
3
+ * Execution diagnostics use output.source to identify the same call.
4
+ */ export const resultEntries = (bundles, tx)=>{
5
+ const source = (b)=>{
6
+ if (b.result) return b.result.call;
7
+ if (b.refusal || b.interrupted || b.exception) {
8
+ return b.output?.source;
9
+ }
10
+ };
11
+ const candidates = bundles.filter((b)=>!('entry' in b) && source(b) != null);
12
+ if (!candidates.length) return bundles;
13
+ return after(tx.get(candidates.map((b)=>b.entity.eid)), (existing)=>{
14
+ const lacking = candidates.filter((b)=>!existing.some((v)=>v.entity.eid == b.entity.eid && v.entry));
15
+ return after(tx.get(lacking.map((b)=>String(source(b)))), (sources)=>{
16
+ return bundles.map((b)=>{
17
+ if (!lacking.includes(b)) return b;
18
+ const id = String(source(b));
19
+ const call = bundles.find((v)=>v.entity.eid == id && v.entry) ?? sources.find((v)=>v.entity.eid == id);
20
+ const entry = call?.entry;
21
+ if (!call?.call || entry?.session == null) return b;
22
+ return {
23
+ ...b,
24
+ entry: {
25
+ session: entry.session
26
+ }
27
+ };
28
+ });
29
+ });
30
+ });
31
+ };
32
+ //# sourceMappingURL=result-entry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result-entry.js","sources":["./result-entry.ts"],"names":[],"mappings":"AAAA,8EAA8E,GAC9E,SAAS,KAAK,wBAA6B;AAI3C;;CAEC,GACD,OAAO,MAAM,gBAAsB,CAAC,SAAS;EAC3C,MAAM,SAAS,CAAC;IACd,IAAI,EAAE,MAAM,EAAE,OAAO,AAAC,EAAE,MAAM,CAAU,IAAI;IAC5C,IAAI,EAAE,OAAO,IAAI,EAAE,WAAW,IAAI,EAAE,SAAS,EAAE;MAC7C,OAAQ,EAAE,MAAM,EAAuB;IACzC;EACF;EACA,MAAM,aAAa,QAAQ,MAAM,CAAC,CAAC,IAAM,CAAC,CAAC,WAAW,CAAC,KAAK,OAAO,MAAM;EACzE,IAAI,CAAC,WAAW,MAAM,EAAE,OAAO;EAC/B,OAAO,MAAM,GAAG,GAAG,CAAC,WAAW,GAAG,CAAC,CAAC,IAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IACzD,MAAM,UAAU,WAAW,MAAM,CAAC,CAAC,IACjC,CAAC,SAAS,IAAI,CAAC,CAAC,IAAM,EAAE,MAAM,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,GAAG,IAAI,EAAE,KAAK;IAE/D,OAAO,MAAM,GAAG,GAAG,CAAC,QAAQ,GAAG,CAAC,CAAC,IAAM,OAAO,OAAO,OAAO,CAAC;MAC3D,OAAO,QAAQ,GAAG,CAAC,CAAC;QAClB,IAAI,CAAC,QAAQ,QAAQ,CAAC,IAAI,OAAO;QACjC,MAAM,KAAK,OAAO,OAAO;QACzB,MAAM,OAAO,QAAQ,IAAI,CAAC,CAAC,IAAM,EAAE,MAAM,CAAC,GAAG,IAAI,MAAM,EAAE,KAAK,KAC5D,QAAQ,IAAI,CAAC,CAAC,IAAM,EAAE,MAAM,CAAC,GAAG,IAAI;QACtC,MAAM,QAAQ,MAAM;QACpB,IAAI,CAAC,MAAM,QAAQ,OAAO,WAAW,MAAM,OAAO;QAClD,OAAO;UAAE,GAAG,CAAC;UAAE,OAAO;YAAE,SAAS,MAAM,OAAO;UAAC;QAAE;MACnD;IACF;EACF;AACF,EAAC"}
@@ -0,0 +1,34 @@
1
+ /** Session association is a rule, not a responsibility of the tool executor. */
2
+ import { after } from '@yaks/fp'
3
+ import type { Bundle, Comp } from 'jsr:@yaks/graph@0.2.36/bundle'
4
+ import type { Hook } from 'jsr:@yaks/graph@0.2.36/plugin'
5
+
6
+ /** Add transcript membership only when absent. Sequencing is a separate rule.
7
+ * Execution diagnostics use output.source to identify the same call.
8
+ */
9
+ export const resultEntries: Hook = (bundles, tx) => {
10
+ const source = (b: Bundle) => {
11
+ if (b.result) return (b.result as Comp).call
12
+ if (b.refusal || b.interrupted || b.exception) {
13
+ return (b.output as Comp | undefined)?.source
14
+ }
15
+ }
16
+ const candidates = bundles.filter((b) => !('entry' in b) && source(b) != null)
17
+ if (!candidates.length) return bundles
18
+ return after(tx.get(candidates.map((b) => b.entity.eid)), (existing) => {
19
+ const lacking = candidates.filter((b) =>
20
+ !existing.some((v) => v.entity.eid == b.entity.eid && v.entry)
21
+ )
22
+ return after(tx.get(lacking.map((b) => String(source(b)))), (sources) => {
23
+ return bundles.map((b) => {
24
+ if (!lacking.includes(b)) return b
25
+ const id = String(source(b))
26
+ const call = bundles.find((v) => v.entity.eid == id && v.entry) ??
27
+ sources.find((v) => v.entity.eid == id)
28
+ const entry = call?.entry as Comp | undefined
29
+ if (!call?.call || entry?.session == null) return b
30
+ return { ...b, entry: { session: entry.session } }
31
+ })
32
+ })
33
+ })
34
+ }