@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.
- package/LICENSE +202 -0
- package/README.md +1392 -2
- package/_dist/admission.d.ts +15 -0
- package/_dist/admission.d.ts.map +1 -0
- package/_dist/announce.d.ts +17 -0
- package/_dist/announce.d.ts.map +1 -0
- package/_dist/answer.d.ts +200 -0
- package/_dist/answer.d.ts.map +1 -0
- package/_dist/append.d.ts +10 -0
- package/_dist/append.d.ts.map +1 -0
- package/_dist/archive.d.ts +6 -0
- package/_dist/archive.d.ts.map +1 -0
- package/_dist/asks.d.ts +11 -0
- package/_dist/asks.d.ts.map +1 -0
- package/_dist/audit.d.ts +15 -0
- package/_dist/audit.d.ts.map +1 -0
- package/_dist/bounce.d.ts +19 -0
- package/_dist/bounce.d.ts.map +1 -0
- package/_dist/bus.d.ts +8 -0
- package/_dist/bus.d.ts.map +1 -0
- package/_dist/cache.d.ts +45 -0
- package/_dist/cache.d.ts.map +1 -0
- package/_dist/child-notice.d.ts +6 -0
- package/_dist/child-notice.d.ts.map +1 -0
- package/_dist/children.d.ts +59 -0
- package/_dist/children.d.ts.map +1 -0
- package/_dist/cli.d.ts +8 -0
- package/_dist/cli.d.ts.map +1 -0
- package/_dist/comp.d.ts +9 -0
- package/_dist/comp.d.ts.map +1 -0
- package/_dist/compact.d.ts +19 -0
- package/_dist/compact.d.ts.map +1 -0
- package/_dist/conversation.d.ts +158 -0
- package/_dist/conversation.d.ts.map +1 -0
- package/_dist/cost.d.ts +13 -0
- package/_dist/cost.d.ts.map +1 -0
- package/_dist/deferred.d.ts +79 -0
- package/_dist/deferred.d.ts.map +1 -0
- package/_dist/ended.d.ts +27 -0
- package/_dist/ended.d.ts.map +1 -0
- package/_dist/files.d.ts +73 -0
- package/_dist/files.d.ts.map +1 -0
- package/_dist/fork.d.ts +23 -0
- package/_dist/fork.d.ts.map +1 -0
- package/_dist/graft.d.ts +33 -0
- package/_dist/graft.d.ts.map +1 -0
- package/_dist/graph.d.ts +14 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/handoff.d.ts +29 -0
- package/_dist/handoff.d.ts.map +1 -0
- package/_dist/imported.d.ts +63 -0
- package/_dist/imported.d.ts.map +1 -0
- package/_dist/intake.d.ts +43 -0
- package/_dist/intake.d.ts.map +1 -0
- package/_dist/joined.d.ts +35 -0
- package/_dist/joined.d.ts.map +1 -0
- package/_dist/lease.d.ts +21 -0
- package/_dist/lease.d.ts.map +1 -0
- package/_dist/lines.d.ts +13 -0
- package/_dist/lines.d.ts.map +1 -0
- package/_dist/mod.d.ts +107 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/naming.d.ts +10 -0
- package/_dist/naming.d.ts.map +1 -0
- package/_dist/native.d.ts +13 -0
- package/_dist/native.d.ts.map +1 -0
- package/_dist/parts.d.ts +145 -0
- package/_dist/parts.d.ts.map +1 -0
- package/_dist/plugin.d.ts +33 -0
- package/_dist/plugin.d.ts.map +1 -0
- package/_dist/project.d.ts +67 -0
- package/_dist/project.d.ts.map +1 -0
- package/_dist/prose.d.ts +7 -0
- package/_dist/prose.d.ts.map +1 -0
- package/_dist/providers.d.ts +36 -0
- package/_dist/providers.d.ts.map +1 -0
- package/_dist/reach.d.ts +39 -0
- package/_dist/reach.d.ts.map +1 -0
- package/_dist/react.d.ts +236 -0
- package/_dist/react.d.ts.map +1 -0
- package/_dist/readers.d.ts +221 -0
- package/_dist/readers.d.ts.map +1 -0
- package/_dist/reap.d.ts +21 -0
- package/_dist/reap.d.ts.map +1 -0
- package/_dist/recall.d.ts +32 -0
- package/_dist/recall.d.ts.map +1 -0
- package/_dist/routes.d.ts +15 -0
- package/_dist/routes.d.ts.map +1 -0
- package/_dist/run.d.ts +81 -0
- package/_dist/run.d.ts.map +1 -0
- package/_dist/service.d.ts +131 -0
- package/_dist/service.d.ts.map +1 -0
- package/_dist/source.d.ts +9 -0
- package/_dist/source.d.ts.map +1 -0
- package/_dist/start.d.ts +29 -0
- package/_dist/start.d.ts.map +1 -0
- package/_dist/state.d.ts +75 -0
- package/_dist/state.d.ts.map +1 -0
- package/_dist/status.d.ts +38 -0
- package/_dist/status.d.ts.map +1 -0
- package/_dist/tail.d.ts +121 -0
- package/_dist/tail.d.ts.map +1 -0
- package/_dist/timing.d.ts +9 -0
- package/_dist/timing.d.ts.map +1 -0
- package/_dist/told.d.ts +17 -0
- package/_dist/told.d.ts.map +1 -0
- package/_dist/tools.d.ts +41 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/transcript.d.ts +5 -0
- package/_dist/transcript.d.ts.map +1 -0
- package/_dist/turn.d.ts +49 -0
- package/_dist/turn.d.ts.map +1 -0
- package/_dist/unknown.d.ts +6 -0
- package/_dist/unknown.d.ts.map +1 -0
- package/_dist/views.d.ts +9 -0
- package/_dist/views.d.ts.map +1 -0
- package/_dist/vocab.d.ts +9 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/_dist/wait.d.ts +15 -0
- package/_dist/wait.d.ts.map +1 -0
- package/_dist/wake.d.ts +116 -0
- package/_dist/wake.d.ts.map +1 -0
- package/_dist/watch.d.ts +52 -0
- package/_dist/watch.d.ts.map +1 -0
- package/_dist/who.d.ts +84 -0
- package/_dist/who.d.ts.map +1 -0
- package/_dist/window.d.ts +43 -0
- package/_dist/window.d.ts.map +1 -0
- package/admission.js +137 -0
- package/admission.js.map +1 -0
- package/admission.ts +164 -0
- package/announce.js +123 -0
- package/announce.js.map +1 -0
- package/announce.ts +126 -0
- package/answer.js +372 -0
- package/answer.js.map +1 -0
- package/answer.ts +426 -0
- package/append.js +125 -0
- package/append.js.map +1 -0
- package/append.ts +205 -0
- package/archive.js +62 -0
- package/archive.js.map +1 -0
- package/archive.ts +62 -0
- package/asks.js +80 -0
- package/asks.js.map +1 -0
- package/asks.ts +106 -0
- package/attempt.js +46 -0
- package/attempt.js.map +1 -0
- package/attempt.ts +60 -0
- package/audit.js +57 -0
- package/audit.js.map +1 -0
- package/audit.ts +65 -0
- package/bounce.js +29 -0
- package/bounce.js.map +1 -0
- package/bounce.ts +34 -0
- package/bus.js +568 -0
- package/bus.js.map +1 -0
- package/bus.ts +683 -0
- package/cache.js +169 -0
- package/cache.js.map +1 -0
- package/cache.ts +230 -0
- package/child-notice.js +128 -0
- package/child-notice.js.map +1 -0
- package/child-notice.ts +136 -0
- package/children.js +937 -0
- package/children.js.map +1 -0
- package/children.ts +925 -0
- package/claude-control.js +8 -0
- package/claude-control.js.map +1 -0
- package/claude-control.ts +12 -0
- package/cli.js +23 -0
- package/cli.js.map +1 -0
- package/cli.ts +28 -0
- package/comp.js +76 -0
- package/comp.js.map +1 -0
- package/comp.ts +78 -0
- package/compact.js +157 -0
- package/compact.js.map +1 -0
- package/compact.ts +209 -0
- package/compact_ask.js +280 -0
- package/compact_ask.js.map +1 -0
- package/compact_ask.ts +199 -0
- package/continue.js +131 -0
- package/continue.js.map +1 -0
- package/continue.ts +143 -0
- package/conversation.js +337 -0
- package/conversation.js.map +1 -0
- package/conversation.ts +593 -0
- package/cost.js +111 -0
- package/cost.js.map +1 -0
- package/cost.ts +93 -0
- package/deferred.js +207 -0
- package/deferred.js.map +1 -0
- package/deferred.ts +219 -0
- package/deno.json +1 -0
- package/dependencies.js +114 -0
- package/dependencies.js.map +1 -0
- package/dependencies.ts +110 -0
- package/draining.js +20 -0
- package/draining.js.map +1 -0
- package/draining.ts +26 -0
- package/ended.js +210 -0
- package/ended.js.map +1 -0
- package/ended.ts +225 -0
- package/files.js +285 -0
- package/files.js.map +1 -0
- package/files.ts +318 -0
- package/fork.js +96 -0
- package/fork.js.map +1 -0
- package/fork.ts +124 -0
- package/graft.js +97 -0
- package/graft.js.map +1 -0
- package/graft.ts +88 -0
- package/graph.js +49 -0
- package/graph.js.map +1 -0
- package/graph.ts +61 -0
- package/handoff.js +111 -0
- package/handoff.js.map +1 -0
- package/handoff.ts +147 -0
- package/help.js +432 -0
- package/help.js.map +1 -0
- package/help.ts +431 -0
- package/hooks.js +253 -0
- package/hooks.js.map +1 -0
- package/hooks.ts +333 -0
- package/imported.js +259 -0
- package/imported.js.map +1 -0
- package/imported.ts +201 -0
- package/inspect.js +353 -0
- package/inspect.js.map +1 -0
- package/inspect.ts +378 -0
- package/intake.js +115 -0
- package/intake.js.map +1 -0
- package/intake.ts +124 -0
- package/joined.js +67 -0
- package/joined.js.map +1 -0
- package/joined.ts +69 -0
- package/lease.js +146 -0
- package/lease.js.map +1 -0
- package/lease.ts +151 -0
- package/lifecycle.js +49 -0
- package/lifecycle.js.map +1 -0
- package/lifecycle.ts +46 -0
- package/lines.js +171 -0
- package/lines.js.map +1 -0
- package/lines.ts +177 -0
- package/listen.js +604 -0
- package/listen.js.map +1 -0
- package/listen.ts +976 -0
- package/log.js +78 -0
- package/log.js.map +1 -0
- package/log.ts +88 -0
- package/mod.js +107 -0
- package/mod.js.map +1 -0
- package/mod.ts +113 -0
- package/name.js +51 -0
- package/name.js.map +1 -0
- package/name.ts +84 -0
- package/naming.js +96 -0
- package/naming.js.map +1 -0
- package/naming.ts +102 -0
- package/native.js +17 -0
- package/native.js.map +1 -0
- package/native.ts +17 -0
- package/package.json +133 -4
- package/parts.js +334 -0
- package/parts.js.map +1 -0
- package/parts.ts +383 -0
- package/plugin.js +77 -0
- package/plugin.js.map +1 -0
- package/plugin.ts +98 -0
- package/project.js +354 -0
- package/project.js.map +1 -0
- package/project.ts +407 -0
- package/prompt.js +57 -0
- package/prompt.js.map +1 -0
- package/prompt.ts +92 -0
- package/prose.js +43 -0
- package/prose.js.map +1 -0
- package/prose.ts +63 -0
- package/providers.js +279 -0
- package/providers.js.map +1 -0
- package/providers.ts +306 -0
- package/pruning.js +80 -0
- package/pruning.js.map +1 -0
- package/pruning.ts +147 -0
- package/reach.js +923 -0
- package/reach.js.map +1 -0
- package/reach.ts +1107 -0
- package/react.js +2259 -0
- package/react.js.map +1 -0
- package/react.ts +2864 -0
- package/readers.js +956 -0
- package/readers.js.map +1 -0
- package/readers.ts +1017 -0
- package/reap.js +60 -0
- package/reap.js.map +1 -0
- package/reap.ts +65 -0
- package/recall.js +67 -0
- package/recall.js.map +1 -0
- package/recall.ts +114 -0
- package/reopen.js +45 -0
- package/reopen.js.map +1 -0
- package/reopen.ts +44 -0
- package/result-entry.js +32 -0
- package/result-entry.js.map +1 -0
- package/result-entry.ts +34 -0
- package/resume.js +266 -0
- package/resume.js.map +1 -0
- package/resume.ts +283 -0
- package/routes.js +129 -0
- package/routes.js.map +1 -0
- package/routes.ts +147 -0
- package/routine.js +179 -0
- package/routine.js.map +1 -0
- package/routine.ts +191 -0
- package/run.js +932 -0
- package/run.js.map +1 -0
- package/run.ts +999 -0
- package/service.js +806 -0
- package/service.js.map +1 -0
- package/service.ts +911 -0
- package/source.js +26 -0
- package/source.js.map +1 -0
- package/source.ts +40 -0
- package/start.js +197 -0
- package/start.js.map +1 -0
- package/start.ts +214 -0
- package/state.js +247 -0
- package/state.js.map +1 -0
- package/state.ts +404 -0
- package/status.js +1222 -0
- package/status.js.map +1 -0
- package/status.ts +1555 -0
- package/status_bench.ts +50 -0
- package/statusline.js +187 -0
- package/statusline.js.map +1 -0
- package/statusline.ts +232 -0
- package/tail.js +748 -0
- package/tail.js.map +1 -0
- package/tail.ts +815 -0
- package/talk.js +58 -0
- package/talk.js.map +1 -0
- package/talk.ts +51 -0
- package/task-context.js +41 -0
- package/task-context.js.map +1 -0
- package/task-context.ts +53 -0
- package/texted.js +65 -0
- package/texted.js.map +1 -0
- package/texted.ts +65 -0
- package/timing.js +37 -0
- package/timing.js.map +1 -0
- package/timing.ts +52 -0
- package/told.js +56 -0
- package/told.js.map +1 -0
- package/told.ts +54 -0
- package/tools.js +595 -0
- package/tools.js.map +1 -0
- package/tools.ts +633 -0
- package/transcript.js +34 -0
- package/transcript.js.map +1 -0
- package/transcript.ts +41 -0
- package/turn.js +47 -0
- package/turn.js.map +1 -0
- package/turn.ts +68 -0
- package/unknown.js +8 -0
- package/unknown.js.map +1 -0
- package/unknown.ts +9 -0
- package/views.js +15 -0
- package/views.js.map +1 -0
- package/views.ts +21 -0
- package/vocab.js +24 -0
- package/vocab.js.map +1 -0
- package/vocab.json +1573 -0
- package/vocab.ts +30 -0
- package/wait.js +30 -0
- package/wait.js.map +1 -0
- package/wait.ts +45 -0
- package/wake.js +552 -0
- package/wake.js.map +1 -0
- package/wake.ts +597 -0
- package/watch.js +520 -0
- package/watch.js.map +1 -0
- package/watch.ts +596 -0
- package/who.js +309 -0
- package/who.js.map +1 -0
- package/who.ts +347 -0
- package/window.js +179 -0
- package/window.js.map +1 -0
- package/window.ts +268 -0
- package/woken.js +129 -0
- package/woken.js.map +1 -0
- 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
|
+
})
|
package/result-entry.js
ADDED
|
@@ -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"}
|
package/result-entry.ts
ADDED
|
@@ -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
|
+
}
|