@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/fork.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { derivedEid } from "@yaks/graph/identity";
|
|
2
|
+
import { line } from "@yaks/query";
|
|
3
|
+
import { given, said } from "./answer.js";
|
|
4
|
+
import { overheard } from "./child-notice.js";
|
|
5
|
+
import { context, lines } from "./compact.js";
|
|
6
|
+
import { elide, elidedBefore } from "./pruning.js";
|
|
7
|
+
import { pastCache, seqOf, textOf } from "./state.js";
|
|
8
|
+
let part = (b, name)=>b?.[name];
|
|
9
|
+
/** Prose a model gave while its fork still has work. A tool step can carry
|
|
10
|
+
* an output with prose alongside its result, so only a model step speaks.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { equal } from '@yaks/testing'
|
|
14
|
+
* import { forkProgress } from './fork.ts'
|
|
15
|
+
* let words = { entity: { eid: 'draft' }, output: {}, content: { body: 'On it.' } }
|
|
16
|
+
* equal(forkProgress({ did: 'asked', status: 'running', added: [words] }), words)
|
|
17
|
+
* equal(forkProgress({ did: 'ran', status: 'running', added: [words] }), undefined)
|
|
18
|
+
* ```
|
|
19
|
+
*/ export let forkProgress = (step)=>step.did == 'asked' && step.status == 'running' ? step.added.findLast((b)=>said(b) && !!textOf(b).trim()) : undefined;
|
|
20
|
+
/** The latest request inside a fork's frozen prefix. */ export let forkRequest = (parent, anchor, entries)=>{
|
|
21
|
+
let request = entries.findLast((b)=>seqOf(b) <= seqOf(anchor) && part(b, 'entry')?.session == parent && given(b) && !b.prompt);
|
|
22
|
+
return request?.system || request?.delivery ? undefined : request;
|
|
23
|
+
};
|
|
24
|
+
/** The inherited prompt for a fork that began on a confirmed cold turn.
|
|
25
|
+
* Judge expiry at the first ask for the input, before that ask warms it. */ export let coldFork = (entries, parent, request, anchor)=>{
|
|
26
|
+
let seqs = new Map(entries.map((b)=>[
|
|
27
|
+
b.entity.eid,
|
|
28
|
+
seqOf(b)
|
|
29
|
+
]));
|
|
30
|
+
let first = entries.find((b)=>b.ask && part(b, 'entry')?.session == parent && (seqs.get(String(part(b, 'ask')?.through)) ?? 0) >= seqOf(request));
|
|
31
|
+
let at = Date.parse(String(part(first, 'created')?.at ?? ''));
|
|
32
|
+
if (!first || !Number.isFinite(at) || !pastCache(entries.filter((b)=>seqOf(b) < seqOf(first)), parent, at)) return;
|
|
33
|
+
let inherited = entries.filter((b)=>seqOf(b) <= seqOf(anchor));
|
|
34
|
+
let before = Number(part(first, 'ask')?.elided_before ?? elidedBefore(inherited, parent));
|
|
35
|
+
return {
|
|
36
|
+
before,
|
|
37
|
+
visible: new Set(lines(elide(context(inherited), before)).map((b)=>b.entity.eid))
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
/** A fork's answer is a passive receipt in the same conversation as its request. */ export let forkAnswer = async (g, child, output)=>{
|
|
41
|
+
let request = part(child, 'fork')?.request;
|
|
42
|
+
if (typeof request != 'string') return;
|
|
43
|
+
let session = child.entity.eid;
|
|
44
|
+
let [[input], [mark]] = await Promise.all([
|
|
45
|
+
g.get([
|
|
46
|
+
request
|
|
47
|
+
], [
|
|
48
|
+
'content',
|
|
49
|
+
'entry',
|
|
50
|
+
'intake',
|
|
51
|
+
'channel'
|
|
52
|
+
]),
|
|
53
|
+
output ? [
|
|
54
|
+
output
|
|
55
|
+
] : g.read(line`.entry.session=${session} .order=-entry.seq .limit=1 .fields=entity.eid,stop`)
|
|
56
|
+
]);
|
|
57
|
+
let parent = part(input, 'entry')?.session;
|
|
58
|
+
if (!input || typeof parent != 'string' || !mark) return;
|
|
59
|
+
let [later] = await g.read(line`.entry.session=${parent} .entry.seq>${seqOf(input)} .intake !system !notice .limit=1 .fields=entity.eid`);
|
|
60
|
+
return {
|
|
61
|
+
parent,
|
|
62
|
+
input,
|
|
63
|
+
mark,
|
|
64
|
+
earlier: !!later
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
/** Record the answer as the child's delivery. The parent can read it without waking. */ export let forkReceipt = async (g, child, { parent, mark }, text, by, outcome)=>({
|
|
68
|
+
entity: {
|
|
69
|
+
eid: derivedEid(`delivery:${child}:${mark.entity.eid}`)
|
|
70
|
+
},
|
|
71
|
+
entry: {
|
|
72
|
+
session: parent
|
|
73
|
+
},
|
|
74
|
+
notice: {
|
|
75
|
+
child
|
|
76
|
+
},
|
|
77
|
+
delivery: {
|
|
78
|
+
child,
|
|
79
|
+
through: mark.entity.eid,
|
|
80
|
+
...outcome ? {
|
|
81
|
+
outcome
|
|
82
|
+
} : {}
|
|
83
|
+
},
|
|
84
|
+
output: {},
|
|
85
|
+
content: {
|
|
86
|
+
body: text
|
|
87
|
+
},
|
|
88
|
+
...await overheard(g, child) ? {
|
|
89
|
+
heard: {}
|
|
90
|
+
} : {},
|
|
91
|
+
$actor: {
|
|
92
|
+
by,
|
|
93
|
+
via: child
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
//# sourceMappingURL=fork.js.map
|
package/fork.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fork.js","sources":["./fork.ts"],"names":[],"mappings":"AACA,SAAS,UAAU,oCAAyC;AAC5D,SAAS,IAAI,2BAAgC;AAC7C,SAAS,KAAK,EAAE,IAAI,sBAAqB;AACzC,SAAS,SAAS,4BAA2B;AAC7C,SAAS,OAAO,EAAE,KAAK,uBAA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E;MAAQ,IAAI,CAAC,CAAC;IAAC;IAC3E,QAAQ,CAAC;IACT,SAAS;MAAE,MAAM;IAAK;IACtB,GAAG,MAAM,UAAU,GAAG,SAAS;MAAE,OAAO,CAAC;IAAE,IAAI,CAAC,CAAC;IACjD,QAAQ;MAAE;MAAI,KAAK;IAAM;EAC3B,CAAC,EAAC"}
|
package/fork.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { Bundle, Comp, Eid, Graph } from 'jsr:@yaks/graph@0.2.36'
|
|
2
|
+
import { derivedEid } from '@yaks/graph/identity'
|
|
3
|
+
import { line } from '@yaks/query'
|
|
4
|
+
import { given, said } from './answer.js'
|
|
5
|
+
import { overheard } from './child-notice.js'
|
|
6
|
+
import { context, lines } from './compact.js'
|
|
7
|
+
import { elide, elidedBefore } from './pruning.js'
|
|
8
|
+
import type { Step } from './react.ts'
|
|
9
|
+
import { pastCache, seqOf, textOf } from './state.js'
|
|
10
|
+
|
|
11
|
+
let part = (b: Bundle | undefined, name: string) =>
|
|
12
|
+
b?.[name] as Comp | undefined
|
|
13
|
+
|
|
14
|
+
/** Prose a model gave while its fork still has work. A tool step can carry
|
|
15
|
+
* an output with prose alongside its result, so only a model step speaks.
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { equal } from '@yaks/testing'
|
|
19
|
+
* import { forkProgress } from './fork.ts'
|
|
20
|
+
* let words = { entity: { eid: 'draft' }, output: {}, content: { body: 'On it.' } }
|
|
21
|
+
* equal(forkProgress({ did: 'asked', status: 'running', added: [words] }), words)
|
|
22
|
+
* equal(forkProgress({ did: 'ran', status: 'running', added: [words] }), undefined)
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export let forkProgress = (step: Step): Bundle | undefined =>
|
|
26
|
+
step.did == 'asked' && step.status == 'running'
|
|
27
|
+
? step.added.findLast((b) => said(b) && !!textOf(b).trim())
|
|
28
|
+
: undefined
|
|
29
|
+
|
|
30
|
+
/** The latest request inside a fork's frozen prefix. */
|
|
31
|
+
export let forkRequest = (parent: Eid, anchor: Bundle, entries: Bundle[]) => {
|
|
32
|
+
let request = entries.findLast((b) =>
|
|
33
|
+
seqOf(b) <= seqOf(anchor) && part(b, 'entry')?.session == parent &&
|
|
34
|
+
given(b) && !b.prompt
|
|
35
|
+
)
|
|
36
|
+
return request?.system || request?.delivery ? undefined : request
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The inherited prompt for a fork that began on a confirmed cold turn.
|
|
40
|
+
* Judge expiry at the first ask for the input, before that ask warms it. */
|
|
41
|
+
export let coldFork = (
|
|
42
|
+
entries: Bundle[],
|
|
43
|
+
parent: Eid,
|
|
44
|
+
request: Bundle,
|
|
45
|
+
anchor: Bundle,
|
|
46
|
+
) => {
|
|
47
|
+
let seqs = new Map(entries.map((b) => [b.entity.eid, seqOf(b)]))
|
|
48
|
+
let first = entries.find((b) =>
|
|
49
|
+
b.ask && part(b, 'entry')?.session == parent &&
|
|
50
|
+
(seqs.get(String(part(b, 'ask')?.through)) ?? 0) >= seqOf(request)
|
|
51
|
+
)
|
|
52
|
+
let at = Date.parse(String(part(first, 'created')?.at ?? ''))
|
|
53
|
+
if (
|
|
54
|
+
!first || !Number.isFinite(at) || !pastCache(
|
|
55
|
+
entries.filter((b) => seqOf(b) < seqOf(first)),
|
|
56
|
+
parent,
|
|
57
|
+
at,
|
|
58
|
+
)
|
|
59
|
+
) return
|
|
60
|
+
let inherited = entries.filter((b) => seqOf(b) <= seqOf(anchor))
|
|
61
|
+
let before = Number(
|
|
62
|
+
part(first, 'ask')?.elided_before ??
|
|
63
|
+
elidedBefore(inherited, parent),
|
|
64
|
+
)
|
|
65
|
+
return {
|
|
66
|
+
before,
|
|
67
|
+
visible: new Set(
|
|
68
|
+
lines(elide(context(inherited), before)).map((b) => b.entity.eid),
|
|
69
|
+
),
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Where a fork's answer goes: the parent session, the request it answers,
|
|
74
|
+
* the child's last entry, and whether the parent has spoken since. */
|
|
75
|
+
export type ForkAnswer = {
|
|
76
|
+
parent: Eid
|
|
77
|
+
input: Bundle
|
|
78
|
+
mark: Bundle
|
|
79
|
+
earlier: boolean
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** A fork's answer is a passive receipt in the same conversation as its request. */
|
|
83
|
+
export let forkAnswer = async (
|
|
84
|
+
g: Graph,
|
|
85
|
+
child: Bundle,
|
|
86
|
+
output?: Bundle,
|
|
87
|
+
): Promise<ForkAnswer | undefined> => {
|
|
88
|
+
let request = part(child, 'fork')?.request
|
|
89
|
+
if (typeof request != 'string') return
|
|
90
|
+
let session = child.entity.eid
|
|
91
|
+
let [[input], [mark]] = await Promise.all([
|
|
92
|
+
g.get([request], ['content', 'entry', 'intake', 'channel']),
|
|
93
|
+
output ? [output] : g.read(
|
|
94
|
+
line`.entry.session=${session} .order=-entry.seq .limit=1 .fields=entity.eid,stop`,
|
|
95
|
+
),
|
|
96
|
+
])
|
|
97
|
+
let parent = part(input, 'entry')?.session
|
|
98
|
+
if (!input || typeof parent != 'string' || !mark) return
|
|
99
|
+
let [later] = await g.read(
|
|
100
|
+
line`.entry.session=${parent} .entry.seq>${
|
|
101
|
+
seqOf(input)
|
|
102
|
+
} .intake !system !notice .limit=1 .fields=entity.eid`,
|
|
103
|
+
)
|
|
104
|
+
return { parent, input, mark, earlier: !!later }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Record the answer as the child's delivery. The parent can read it without waking. */
|
|
108
|
+
export let forkReceipt = async (
|
|
109
|
+
g: Graph,
|
|
110
|
+
child: Eid,
|
|
111
|
+
{ parent, mark }: ForkAnswer,
|
|
112
|
+
text: string,
|
|
113
|
+
by: Eid,
|
|
114
|
+
outcome?: 'settled' | 'failed' | 'stopped',
|
|
115
|
+
): Promise<Bundle> => ({
|
|
116
|
+
entity: { eid: derivedEid(`delivery:${child}:${mark.entity.eid}`) },
|
|
117
|
+
entry: { session: parent },
|
|
118
|
+
notice: { child },
|
|
119
|
+
delivery: { child, through: mark.entity.eid, ...outcome ? { outcome } : {} },
|
|
120
|
+
output: {},
|
|
121
|
+
content: { body: text },
|
|
122
|
+
...await overheard(g, child) ? { heard: {} } : {},
|
|
123
|
+
$actor: { by, via: child },
|
|
124
|
+
})
|
package/graft.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// A graft: another transcript's lines written as the beginning of a session,
|
|
2
|
+
// as a cutting from one tree grows on another. A fork continues a transcript
|
|
3
|
+
// within its store (`fork{from}`); a graft carries the lines themselves, so
|
|
4
|
+
// the session it starts holds them in a store that never had the original.
|
|
5
|
+
import { derivedEid } from "@yaks/graph/identity";
|
|
6
|
+
import { kindOf, ordered } from "./state.js";
|
|
7
|
+
// The lines a graft carries: what was said, asked and answered.
|
|
8
|
+
let CARRIED = new Set([
|
|
9
|
+
'input',
|
|
10
|
+
'output',
|
|
11
|
+
'call',
|
|
12
|
+
'result',
|
|
13
|
+
'ask'
|
|
14
|
+
]);
|
|
15
|
+
// What a carried line keeps: the components that say what it is. What the
|
|
16
|
+
// provider kept about an ask, what it cost, the model chosen, the request it
|
|
17
|
+
// came in and its archive mark stay with the transcript they belong to.
|
|
18
|
+
let KEPT = [
|
|
19
|
+
'content',
|
|
20
|
+
'call',
|
|
21
|
+
'result',
|
|
22
|
+
'output',
|
|
23
|
+
'ask',
|
|
24
|
+
'channel',
|
|
25
|
+
'system',
|
|
26
|
+
'refusal',
|
|
27
|
+
'exception'
|
|
28
|
+
];
|
|
29
|
+
// Lines the session wrote for itself rather than said: its prompts, a
|
|
30
|
+
// child's notice, the task it was given.
|
|
31
|
+
let OWN = [
|
|
32
|
+
'prompt',
|
|
33
|
+
'notice',
|
|
34
|
+
'task_context'
|
|
35
|
+
];
|
|
36
|
+
/**
|
|
37
|
+
* The rows that begin `session` with `lines`, another transcript's entries:
|
|
38
|
+
* each line it carries (`CARRIED`) as a new entry of `session`, in transcript
|
|
39
|
+
* order and appended after whatever the session holds, with the components
|
|
40
|
+
* that say what it is (`KEPT`). A reference from one line to another names
|
|
41
|
+
* the other's copy. Each copy's eid is derived from the session and the
|
|
42
|
+
* original's, so giving the same lines again writes the same rows.
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { grafted } from './graft.ts'
|
|
46
|
+
* import { assertEquals } from '@std/assert'
|
|
47
|
+
* let at = (eid: string, seq: number, rest: object) => ({
|
|
48
|
+
* entity: { eid }, entry: { session: 'demo', seq }, ...rest,
|
|
49
|
+
* })
|
|
50
|
+
* let rows = grafted([
|
|
51
|
+
* at('said', 1, { content: { body: 'A guestbook' }, using: { model: 'm' } }),
|
|
52
|
+
* at('asked', 2, { ask: { to: 'm', through: 'said' }, anthropic: {} }),
|
|
53
|
+
* at('call', 3, { call: { name: 'app_deploy', source: 'asked' } }),
|
|
54
|
+
* at('done', 4, { result: { call: 'call', value: 1 } }),
|
|
55
|
+
* at('rule', 5, { prompt: { scope: 'local' }, content: { body: 'Be kind' } }),
|
|
56
|
+
* ], 'mine')
|
|
57
|
+
* assertEquals(rows.map((r) => Object.keys(r)), [
|
|
58
|
+
* ['entity', 'entry', 'content'],
|
|
59
|
+
* ['entity', 'entry', 'ask'],
|
|
60
|
+
* ['entity', 'entry', 'call'],
|
|
61
|
+
* ['entity', 'entry', 'result'],
|
|
62
|
+
* ])
|
|
63
|
+
* assertEquals((rows[3].result as { call: string }).call, rows[2].entity.eid)
|
|
64
|
+
* assertEquals(rows[1].entry, { session: 'mine' })
|
|
65
|
+
* ```
|
|
66
|
+
*/ export let grafted = (lines, session)=>{
|
|
67
|
+
let carried = ordered(lines).filter((b)=>CARRIED.has(kindOf(b) ?? '') && !OWN.some((c)=>b[c]));
|
|
68
|
+
let copy = new Map(carried.map((b)=>[
|
|
69
|
+
b.entity.eid,
|
|
70
|
+
derivedEid(`graft|${session}|${b.entity.eid}`)
|
|
71
|
+
]));
|
|
72
|
+
let named = (v)=>typeof v == 'string' ? copy.get(v) ?? v : v;
|
|
73
|
+
return carried.map((b)=>{
|
|
74
|
+
let from = b.entry.from;
|
|
75
|
+
let row = {
|
|
76
|
+
entity: {
|
|
77
|
+
eid: copy.get(b.entity.eid)
|
|
78
|
+
},
|
|
79
|
+
entry: {
|
|
80
|
+
session,
|
|
81
|
+
...from ? {
|
|
82
|
+
from
|
|
83
|
+
} : {}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
for (let name of KEPT){
|
|
87
|
+
let c = b[name];
|
|
88
|
+
if (!c) continue;
|
|
89
|
+
row[name] = Object.fromEntries(Object.entries(c).map(([k, v])=>[
|
|
90
|
+
k,
|
|
91
|
+
named(v)
|
|
92
|
+
]));
|
|
93
|
+
}
|
|
94
|
+
return row;
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=graft.js.map
|
package/graft.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graft.js","sources":["./graft.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,6EAA6E;AAC7E,4EAA4E;AAC5E,2EAA2E;AAE3E,SAAS,UAAU,oCAAyC;AAC5D,SAAS,MAAM,EAAE,OAAO,qBAAoB;AAE5C,gEAAgE;AAChE,IAAI,UAAU,IAAI,IAAI;EAAC;EAAS;EAAU;EAAQ;EAAU;CAAM;AAElE,0EAA0E;AAC1E,6EAA6E;AAC7E,wEAAwE;AACxE,IAAI,OAAO;EACT;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD;AAED,sEAAsE;AACtE,yCAAyC;AACzC,IAAI,MAAM;EAAC;EAAU;EAAU;CAAe;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BC,GACD,OAAO,IAAI,UAAU,CAAC,OAAiB;EACrC,IAAI,UAAU,QAAQ,OAAO,MAAM,CAAC,CAAC,IACnC,QAAQ,GAAG,CAAC,OAAO,MAAM,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC,IAAM,CAAC,CAAC,EAAE;EAEvD,IAAI,OAAO,IAAI,IACb,QAAQ,GAAG,CAAC,CAAC,IAAM;MACjB,EAAE,MAAM,CAAC,GAAG;MACZ,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC,GAAG,EAAE;KAC9C;EAEH,IAAI,QAAQ,CAAC,IAAe,OAAO,KAAK,WAAW,KAAK,GAAG,CAAC,MAAM,IAAI;EACtE,OAAO,QAAQ,GAAG,CAAC,CAAC;IAClB,IAAI,OAAO,AAAC,EAAE,KAAK,CAAU,IAAI;IACjC,IAAI,MAAc;MAChB,QAAQ;QAAE,KAAK,KAAK,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG;MAAG;MACvC,OAAO;QAAE;QAAS,GAAG,OAAO;UAAE;QAAK,IAAI,CAAC,CAAC;MAAC;IAC5C;IACA,KAAK,IAAI,QAAQ,KAAM;MACrB,IAAI,IAAI,CAAC,CAAC,KAAK;MACf,IAAI,CAAC,GAAG;MACR,GAAG,CAAC,KAAK,GAAG,OAAO,WAAW,CAC5B,OAAO,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,GAAK;UAAC;UAAG,MAAM;SAAG;IAEnD;IACA,OAAO;EACT;AACF,EAAC"}
|
package/graft.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// A graft: another transcript's lines written as the beginning of a session,
|
|
2
|
+
// as a cutting from one tree grows on another. A fork continues a transcript
|
|
3
|
+
// within its store (`fork{from}`); a graft carries the lines themselves, so
|
|
4
|
+
// the session it starts holds them in a store that never had the original.
|
|
5
|
+
import type { Bundle, Comp, Eid } from 'jsr:@yaks/graph@0.2.36'
|
|
6
|
+
import { derivedEid } from '@yaks/graph/identity'
|
|
7
|
+
import { kindOf, ordered } from './state.js'
|
|
8
|
+
|
|
9
|
+
// The lines a graft carries: what was said, asked and answered.
|
|
10
|
+
let CARRIED = new Set(['input', 'output', 'call', 'result', 'ask'])
|
|
11
|
+
|
|
12
|
+
// What a carried line keeps: the components that say what it is. What the
|
|
13
|
+
// provider kept about an ask, what it cost, the model chosen, the request it
|
|
14
|
+
// came in and its archive mark stay with the transcript they belong to.
|
|
15
|
+
let KEPT = [
|
|
16
|
+
'content',
|
|
17
|
+
'call',
|
|
18
|
+
'result',
|
|
19
|
+
'output',
|
|
20
|
+
'ask',
|
|
21
|
+
'channel',
|
|
22
|
+
'system',
|
|
23
|
+
'refusal',
|
|
24
|
+
'exception',
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
// Lines the session wrote for itself rather than said: its prompts, a
|
|
28
|
+
// child's notice, the task it was given.
|
|
29
|
+
let OWN = ['prompt', 'notice', 'task_context']
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The rows that begin `session` with `lines`, another transcript's entries:
|
|
33
|
+
* each line it carries (`CARRIED`) as a new entry of `session`, in transcript
|
|
34
|
+
* order and appended after whatever the session holds, with the components
|
|
35
|
+
* that say what it is (`KEPT`). A reference from one line to another names
|
|
36
|
+
* the other's copy. Each copy's eid is derived from the session and the
|
|
37
|
+
* original's, so giving the same lines again writes the same rows.
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { grafted } from './graft.ts'
|
|
41
|
+
* import { assertEquals } from '@std/assert'
|
|
42
|
+
* let at = (eid: string, seq: number, rest: object) => ({
|
|
43
|
+
* entity: { eid }, entry: { session: 'demo', seq }, ...rest,
|
|
44
|
+
* })
|
|
45
|
+
* let rows = grafted([
|
|
46
|
+
* at('said', 1, { content: { body: 'A guestbook' }, using: { model: 'm' } }),
|
|
47
|
+
* at('asked', 2, { ask: { to: 'm', through: 'said' }, anthropic: {} }),
|
|
48
|
+
* at('call', 3, { call: { name: 'app_deploy', source: 'asked' } }),
|
|
49
|
+
* at('done', 4, { result: { call: 'call', value: 1 } }),
|
|
50
|
+
* at('rule', 5, { prompt: { scope: 'local' }, content: { body: 'Be kind' } }),
|
|
51
|
+
* ], 'mine')
|
|
52
|
+
* assertEquals(rows.map((r) => Object.keys(r)), [
|
|
53
|
+
* ['entity', 'entry', 'content'],
|
|
54
|
+
* ['entity', 'entry', 'ask'],
|
|
55
|
+
* ['entity', 'entry', 'call'],
|
|
56
|
+
* ['entity', 'entry', 'result'],
|
|
57
|
+
* ])
|
|
58
|
+
* assertEquals((rows[3].result as { call: string }).call, rows[2].entity.eid)
|
|
59
|
+
* assertEquals(rows[1].entry, { session: 'mine' })
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export let grafted = (lines: Bundle[], session: Eid): Bundle[] => {
|
|
63
|
+
let carried = ordered(lines).filter((b) =>
|
|
64
|
+
CARRIED.has(kindOf(b) ?? '') && !OWN.some((c) => b[c])
|
|
65
|
+
)
|
|
66
|
+
let copy = new Map(
|
|
67
|
+
carried.map((b) => [
|
|
68
|
+
b.entity.eid,
|
|
69
|
+
derivedEid(`graft|${session}|${b.entity.eid}`),
|
|
70
|
+
]),
|
|
71
|
+
)
|
|
72
|
+
let named = (v: unknown) => typeof v == 'string' ? copy.get(v) ?? v : v
|
|
73
|
+
return carried.map((b) => {
|
|
74
|
+
let from = (b.entry as Comp).from
|
|
75
|
+
let row: Bundle = {
|
|
76
|
+
entity: { eid: copy.get(b.entity.eid)! },
|
|
77
|
+
entry: { session, ...from ? { from } : {} },
|
|
78
|
+
}
|
|
79
|
+
for (let name of KEPT) {
|
|
80
|
+
let c = b[name] as Comp | undefined
|
|
81
|
+
if (!c) continue
|
|
82
|
+
row[name] = Object.fromEntries(
|
|
83
|
+
Object.entries(c).map(([k, v]) => [k, named(v)]),
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
return row
|
|
87
|
+
})
|
|
88
|
+
}
|
package/graph.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// What a batch means about a transcript, and who is writing it: the graph
|
|
2
|
+
// plugins exported as `@yaks/session/graph` — entry sequencing, the reference
|
|
3
|
+
// checks a fork and a `using` must pass, the lease on any entity, and the
|
|
4
|
+
// conflict row written when two sessions want the same thing — and
|
|
5
|
+
// `authenticate`, which every door over the graph asks who a request is from.
|
|
6
|
+
//
|
|
7
|
+
// A client names which run it speaks for, in the `x-via` request header — the
|
|
8
|
+
// fleet's own header name, naming the instrument behind a write rather than a
|
|
9
|
+
// credential — and it is resolved the way every other id a caller types is
|
|
10
|
+
// resolved (./who.ts): an eid, a human-readable id, a name, or the harness's
|
|
11
|
+
// own id for the transcript. What it names is a lease and an attribution, never
|
|
12
|
+
// an authorization: a server that gates access checks a key and lets this
|
|
13
|
+
// identify the run alongside it. A command line asks the same question about
|
|
14
|
+
// the session it speaks for (@yaks/cli `signer`), which is why this is part of
|
|
15
|
+
// what a write means rather than one of the routes.
|
|
16
|
+
//
|
|
17
|
+
// A harness's tool call may also be one the hook door was told about: an MCP
|
|
18
|
+
// call carries the harness's id for the call in its `_meta`, and the run the
|
|
19
|
+
// hook paired with that id is the one speaking (./announce.ts). That says more
|
|
20
|
+
// than `x-via` can, since one harness connection carries a session and every
|
|
21
|
+
// subagent, so it wins where it was said; a call whose hook is late or never
|
|
22
|
+
// comes is still its connection's session (./hooks.ts `connection`).
|
|
23
|
+
//
|
|
24
|
+
// A request that names nothing, or names a run this graph has never heard of,
|
|
25
|
+
// is left to the host's own fallback — the composer attributes those to the
|
|
26
|
+
// process itself (@yaks/cli `writer`), so a write is attributed either way.
|
|
27
|
+
import { VIA } from "@yaks/api";
|
|
28
|
+
import { announced, callIn } from "./announce.js";
|
|
29
|
+
import { reply as owed } from "./bus.js";
|
|
30
|
+
import { sessions } from "./plugin.js";
|
|
31
|
+
import { sessionFor, speaking } from "./who.js";
|
|
32
|
+
export { callIn } from "./announce.js";
|
|
33
|
+
/** Transcripts, leases and the audit of a bounced claim. */ export let plugins = ()=>[
|
|
34
|
+
sessions()
|
|
35
|
+
];
|
|
36
|
+
/** What a direct tool call owes the session speaking through it. */ export let reply = (host)=>(call)=>owed(host, call);
|
|
37
|
+
export { VIA };
|
|
38
|
+
/** Who a request is from: the run the hook door said makes the harness call
|
|
39
|
+
* its message names, else the run its `x-via` header names, as the actor
|
|
40
|
+
* behind what it writes. */ export let authenticate = (host)=>async (request, message)=>{
|
|
41
|
+
let call = callIn(message);
|
|
42
|
+
let said = (call ? await announced(host.graph, call) : undefined) || request.headers.get(VIA);
|
|
43
|
+
if (!said) return null;
|
|
44
|
+
let s = await sessionFor(host.graph, said, [
|
|
45
|
+
'session.id'
|
|
46
|
+
]);
|
|
47
|
+
return s ? await speaking(host.graph, s) : null;
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=graph.js.map
|
package/graph.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.js","sources":["./graph.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,8EAA8E;AAC9E,0EAA0E;AAC1E,mEAAmE;AACnE,8EAA8E;AAC9E,EAAE;AACF,8EAA8E;AAC9E,8EAA8E;AAC9E,2EAA2E;AAC3E,6EAA6E;AAC7E,gFAAgF;AAChF,0EAA0E;AAC1E,6EAA6E;AAC7E,+EAA+E;AAC/E,oDAAoD;AACpD,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,+EAA+E;AAC/E,6EAA6E;AAC7E,6EAA6E;AAC7E,qEAAqE;AACrE,EAAE;AACF,8EAA8E;AAC9E,4EAA4E;AAC5E,4EAA4E;AAE5E,SAA4B,GAAG,yBAA8B;AAE7D,SAAS,SAAS,EAAE,MAAM,wBAAuB;AACjD,SAAoB,SAAS,IAAI,mBAAkB;AACnD,SAAS,QAAQ,sBAAqB;AACtC,SAAS,UAAU,EAAE,QAAQ,mBAAkB;AAE/C,SAAS,MAAM,wBAAuB;AAEtC,0DAA0D,GAC1D,OAAO,IAAI,UAAU,IAAgB;IAAC;GAAW,CAAA;AAEjD,kEAAkE,GAClE,OAAO,IAAI,QAAQ,CAAC,OAAe,CAAC,OAClC,KAAK,MAAM,MAAK;AAElB,SAAS,GAAG,GAAE;AAKd;;0BAE0B,GAC1B,OAAO,IAAI,eACT,CAAC,OACD,OAAO,SAAkB;IACvB,IAAI,OAAO,OAAO;IAClB,IAAI,OAAO,CAAC,OAAO,MAAM,UAAU,KAAK,KAAK,EAAE,QAAQ,SAAS,KAC9D,QAAQ,OAAO,CAAC,GAAG,CAAC;IACtB,IAAI,CAAC,MAAM,OAAO;IAClB,IAAI,IAAI,MAAM,WAAW,KAAK,KAAK,EAAE,MAAM;MAAC;KAAa;IACzD,OAAO,IAAI,MAAM,SAAS,KAAK,KAAK,EAAE,KAAK;EAC7C,EAAC"}
|
package/graph.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// What a batch means about a transcript, and who is writing it: the graph
|
|
2
|
+
// plugins exported as `@yaks/session/graph` — entry sequencing, the reference
|
|
3
|
+
// checks a fork and a `using` must pass, the lease on any entity, and the
|
|
4
|
+
// conflict row written when two sessions want the same thing — and
|
|
5
|
+
// `authenticate`, which every door over the graph asks who a request is from.
|
|
6
|
+
//
|
|
7
|
+
// A client names which run it speaks for, in the `x-via` request header — the
|
|
8
|
+
// fleet's own header name, naming the instrument behind a write rather than a
|
|
9
|
+
// credential — and it is resolved the way every other id a caller types is
|
|
10
|
+
// resolved (./who.ts): an eid, a human-readable id, a name, or the harness's
|
|
11
|
+
// own id for the transcript. What it names is a lease and an attribution, never
|
|
12
|
+
// an authorization: a server that gates access checks a key and lets this
|
|
13
|
+
// identify the run alongside it. A command line asks the same question about
|
|
14
|
+
// the session it speaks for (@yaks/cli `signer`), which is why this is part of
|
|
15
|
+
// what a write means rather than one of the routes.
|
|
16
|
+
//
|
|
17
|
+
// A harness's tool call may also be one the hook door was told about: an MCP
|
|
18
|
+
// call carries the harness's id for the call in its `_meta`, and the run the
|
|
19
|
+
// hook paired with that id is the one speaking (./announce.ts). That says more
|
|
20
|
+
// than `x-via` can, since one harness connection carries a session and every
|
|
21
|
+
// subagent, so it wins where it was said; a call whose hook is late or never
|
|
22
|
+
// comes is still its connection's session (./hooks.ts `connection`).
|
|
23
|
+
//
|
|
24
|
+
// A request that names nothing, or names a run this graph has never heard of,
|
|
25
|
+
// is left to the host's own fallback — the composer attributes those to the
|
|
26
|
+
// process itself (@yaks/cli `writer`), so a write is attributed either way.
|
|
27
|
+
|
|
28
|
+
import { type Authenticate, VIA } from '@yaks/api'
|
|
29
|
+
import type { Actor, Bundle, Graph, Plugin } from 'jsr:@yaks/graph@0.2.36'
|
|
30
|
+
import { announced, callIn } from './announce.js'
|
|
31
|
+
import { type Door, reply as owed } from './bus.js'
|
|
32
|
+
import { sessions } from './plugin.js'
|
|
33
|
+
import { sessionFor, speaking } from './who.js'
|
|
34
|
+
|
|
35
|
+
export { callIn } from './announce.js'
|
|
36
|
+
|
|
37
|
+
/** Transcripts, leases and the audit of a bounced claim. */
|
|
38
|
+
export let plugins = (): Plugin[] => [sessions()]
|
|
39
|
+
|
|
40
|
+
/** What a direct tool call owes the session speaking through it. */
|
|
41
|
+
export let reply = (host: Door) => (call: Bundle): Promise<Bundle[]> =>
|
|
42
|
+
owed(host, call)
|
|
43
|
+
|
|
44
|
+
export { VIA }
|
|
45
|
+
|
|
46
|
+
/** What `authenticate` is given: the graph, once it is open. */
|
|
47
|
+
export type Host = { graph: Graph }
|
|
48
|
+
|
|
49
|
+
/** Who a request is from: the run the hook door said makes the harness call
|
|
50
|
+
* its message names, else the run its `x-via` header names, as the actor
|
|
51
|
+
* behind what it writes. */
|
|
52
|
+
export let authenticate =
|
|
53
|
+
(host: Host): Authenticate =>
|
|
54
|
+
async (request: Request, message?: unknown): Promise<Actor | null> => {
|
|
55
|
+
let call = callIn(message)
|
|
56
|
+
let said = (call ? await announced(host.graph, call) : undefined) ||
|
|
57
|
+
request.headers.get(VIA)
|
|
58
|
+
if (!said) return null
|
|
59
|
+
let s = await sessionFor(host.graph, said, ['session.id'])
|
|
60
|
+
return s ? await speaking(host.graph, s) : null
|
|
61
|
+
}
|
package/handoff.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// What a model is told when it takes over a conversation another harness
|
|
2
|
+
// (Claude Code, Codex, Grok, Antigravity) ran: what it ran on, that the tool
|
|
3
|
+
// calls in it were that harness's own, and the files it worked on. A model
|
|
4
|
+
// whose window cannot hold the conversation reads it summarized, as any long
|
|
5
|
+
// transcript is (./compact.ts).
|
|
6
|
+
import { line, sub } from "@yaks/query";
|
|
7
|
+
import { ordered } from "./state.js";
|
|
8
|
+
let comp = (b, name)=>b?.[name];
|
|
9
|
+
// The argument names a file path goes by in the tools of Claude Code, Codex,
|
|
10
|
+
// Grok, Antigravity and the harness.
|
|
11
|
+
let PATHS = [
|
|
12
|
+
'file_path',
|
|
13
|
+
'path',
|
|
14
|
+
'filePath',
|
|
15
|
+
'notebook_path',
|
|
16
|
+
'AbsolutePath',
|
|
17
|
+
'TargetFile',
|
|
18
|
+
'target_file'
|
|
19
|
+
];
|
|
20
|
+
// The files a patch names (`*** Update File: a.ts`), as Codex's apply_patch
|
|
21
|
+
// writes them.
|
|
22
|
+
let patched = (text)=>[
|
|
23
|
+
...text.matchAll(/^\*\*\* (?:Add|Update|Delete) File: (.+)$/gm)
|
|
24
|
+
].map((m)=>m[1].trim());
|
|
25
|
+
/** The files a transcript's calls named, newest first, each once. */ export let touched = (entries)=>{
|
|
26
|
+
let files = ordered(entries).flatMap((b)=>{
|
|
27
|
+
let args = comp(b, 'call')?.args;
|
|
28
|
+
if (!args) return [];
|
|
29
|
+
return [
|
|
30
|
+
...PATHS.map((k)=>args[k]).filter((v)=>typeof v == 'string' && !!v),
|
|
31
|
+
...Object.values(args).flatMap((v)=>typeof v == 'string' ? patched(v) : [])
|
|
32
|
+
];
|
|
33
|
+
});
|
|
34
|
+
return [
|
|
35
|
+
...new Set(files.toReversed())
|
|
36
|
+
];
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The note a session gets when another model takes over its conversation
|
|
40
|
+
* from another harness: what the conversation ran on so far, by the names
|
|
41
|
+
* `names` gives the provider and model rows its newest `using` or ask names,
|
|
42
|
+
* and the files its calls named, at most `limit`.
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { handoff } from './handoff.ts'
|
|
46
|
+
* import { assertEquals } from '@std/assert'
|
|
47
|
+
*
|
|
48
|
+
* let entries = [
|
|
49
|
+
* { entity: { eid: 'u' }, entry: { session: 's', seq: 1 }, using: { provider: 'p' } },
|
|
50
|
+
* { entity: { eid: 'c' }, entry: { session: 's', seq: 2 },
|
|
51
|
+
* call: { name: 'Edit', args: { file_path: '/w/a.ts' } } },
|
|
52
|
+
* ]
|
|
53
|
+
* assertEquals(handoff(entries, new Map([['p', 'claude']])),
|
|
54
|
+
* 'Until here this conversation ran on claude, and another model takes ' +
|
|
55
|
+
* 'it over now. The tool calls above were made with that harness\'s own ' +
|
|
56
|
+
* 'tools, and their results are as it saw them; call your own tools from ' +
|
|
57
|
+
* 'here on.\n\nFiles it worked on, newest first:\n- /w/a.ts')
|
|
58
|
+
* ```
|
|
59
|
+
*/ export let handoff = (entries, names, limit = 40)=>{
|
|
60
|
+
let newest = ordered(entries).toReversed();
|
|
61
|
+
let using = newest.map((b)=>comp(b, 'using')).find(Boolean);
|
|
62
|
+
let model = using?.model ?? newest.map((b)=>comp(b, 'ask')?.to).find(Boolean);
|
|
63
|
+
let ran = [
|
|
64
|
+
using?.provider,
|
|
65
|
+
model
|
|
66
|
+
].map((eid)=>eid && names.get(String(eid))).filter(Boolean).join(' ');
|
|
67
|
+
let files = touched(entries);
|
|
68
|
+
return [
|
|
69
|
+
`Until here this conversation ran ${ran ? `on ${ran}` : 'elsewhere'}, ` + 'and another model takes it over now. The tool calls above were made ' + "with that harness's own tools, and their results are as it saw them; " + 'call your own tools from here on.',
|
|
70
|
+
...files.length ? [
|
|
71
|
+
'Files it worked on, newest first:\n' + files.slice(0, limit).map((f)=>`- ${f}`).join('\n') + (files.length > limit ? `\n- and ${files.length - limit} more` : '')
|
|
72
|
+
] : []
|
|
73
|
+
].join('\n\n');
|
|
74
|
+
};
|
|
75
|
+
/** The note for `session` ({@link handoff}) where another harness ran its
|
|
76
|
+
* conversation so far: its newest model selection or request was read from
|
|
77
|
+
* that harness's file (`lines{file, start}`), not asked here. Nothing where
|
|
78
|
+
* this harness asked it last, or nothing asked it yet. */ export let handoffOf = async (g, session)=>{
|
|
79
|
+
let own = line`.entry.session=${session}`;
|
|
80
|
+
let [last] = await g.read(line`${sub(own)}&(.using|.ask)&.order=-entry.seq&.limit=1&.fields=entry.seq,lines.file`);
|
|
81
|
+
if (!comp(last, 'lines')?.file) return undefined;
|
|
82
|
+
let [calls, said] = await Promise.all([
|
|
83
|
+
g.read(line`${sub(own)}&.call&.fields=entry.seq,call.args`),
|
|
84
|
+
g.read(line`${sub(own)}&(.using|.ask)&.order=-entry.seq&.limit=8&.fields=entry.seq,using.provider,using.model,ask.to`)
|
|
85
|
+
]);
|
|
86
|
+
return handoff([
|
|
87
|
+
...calls,
|
|
88
|
+
...said
|
|
89
|
+
], await namesOf(g, said));
|
|
90
|
+
};
|
|
91
|
+
/** The names of the providers and models entries' `using` and `ask` name,
|
|
92
|
+
* by their rows' eids: what {@link handoff} says a conversation ran on. */ export let namesOf = async (g, entries)=>{
|
|
93
|
+
let named = [
|
|
94
|
+
...new Set(entries.flatMap((b)=>[
|
|
95
|
+
comp(b, 'using')?.provider,
|
|
96
|
+
comp(b, 'using')?.model,
|
|
97
|
+
comp(b, 'ask')?.to
|
|
98
|
+
]).filter((v)=>typeof v == 'string'))
|
|
99
|
+
];
|
|
100
|
+
let rows = named.length ? await g.get(named) : [];
|
|
101
|
+
return new Map(rows.flatMap((r)=>{
|
|
102
|
+
let name = comp(r, 'provider')?.name ?? comp(r, 'model')?.name;
|
|
103
|
+
return typeof name == 'string' ? [
|
|
104
|
+
[
|
|
105
|
+
r.entity.eid,
|
|
106
|
+
name
|
|
107
|
+
]
|
|
108
|
+
] : [];
|
|
109
|
+
}));
|
|
110
|
+
};
|
|
111
|
+
//# sourceM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